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_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12844                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
12845                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_S",
12846                            new String[] {
12847                                    Long.class.getName(), Boolean.class.getName(),
12848                                    Integer.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_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12854                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
12855                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_S",
12856                            new String[] {
12857                                    Long.class.getName(), Boolean.class.getName(),
12858                                    Integer.class.getName()
12859                            },
12860                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
12861                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
12862                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
12863                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
12864                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
12865            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12866                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12867                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_S",
12868                            new String[] {
12869                                    Long.class.getName(), Boolean.class.getName(),
12870                                    Integer.class.getName()
12871                            });
12872    
12873            /**
12874             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
12875             *
12876             * @param nodeId the node ID
12877             * @param head the head
12878             * @param status the status
12879             * @return the matching wiki pages
12880             * @throws SystemException if a system exception occurred
12881             */
12882            @Override
12883            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status)
12884                    throws SystemException {
12885                    return findByN_H_S(nodeId, head, status, 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 status = &#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 status the status
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_S(long nodeId, boolean head, int status,
12906                    int start, int end) throws SystemException {
12907                    return findByN_H_S(nodeId, head, status, start, end, null);
12908            }
12909    
12910            /**
12911             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and status = &#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 status the status
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_S(long nodeId, boolean head, int status,
12928                    int start, int end, OrderByComparator orderByComparator)
12929                    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_S;
12938                            finderArgs = new Object[] { nodeId, head, status };
12939                    }
12940                    else {
12941                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_S;
12942                            finderArgs = new Object[] {
12943                                            nodeId, head, status,
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                                                    (status != wikiPage.getStatus())) {
12957                                            list = null;
12958    
12959                                            break;
12960                                    }
12961                            }
12962                    }
12963    
12964                    if (list == null) {
12965                            StringBundler query = null;
12966    
12967                            if (orderByComparator != null) {
12968                                    query = new StringBundler(5 +
12969                                                    (orderByComparator.getOrderByFields().length * 3));
12970                            }
12971                            else {
12972                                    query = new StringBundler(5);
12973                            }
12974    
12975                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
12976    
12977                            query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
12978    
12979                            query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
12980    
12981                            query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
12982    
12983                            if (orderByComparator != null) {
12984                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12985                                            orderByComparator);
12986                            }
12987                            else
12988                             if (pagination) {
12989                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12990                            }
12991    
12992                            String sql = query.toString();
12993    
12994                            Session session = null;
12995    
12996                            try {
12997                                    session = openSession();
12998    
12999                                    Query q = session.createQuery(sql);
13000    
13001                                    QueryPos qPos = QueryPos.getInstance(q);
13002    
13003                                    qPos.add(nodeId);
13004    
13005                                    qPos.add(head);
13006    
13007                                    qPos.add(status);
13008    
13009                                    if (!pagination) {
13010                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13011                                                            start, end, false);
13012    
13013                                            Collections.sort(list);
13014    
13015                                            list = new UnmodifiableList<WikiPage>(list);
13016                                    }
13017                                    else {
13018                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13019                                                            start, end);
13020                                    }
13021    
13022                                    cacheResult(list);
13023    
13024                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13025                            }
13026                            catch (Exception e) {
13027                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13028    
13029                                    throw processException(e);
13030                            }
13031                            finally {
13032                                    closeSession(session);
13033                            }
13034                    }
13035    
13036                    return list;
13037            }
13038    
13039            /**
13040             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
13041             *
13042             * @param nodeId the node ID
13043             * @param head the head
13044             * @param status the status
13045             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13046             * @return the first matching wiki page
13047             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13048             * @throws SystemException if a system exception occurred
13049             */
13050            @Override
13051            public WikiPage findByN_H_S_First(long nodeId, boolean head, int status,
13052                    OrderByComparator orderByComparator)
13053                    throws NoSuchPageException, SystemException {
13054                    WikiPage wikiPage = fetchByN_H_S_First(nodeId, head, status,
13055                                    orderByComparator);
13056    
13057                    if (wikiPage != null) {
13058                            return wikiPage;
13059                    }
13060    
13061                    StringBundler msg = new StringBundler(8);
13062    
13063                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13064    
13065                    msg.append("nodeId=");
13066                    msg.append(nodeId);
13067    
13068                    msg.append(", head=");
13069                    msg.append(head);
13070    
13071                    msg.append(", status=");
13072                    msg.append(status);
13073    
13074                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13075    
13076                    throw new NoSuchPageException(msg.toString());
13077            }
13078    
13079            /**
13080             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
13081             *
13082             * @param nodeId the node ID
13083             * @param head the head
13084             * @param status the status
13085             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13086             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
13087             * @throws SystemException if a system exception occurred
13088             */
13089            @Override
13090            public WikiPage fetchByN_H_S_First(long nodeId, boolean head, int status,
13091                    OrderByComparator orderByComparator) throws SystemException {
13092                    List<WikiPage> list = findByN_H_S(nodeId, head, status, 0, 1,
13093                                    orderByComparator);
13094    
13095                    if (!list.isEmpty()) {
13096                            return list.get(0);
13097                    }
13098    
13099                    return null;
13100            }
13101    
13102            /**
13103             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
13104             *
13105             * @param nodeId the node ID
13106             * @param head the head
13107             * @param status the status
13108             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13109             * @return the last matching wiki page
13110             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13111             * @throws SystemException if a system exception occurred
13112             */
13113            @Override
13114            public WikiPage findByN_H_S_Last(long nodeId, boolean head, int status,
13115                    OrderByComparator orderByComparator)
13116                    throws NoSuchPageException, SystemException {
13117                    WikiPage wikiPage = fetchByN_H_S_Last(nodeId, head, status,
13118                                    orderByComparator);
13119    
13120                    if (wikiPage != null) {
13121                            return wikiPage;
13122                    }
13123    
13124                    StringBundler msg = new StringBundler(8);
13125    
13126                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13127    
13128                    msg.append("nodeId=");
13129                    msg.append(nodeId);
13130    
13131                    msg.append(", head=");
13132                    msg.append(head);
13133    
13134                    msg.append(", status=");
13135                    msg.append(status);
13136    
13137                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13138    
13139                    throw new NoSuchPageException(msg.toString());
13140            }
13141    
13142            /**
13143             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
13144             *
13145             * @param nodeId the node ID
13146             * @param head the head
13147             * @param status the status
13148             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13149             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
13150             * @throws SystemException if a system exception occurred
13151             */
13152            @Override
13153            public WikiPage fetchByN_H_S_Last(long nodeId, boolean head, int status,
13154                    OrderByComparator orderByComparator) throws SystemException {
13155                    int count = countByN_H_S(nodeId, head, status);
13156    
13157                    if (count == 0) {
13158                            return null;
13159                    }
13160    
13161                    List<WikiPage> list = findByN_H_S(nodeId, head, status, count - 1,
13162                                    count, orderByComparator);
13163    
13164                    if (!list.isEmpty()) {
13165                            return list.get(0);
13166                    }
13167    
13168                    return null;
13169            }
13170    
13171            /**
13172             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
13173             *
13174             * @param pageId the primary key of the current wiki page
13175             * @param nodeId the node ID
13176             * @param head the head
13177             * @param status the status
13178             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13179             * @return the previous, current, and next wiki page
13180             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
13181             * @throws SystemException if a system exception occurred
13182             */
13183            @Override
13184            public WikiPage[] findByN_H_S_PrevAndNext(long pageId, long nodeId,
13185                    boolean head, int status, OrderByComparator orderByComparator)
13186                    throws NoSuchPageException, SystemException {
13187                    WikiPage wikiPage = findByPrimaryKey(pageId);
13188    
13189                    Session session = null;
13190    
13191                    try {
13192                            session = openSession();
13193    
13194                            WikiPage[] array = new WikiPageImpl[3];
13195    
13196                            array[0] = getByN_H_S_PrevAndNext(session, wikiPage, nodeId, head,
13197                                            status, orderByComparator, true);
13198    
13199                            array[1] = wikiPage;
13200    
13201                            array[2] = getByN_H_S_PrevAndNext(session, wikiPage, nodeId, head,
13202                                            status, orderByComparator, false);
13203    
13204                            return array;
13205                    }
13206                    catch (Exception e) {
13207                            throw processException(e);
13208                    }
13209                    finally {
13210                            closeSession(session);
13211                    }
13212            }
13213    
13214            protected WikiPage getByN_H_S_PrevAndNext(Session session,
13215                    WikiPage wikiPage, long nodeId, boolean head, int status,
13216                    OrderByComparator orderByComparator, boolean previous) {
13217                    StringBundler query = null;
13218    
13219                    if (orderByComparator != null) {
13220                            query = new StringBundler(6 +
13221                                            (orderByComparator.getOrderByFields().length * 6));
13222                    }
13223                    else {
13224                            query = new StringBundler(3);
13225                    }
13226    
13227                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
13228    
13229                    query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
13230    
13231                    query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
13232    
13233                    query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
13234    
13235                    if (orderByComparator != null) {
13236                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13237    
13238                            if (orderByConditionFields.length > 0) {
13239                                    query.append(WHERE_AND);
13240                            }
13241    
13242                            for (int i = 0; i < orderByConditionFields.length; i++) {
13243                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13244                                    query.append(orderByConditionFields[i]);
13245    
13246                                    if ((i + 1) < orderByConditionFields.length) {
13247                                            if (orderByComparator.isAscending() ^ previous) {
13248                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13249                                            }
13250                                            else {
13251                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13252                                            }
13253                                    }
13254                                    else {
13255                                            if (orderByComparator.isAscending() ^ previous) {
13256                                                    query.append(WHERE_GREATER_THAN);
13257                                            }
13258                                            else {
13259                                                    query.append(WHERE_LESSER_THAN);
13260                                            }
13261                                    }
13262                            }
13263    
13264                            query.append(ORDER_BY_CLAUSE);
13265    
13266                            String[] orderByFields = orderByComparator.getOrderByFields();
13267    
13268                            for (int i = 0; i < orderByFields.length; i++) {
13269                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13270                                    query.append(orderByFields[i]);
13271    
13272                                    if ((i + 1) < orderByFields.length) {
13273                                            if (orderByComparator.isAscending() ^ previous) {
13274                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13275                                            }
13276                                            else {
13277                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13278                                            }
13279                                    }
13280                                    else {
13281                                            if (orderByComparator.isAscending() ^ previous) {
13282                                                    query.append(ORDER_BY_ASC);
13283                                            }
13284                                            else {
13285                                                    query.append(ORDER_BY_DESC);
13286                                            }
13287                                    }
13288                            }
13289                    }
13290                    else {
13291                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13292                    }
13293    
13294                    String sql = query.toString();
13295    
13296                    Query q = session.createQuery(sql);
13297    
13298                    q.setFirstResult(0);
13299                    q.setMaxResults(2);
13300    
13301                    QueryPos qPos = QueryPos.getInstance(q);
13302    
13303                    qPos.add(nodeId);
13304    
13305                    qPos.add(head);
13306    
13307                    qPos.add(status);
13308    
13309                    if (orderByComparator != null) {
13310                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
13311    
13312                            for (Object value : values) {
13313                                    qPos.add(value);
13314                            }
13315                    }
13316    
13317                    List<WikiPage> list = q.list();
13318    
13319                    if (list.size() == 2) {
13320                            return list.get(1);
13321                    }
13322                    else {
13323                            return null;
13324                    }
13325            }
13326    
13327            /**
13328             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63; from the database.
13329             *
13330             * @param nodeId the node ID
13331             * @param head the head
13332             * @param status the status
13333             * @throws SystemException if a system exception occurred
13334             */
13335            @Override
13336            public void removeByN_H_S(long nodeId, boolean head, int status)
13337                    throws SystemException {
13338                    for (WikiPage wikiPage : findByN_H_S(nodeId, head, status,
13339                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13340                            remove(wikiPage);
13341                    }
13342            }
13343    
13344            /**
13345             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
13346             *
13347             * @param nodeId the node ID
13348             * @param head the head
13349             * @param status the status
13350             * @return the number of matching wiki pages
13351             * @throws SystemException if a system exception occurred
13352             */
13353            @Override
13354            public int countByN_H_S(long nodeId, boolean head, int status)
13355                    throws SystemException {
13356                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_S;
13357    
13358                    Object[] finderArgs = new Object[] { nodeId, head, status };
13359    
13360                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
13361                                    this);
13362    
13363                    if (count == null) {
13364                            StringBundler query = new StringBundler(4);
13365    
13366                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
13367    
13368                            query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
13369    
13370                            query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
13371    
13372                            query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
13373    
13374                            String sql = query.toString();
13375    
13376                            Session session = null;
13377    
13378                            try {
13379                                    session = openSession();
13380    
13381                                    Query q = session.createQuery(sql);
13382    
13383                                    QueryPos qPos = QueryPos.getInstance(q);
13384    
13385                                    qPos.add(nodeId);
13386    
13387                                    qPos.add(head);
13388    
13389                                    qPos.add(status);
13390    
13391                                    count = (Long)q.uniqueResult();
13392    
13393                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
13394                            }
13395                            catch (Exception e) {
13396                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13397    
13398                                    throw processException(e);
13399                            }
13400                            finally {
13401                                    closeSession(session);
13402                            }
13403                    }
13404    
13405                    return count.intValue();
13406            }
13407    
13408            private static final String _FINDER_COLUMN_N_H_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
13409            private static final String _FINDER_COLUMN_N_H_S_HEAD_2 = "wikiPage.head = ? AND ";
13410            private static final String _FINDER_COLUMN_N_H_S_STATUS_2 = "wikiPage.status = ?";
13411            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_NOTS = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13412                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
13413                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_NotS",
13414                            new String[] {
13415                                    Long.class.getName(), Boolean.class.getName(),
13416                                    Integer.class.getName(),
13417                                    
13418                            Integer.class.getName(), Integer.class.getName(),
13419                                    OrderByComparator.class.getName()
13420                            });
13421            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_N_H_NOTS =
13422                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13423                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13424                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByN_H_NotS",
13425                            new String[] {
13426                                    Long.class.getName(), Boolean.class.getName(),
13427                                    Integer.class.getName()
13428                            });
13429    
13430            /**
13431             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and status &ne; &#63;.
13432             *
13433             * @param nodeId the node ID
13434             * @param head the head
13435             * @param status the status
13436             * @return the matching wiki pages
13437             * @throws SystemException if a system exception occurred
13438             */
13439            @Override
13440            public List<WikiPage> findByN_H_NotS(long nodeId, boolean head, int status)
13441                    throws SystemException {
13442                    return findByN_H_NotS(nodeId, head, status, QueryUtil.ALL_POS,
13443                            QueryUtil.ALL_POS, null);
13444            }
13445    
13446            /**
13447             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and status &ne; &#63;.
13448             *
13449             * <p>
13450             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
13451             * </p>
13452             *
13453             * @param nodeId the node ID
13454             * @param head the head
13455             * @param status the status
13456             * @param start the lower bound of the range of wiki pages
13457             * @param end the upper bound of the range of wiki pages (not inclusive)
13458             * @return the range of matching wiki pages
13459             * @throws SystemException if a system exception occurred
13460             */
13461            @Override
13462            public List<WikiPage> findByN_H_NotS(long nodeId, boolean head, int status,
13463                    int start, int end) throws SystemException {
13464                    return findByN_H_NotS(nodeId, head, status, start, end, null);
13465            }
13466    
13467            /**
13468             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and status &ne; &#63;.
13469             *
13470             * <p>
13471             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
13472             * </p>
13473             *
13474             * @param nodeId the node ID
13475             * @param head the head
13476             * @param status the status
13477             * @param start the lower bound of the range of wiki pages
13478             * @param end the upper bound of the range of wiki pages (not inclusive)
13479             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13480             * @return the ordered range of matching wiki pages
13481             * @throws SystemException if a system exception occurred
13482             */
13483            @Override
13484            public List<WikiPage> findByN_H_NotS(long nodeId, boolean head, int status,
13485                    int start, int end, OrderByComparator orderByComparator)
13486                    throws SystemException {
13487                    boolean pagination = true;
13488                    FinderPath finderPath = null;
13489                    Object[] finderArgs = null;
13490    
13491                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_NOTS;
13492                    finderArgs = new Object[] {
13493                                    nodeId, head, status,
13494                                    
13495                                    start, end, orderByComparator
13496                            };
13497    
13498                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
13499                                    finderArgs, this);
13500    
13501                    if ((list != null) && !list.isEmpty()) {
13502                            for (WikiPage wikiPage : list) {
13503                                    if ((nodeId != wikiPage.getNodeId()) ||
13504                                                    (head != wikiPage.getHead()) ||
13505                                                    (status == wikiPage.getStatus())) {
13506                                            list = null;
13507    
13508                                            break;
13509                                    }
13510                            }
13511                    }
13512    
13513                    if (list == null) {
13514                            StringBundler query = null;
13515    
13516                            if (orderByComparator != null) {
13517                                    query = new StringBundler(5 +
13518                                                    (orderByComparator.getOrderByFields().length * 3));
13519                            }
13520                            else {
13521                                    query = new StringBundler(5);
13522                            }
13523    
13524                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
13525    
13526                            query.append(_FINDER_COLUMN_N_H_NOTS_NODEID_2);
13527    
13528                            query.append(_FINDER_COLUMN_N_H_NOTS_HEAD_2);
13529    
13530                            query.append(_FINDER_COLUMN_N_H_NOTS_STATUS_2);
13531    
13532                            if (orderByComparator != null) {
13533                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13534                                            orderByComparator);
13535                            }
13536                            else
13537                             if (pagination) {
13538                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13539                            }
13540    
13541                            String sql = query.toString();
13542    
13543                            Session session = null;
13544    
13545                            try {
13546                                    session = openSession();
13547    
13548                                    Query q = session.createQuery(sql);
13549    
13550                                    QueryPos qPos = QueryPos.getInstance(q);
13551    
13552                                    qPos.add(nodeId);
13553    
13554                                    qPos.add(head);
13555    
13556                                    qPos.add(status);
13557    
13558                                    if (!pagination) {
13559                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13560                                                            start, end, false);
13561    
13562                                            Collections.sort(list);
13563    
13564                                            list = new UnmodifiableList<WikiPage>(list);
13565                                    }
13566                                    else {
13567                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13568                                                            start, end);
13569                                    }
13570    
13571                                    cacheResult(list);
13572    
13573                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13574                            }
13575                            catch (Exception e) {
13576                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13577    
13578                                    throw processException(e);
13579                            }
13580                            finally {
13581                                    closeSession(session);
13582                            }
13583                    }
13584    
13585                    return list;
13586            }
13587    
13588            /**
13589             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and status &ne; &#63;.
13590             *
13591             * @param nodeId the node ID
13592             * @param head the head
13593             * @param status the status
13594             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13595             * @return the first matching wiki page
13596             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13597             * @throws SystemException if a system exception occurred
13598             */
13599            @Override
13600            public WikiPage findByN_H_NotS_First(long nodeId, boolean head, int status,
13601                    OrderByComparator orderByComparator)
13602                    throws NoSuchPageException, SystemException {
13603                    WikiPage wikiPage = fetchByN_H_NotS_First(nodeId, head, status,
13604                                    orderByComparator);
13605    
13606                    if (wikiPage != null) {
13607                            return wikiPage;
13608                    }
13609    
13610                    StringBundler msg = new StringBundler(8);
13611    
13612                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13613    
13614                    msg.append("nodeId=");
13615                    msg.append(nodeId);
13616    
13617                    msg.append(", head=");
13618                    msg.append(head);
13619    
13620                    msg.append(", status=");
13621                    msg.append(status);
13622    
13623                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13624    
13625                    throw new NoSuchPageException(msg.toString());
13626            }
13627    
13628            /**
13629             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and status &ne; &#63;.
13630             *
13631             * @param nodeId the node ID
13632             * @param head the head
13633             * @param status the status
13634             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13635             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
13636             * @throws SystemException if a system exception occurred
13637             */
13638            @Override
13639            public WikiPage fetchByN_H_NotS_First(long nodeId, boolean head,
13640                    int status, OrderByComparator orderByComparator)
13641                    throws SystemException {
13642                    List<WikiPage> list = findByN_H_NotS(nodeId, head, status, 0, 1,
13643                                    orderByComparator);
13644    
13645                    if (!list.isEmpty()) {
13646                            return list.get(0);
13647                    }
13648    
13649                    return null;
13650            }
13651    
13652            /**
13653             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and status &ne; &#63;.
13654             *
13655             * @param nodeId the node ID
13656             * @param head the head
13657             * @param status the status
13658             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13659             * @return the last matching wiki page
13660             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13661             * @throws SystemException if a system exception occurred
13662             */
13663            @Override
13664            public WikiPage findByN_H_NotS_Last(long nodeId, boolean head, int status,
13665                    OrderByComparator orderByComparator)
13666                    throws NoSuchPageException, SystemException {
13667                    WikiPage wikiPage = fetchByN_H_NotS_Last(nodeId, head, status,
13668                                    orderByComparator);
13669    
13670                    if (wikiPage != null) {
13671                            return wikiPage;
13672                    }
13673    
13674                    StringBundler msg = new StringBundler(8);
13675    
13676                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13677    
13678                    msg.append("nodeId=");
13679                    msg.append(nodeId);
13680    
13681                    msg.append(", head=");
13682                    msg.append(head);
13683    
13684                    msg.append(", status=");
13685                    msg.append(status);
13686    
13687                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13688    
13689                    throw new NoSuchPageException(msg.toString());
13690            }
13691    
13692            /**
13693             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and status &ne; &#63;.
13694             *
13695             * @param nodeId the node ID
13696             * @param head the head
13697             * @param status the status
13698             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13699             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
13700             * @throws SystemException if a system exception occurred
13701             */
13702            @Override
13703            public WikiPage fetchByN_H_NotS_Last(long nodeId, boolean head, int status,
13704                    OrderByComparator orderByComparator) throws SystemException {
13705                    int count = countByN_H_NotS(nodeId, head, status);
13706    
13707                    if (count == 0) {
13708                            return null;
13709                    }
13710    
13711                    List<WikiPage> list = findByN_H_NotS(nodeId, head, status, count - 1,
13712                                    count, orderByComparator);
13713    
13714                    if (!list.isEmpty()) {
13715                            return list.get(0);
13716                    }
13717    
13718                    return null;
13719            }
13720    
13721            /**
13722             * 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;.
13723             *
13724             * @param pageId the primary key of the current wiki page
13725             * @param nodeId the node ID
13726             * @param head the head
13727             * @param status the status
13728             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13729             * @return the previous, current, and next wiki page
13730             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
13731             * @throws SystemException if a system exception occurred
13732             */
13733            @Override
13734            public WikiPage[] findByN_H_NotS_PrevAndNext(long pageId, long nodeId,
13735                    boolean head, int status, OrderByComparator orderByComparator)
13736                    throws NoSuchPageException, SystemException {
13737                    WikiPage wikiPage = findByPrimaryKey(pageId);
13738    
13739                    Session session = null;
13740    
13741                    try {
13742                            session = openSession();
13743    
13744                            WikiPage[] array = new WikiPageImpl[3];
13745    
13746                            array[0] = getByN_H_NotS_PrevAndNext(session, wikiPage, nodeId,
13747                                            head, status, orderByComparator, true);
13748    
13749                            array[1] = wikiPage;
13750    
13751                            array[2] = getByN_H_NotS_PrevAndNext(session, wikiPage, nodeId,
13752                                            head, status, orderByComparator, false);
13753    
13754                            return array;
13755                    }
13756                    catch (Exception e) {
13757                            throw processException(e);
13758                    }
13759                    finally {
13760                            closeSession(session);
13761                    }
13762            }
13763    
13764            protected WikiPage getByN_H_NotS_PrevAndNext(Session session,
13765                    WikiPage wikiPage, long nodeId, boolean head, int status,
13766                    OrderByComparator orderByComparator, boolean previous) {
13767                    StringBundler query = null;
13768    
13769                    if (orderByComparator != null) {
13770                            query = new StringBundler(6 +
13771                                            (orderByComparator.getOrderByFields().length * 6));
13772                    }
13773                    else {
13774                            query = new StringBundler(3);
13775                    }
13776    
13777                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
13778    
13779                    query.append(_FINDER_COLUMN_N_H_NOTS_NODEID_2);
13780    
13781                    query.append(_FINDER_COLUMN_N_H_NOTS_HEAD_2);
13782    
13783                    query.append(_FINDER_COLUMN_N_H_NOTS_STATUS_2);
13784    
13785                    if (orderByComparator != null) {
13786                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13787    
13788                            if (orderByConditionFields.length > 0) {
13789                                    query.append(WHERE_AND);
13790                            }
13791    
13792                            for (int i = 0; i < orderByConditionFields.length; i++) {
13793                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13794                                    query.append(orderByConditionFields[i]);
13795    
13796                                    if ((i + 1) < orderByConditionFields.length) {
13797                                            if (orderByComparator.isAscending() ^ previous) {
13798                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13799                                            }
13800                                            else {
13801                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13802                                            }
13803                                    }
13804                                    else {
13805                                            if (orderByComparator.isAscending() ^ previous) {
13806                                                    query.append(WHERE_GREATER_THAN);
13807                                            }
13808                                            else {
13809                                                    query.append(WHERE_LESSER_THAN);
13810                                            }
13811                                    }
13812                            }
13813    
13814                            query.append(ORDER_BY_CLAUSE);
13815    
13816                            String[] orderByFields = orderByComparator.getOrderByFields();
13817    
13818                            for (int i = 0; i < orderByFields.length; i++) {
13819                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13820                                    query.append(orderByFields[i]);
13821    
13822                                    if ((i + 1) < orderByFields.length) {
13823                                            if (orderByComparator.isAscending() ^ previous) {
13824                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13825                                            }
13826                                            else {
13827                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13828                                            }
13829                                    }
13830                                    else {
13831                                            if (orderByComparator.isAscending() ^ previous) {
13832                                                    query.append(ORDER_BY_ASC);
13833                                            }
13834                                            else {
13835                                                    query.append(ORDER_BY_DESC);
13836                                            }
13837                                    }
13838                            }
13839                    }
13840                    else {
13841                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13842                    }
13843    
13844                    String sql = query.toString();
13845    
13846                    Query q = session.createQuery(sql);
13847    
13848                    q.setFirstResult(0);
13849                    q.setMaxResults(2);
13850    
13851                    QueryPos qPos = QueryPos.getInstance(q);
13852    
13853                    qPos.add(nodeId);
13854    
13855                    qPos.add(head);
13856    
13857                    qPos.add(status);
13858    
13859                    if (orderByComparator != null) {
13860                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
13861    
13862                            for (Object value : values) {
13863                                    qPos.add(value);
13864                            }
13865                    }
13866    
13867                    List<WikiPage> list = q.list();
13868    
13869                    if (list.size() == 2) {
13870                            return list.get(1);
13871                    }
13872                    else {
13873                            return null;
13874                    }
13875            }
13876    
13877            /**
13878             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and status &ne; &#63; from the database.
13879             *
13880             * @param nodeId the node ID
13881             * @param head the head
13882             * @param status the status
13883             * @throws SystemException if a system exception occurred
13884             */
13885            @Override
13886            public void removeByN_H_NotS(long nodeId, boolean head, int status)
13887                    throws SystemException {
13888                    for (WikiPage wikiPage : findByN_H_NotS(nodeId, head, status,
13889                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13890                            remove(wikiPage);
13891                    }
13892            }
13893    
13894            /**
13895             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and status &ne; &#63;.
13896             *
13897             * @param nodeId the node ID
13898             * @param head the head
13899             * @param status the status
13900             * @return the number of matching wiki pages
13901             * @throws SystemException if a system exception occurred
13902             */
13903            @Override
13904            public int countByN_H_NotS(long nodeId, boolean head, int status)
13905                    throws SystemException {
13906                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_N_H_NOTS;
13907    
13908                    Object[] finderArgs = new Object[] { nodeId, head, status };
13909    
13910                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
13911                                    this);
13912    
13913                    if (count == null) {
13914                            StringBundler query = new StringBundler(4);
13915    
13916                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
13917    
13918                            query.append(_FINDER_COLUMN_N_H_NOTS_NODEID_2);
13919    
13920                            query.append(_FINDER_COLUMN_N_H_NOTS_HEAD_2);
13921    
13922                            query.append(_FINDER_COLUMN_N_H_NOTS_STATUS_2);
13923    
13924                            String sql = query.toString();
13925    
13926                            Session session = null;
13927    
13928                            try {
13929                                    session = openSession();
13930    
13931                                    Query q = session.createQuery(sql);
13932    
13933                                    QueryPos qPos = QueryPos.getInstance(q);
13934    
13935                                    qPos.add(nodeId);
13936    
13937                                    qPos.add(head);
13938    
13939                                    qPos.add(status);
13940    
13941                                    count = (Long)q.uniqueResult();
13942    
13943                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
13944                            }
13945                            catch (Exception e) {
13946                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13947    
13948                                    throw processException(e);
13949                            }
13950                            finally {
13951                                    closeSession(session);
13952                            }
13953                    }
13954    
13955                    return count.intValue();
13956            }
13957    
13958            private static final String _FINDER_COLUMN_N_H_NOTS_NODEID_2 = "wikiPage.nodeId = ? AND ";
13959            private static final String _FINDER_COLUMN_N_H_NOTS_HEAD_2 = "wikiPage.head = ? AND ";
13960            private static final String _FINDER_COLUMN_N_H_NOTS_STATUS_2 = "wikiPage.status != ?";
13961            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13962                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
13963                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_N_S",
13964                            new String[] {
13965                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
13966                                    Integer.class.getName(),
13967                                    
13968                            Integer.class.getName(), Integer.class.getName(),
13969                                    OrderByComparator.class.getName()
13970                            });
13971            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S =
13972                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13973                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
13974                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_N_S",
13975                            new String[] {
13976                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
13977                                    Integer.class.getName()
13978                            },
13979                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
13980                            WikiPageModelImpl.USERID_COLUMN_BITMASK |
13981                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
13982                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
13983                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
13984                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
13985            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13986                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13987                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_N_S",
13988                            new String[] {
13989                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
13990                                    Integer.class.getName()
13991                            });
13992    
13993            /**
13994             * Returns all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
13995             *
13996             * @param groupId the group ID
13997             * @param userId the user ID
13998             * @param nodeId the node ID
13999             * @param status the status
14000             * @return the matching wiki pages
14001             * @throws SystemException if a system exception occurred
14002             */
14003            @Override
14004            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
14005                    int status) throws SystemException {
14006                    return findByG_U_N_S(groupId, userId, nodeId, status,
14007                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14008            }
14009    
14010            /**
14011             * Returns a range of all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14012             *
14013             * <p>
14014             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
14015             * </p>
14016             *
14017             * @param groupId the group ID
14018             * @param userId the user ID
14019             * @param nodeId the node ID
14020             * @param status the status
14021             * @param start the lower bound of the range of wiki pages
14022             * @param end the upper bound of the range of wiki pages (not inclusive)
14023             * @return the range of matching wiki pages
14024             * @throws SystemException if a system exception occurred
14025             */
14026            @Override
14027            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
14028                    int status, int start, int end) throws SystemException {
14029                    return findByG_U_N_S(groupId, userId, nodeId, status, start, end, null);
14030            }
14031    
14032            /**
14033             * Returns an ordered range of all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14034             *
14035             * <p>
14036             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
14037             * </p>
14038             *
14039             * @param groupId the group ID
14040             * @param userId the user ID
14041             * @param nodeId the node ID
14042             * @param status the status
14043             * @param start the lower bound of the range of wiki pages
14044             * @param end the upper bound of the range of wiki pages (not inclusive)
14045             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14046             * @return the ordered range of matching wiki pages
14047             * @throws SystemException if a system exception occurred
14048             */
14049            @Override
14050            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
14051                    int status, int start, int end, OrderByComparator orderByComparator)
14052                    throws SystemException {
14053                    boolean pagination = true;
14054                    FinderPath finderPath = null;
14055                    Object[] finderArgs = null;
14056    
14057                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14058                                    (orderByComparator == null)) {
14059                            pagination = false;
14060                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S;
14061                            finderArgs = new Object[] { groupId, userId, nodeId, status };
14062                    }
14063                    else {
14064                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_N_S;
14065                            finderArgs = new Object[] {
14066                                            groupId, userId, nodeId, status,
14067                                            
14068                                            start, end, orderByComparator
14069                                    };
14070                    }
14071    
14072                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
14073                                    finderArgs, this);
14074    
14075                    if ((list != null) && !list.isEmpty()) {
14076                            for (WikiPage wikiPage : list) {
14077                                    if ((groupId != wikiPage.getGroupId()) ||
14078                                                    (userId != wikiPage.getUserId()) ||
14079                                                    (nodeId != wikiPage.getNodeId()) ||
14080                                                    (status != wikiPage.getStatus())) {
14081                                            list = null;
14082    
14083                                            break;
14084                                    }
14085                            }
14086                    }
14087    
14088                    if (list == null) {
14089                            StringBundler query = null;
14090    
14091                            if (orderByComparator != null) {
14092                                    query = new StringBundler(6 +
14093                                                    (orderByComparator.getOrderByFields().length * 3));
14094                            }
14095                            else {
14096                                    query = new StringBundler(6);
14097                            }
14098    
14099                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
14100    
14101                            query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
14102    
14103                            query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
14104    
14105                            query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
14106    
14107                            query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
14108    
14109                            if (orderByComparator != null) {
14110                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14111                                            orderByComparator);
14112                            }
14113                            else
14114                             if (pagination) {
14115                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14116                            }
14117    
14118                            String sql = query.toString();
14119    
14120                            Session session = null;
14121    
14122                            try {
14123                                    session = openSession();
14124    
14125                                    Query q = session.createQuery(sql);
14126    
14127                                    QueryPos qPos = QueryPos.getInstance(q);
14128    
14129                                    qPos.add(groupId);
14130    
14131                                    qPos.add(userId);
14132    
14133                                    qPos.add(nodeId);
14134    
14135                                    qPos.add(status);
14136    
14137                                    if (!pagination) {
14138                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
14139                                                            start, end, false);
14140    
14141                                            Collections.sort(list);
14142    
14143                                            list = new UnmodifiableList<WikiPage>(list);
14144                                    }
14145                                    else {
14146                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
14147                                                            start, end);
14148                                    }
14149    
14150                                    cacheResult(list);
14151    
14152                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
14153                            }
14154                            catch (Exception e) {
14155                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14156    
14157                                    throw processException(e);
14158                            }
14159                            finally {
14160                                    closeSession(session);
14161                            }
14162                    }
14163    
14164                    return list;
14165            }
14166    
14167            /**
14168             * Returns the first wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14169             *
14170             * @param groupId the group ID
14171             * @param userId the user ID
14172             * @param nodeId the node ID
14173             * @param status the status
14174             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14175             * @return the first matching wiki page
14176             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
14177             * @throws SystemException if a system exception occurred
14178             */
14179            @Override
14180            public WikiPage findByG_U_N_S_First(long groupId, long userId, long nodeId,
14181                    int status, OrderByComparator orderByComparator)
14182                    throws NoSuchPageException, SystemException {
14183                    WikiPage wikiPage = fetchByG_U_N_S_First(groupId, userId, nodeId,
14184                                    status, orderByComparator);
14185    
14186                    if (wikiPage != null) {
14187                            return wikiPage;
14188                    }
14189    
14190                    StringBundler msg = new StringBundler(10);
14191    
14192                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14193    
14194                    msg.append("groupId=");
14195                    msg.append(groupId);
14196    
14197                    msg.append(", userId=");
14198                    msg.append(userId);
14199    
14200                    msg.append(", nodeId=");
14201                    msg.append(nodeId);
14202    
14203                    msg.append(", status=");
14204                    msg.append(status);
14205    
14206                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14207    
14208                    throw new NoSuchPageException(msg.toString());
14209            }
14210    
14211            /**
14212             * Returns the first wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14213             *
14214             * @param groupId the group ID
14215             * @param userId the user ID
14216             * @param nodeId the node ID
14217             * @param status the status
14218             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14219             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
14220             * @throws SystemException if a system exception occurred
14221             */
14222            @Override
14223            public WikiPage fetchByG_U_N_S_First(long groupId, long userId,
14224                    long nodeId, int status, OrderByComparator orderByComparator)
14225                    throws SystemException {
14226                    List<WikiPage> list = findByG_U_N_S(groupId, userId, nodeId, status, 0,
14227                                    1, orderByComparator);
14228    
14229                    if (!list.isEmpty()) {
14230                            return list.get(0);
14231                    }
14232    
14233                    return null;
14234            }
14235    
14236            /**
14237             * Returns the last wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14238             *
14239             * @param groupId the group ID
14240             * @param userId the user ID
14241             * @param nodeId the node ID
14242             * @param status the status
14243             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14244             * @return the last matching wiki page
14245             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
14246             * @throws SystemException if a system exception occurred
14247             */
14248            @Override
14249            public WikiPage findByG_U_N_S_Last(long groupId, long userId, long nodeId,
14250                    int status, OrderByComparator orderByComparator)
14251                    throws NoSuchPageException, SystemException {
14252                    WikiPage wikiPage = fetchByG_U_N_S_Last(groupId, userId, nodeId,
14253                                    status, orderByComparator);
14254    
14255                    if (wikiPage != null) {
14256                            return wikiPage;
14257                    }
14258    
14259                    StringBundler msg = new StringBundler(10);
14260    
14261                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14262    
14263                    msg.append("groupId=");
14264                    msg.append(groupId);
14265    
14266                    msg.append(", userId=");
14267                    msg.append(userId);
14268    
14269                    msg.append(", nodeId=");
14270                    msg.append(nodeId);
14271    
14272                    msg.append(", status=");
14273                    msg.append(status);
14274    
14275                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14276    
14277                    throw new NoSuchPageException(msg.toString());
14278            }
14279    
14280            /**
14281             * Returns the last wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14282             *
14283             * @param groupId the group ID
14284             * @param userId the user ID
14285             * @param nodeId the node ID
14286             * @param status the status
14287             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14288             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
14289             * @throws SystemException if a system exception occurred
14290             */
14291            @Override
14292            public WikiPage fetchByG_U_N_S_Last(long groupId, long userId, long nodeId,
14293                    int status, OrderByComparator orderByComparator)
14294                    throws SystemException {
14295                    int count = countByG_U_N_S(groupId, userId, nodeId, status);
14296    
14297                    if (count == 0) {
14298                            return null;
14299                    }
14300    
14301                    List<WikiPage> list = findByG_U_N_S(groupId, userId, nodeId, status,
14302                                    count - 1, count, orderByComparator);
14303    
14304                    if (!list.isEmpty()) {
14305                            return list.get(0);
14306                    }
14307    
14308                    return null;
14309            }
14310    
14311            /**
14312             * 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;.
14313             *
14314             * @param pageId the primary key of the current wiki page
14315             * @param groupId the group ID
14316             * @param userId the user ID
14317             * @param nodeId the node ID
14318             * @param status the status
14319             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14320             * @return the previous, current, and next wiki page
14321             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
14322             * @throws SystemException if a system exception occurred
14323             */
14324            @Override
14325            public WikiPage[] findByG_U_N_S_PrevAndNext(long pageId, long groupId,
14326                    long userId, long nodeId, int status,
14327                    OrderByComparator orderByComparator)
14328                    throws NoSuchPageException, SystemException {
14329                    WikiPage wikiPage = findByPrimaryKey(pageId);
14330    
14331                    Session session = null;
14332    
14333                    try {
14334                            session = openSession();
14335    
14336                            WikiPage[] array = new WikiPageImpl[3];
14337    
14338                            array[0] = getByG_U_N_S_PrevAndNext(session, wikiPage, groupId,
14339                                            userId, nodeId, status, orderByComparator, true);
14340    
14341                            array[1] = wikiPage;
14342    
14343                            array[2] = getByG_U_N_S_PrevAndNext(session, wikiPage, groupId,
14344                                            userId, nodeId, status, orderByComparator, false);
14345    
14346                            return array;
14347                    }
14348                    catch (Exception e) {
14349                            throw processException(e);
14350                    }
14351                    finally {
14352                            closeSession(session);
14353                    }
14354            }
14355    
14356            protected WikiPage getByG_U_N_S_PrevAndNext(Session session,
14357                    WikiPage wikiPage, long groupId, long userId, long nodeId, int status,
14358                    OrderByComparator orderByComparator, boolean previous) {
14359                    StringBundler query = null;
14360    
14361                    if (orderByComparator != null) {
14362                            query = new StringBundler(6 +
14363                                            (orderByComparator.getOrderByFields().length * 6));
14364                    }
14365                    else {
14366                            query = new StringBundler(3);
14367                    }
14368    
14369                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
14370    
14371                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
14372    
14373                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
14374    
14375                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
14376    
14377                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
14378    
14379                    if (orderByComparator != null) {
14380                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14381    
14382                            if (orderByConditionFields.length > 0) {
14383                                    query.append(WHERE_AND);
14384                            }
14385    
14386                            for (int i = 0; i < orderByConditionFields.length; i++) {
14387                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14388                                    query.append(orderByConditionFields[i]);
14389    
14390                                    if ((i + 1) < orderByConditionFields.length) {
14391                                            if (orderByComparator.isAscending() ^ previous) {
14392                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14393                                            }
14394                                            else {
14395                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14396                                            }
14397                                    }
14398                                    else {
14399                                            if (orderByComparator.isAscending() ^ previous) {
14400                                                    query.append(WHERE_GREATER_THAN);
14401                                            }
14402                                            else {
14403                                                    query.append(WHERE_LESSER_THAN);
14404                                            }
14405                                    }
14406                            }
14407    
14408                            query.append(ORDER_BY_CLAUSE);
14409    
14410                            String[] orderByFields = orderByComparator.getOrderByFields();
14411    
14412                            for (int i = 0; i < orderByFields.length; i++) {
14413                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14414                                    query.append(orderByFields[i]);
14415    
14416                                    if ((i + 1) < orderByFields.length) {
14417                                            if (orderByComparator.isAscending() ^ previous) {
14418                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14419                                            }
14420                                            else {
14421                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14422                                            }
14423                                    }
14424                                    else {
14425                                            if (orderByComparator.isAscending() ^ previous) {
14426                                                    query.append(ORDER_BY_ASC);
14427                                            }
14428                                            else {
14429                                                    query.append(ORDER_BY_DESC);
14430                                            }
14431                                    }
14432                            }
14433                    }
14434                    else {
14435                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14436                    }
14437    
14438                    String sql = query.toString();
14439    
14440                    Query q = session.createQuery(sql);
14441    
14442                    q.setFirstResult(0);
14443                    q.setMaxResults(2);
14444    
14445                    QueryPos qPos = QueryPos.getInstance(q);
14446    
14447                    qPos.add(groupId);
14448    
14449                    qPos.add(userId);
14450    
14451                    qPos.add(nodeId);
14452    
14453                    qPos.add(status);
14454    
14455                    if (orderByComparator != null) {
14456                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
14457    
14458                            for (Object value : values) {
14459                                    qPos.add(value);
14460                            }
14461                    }
14462    
14463                    List<WikiPage> list = q.list();
14464    
14465                    if (list.size() == 2) {
14466                            return list.get(1);
14467                    }
14468                    else {
14469                            return null;
14470                    }
14471            }
14472    
14473            /**
14474             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14475             *
14476             * @param groupId the group ID
14477             * @param userId the user ID
14478             * @param nodeId the node ID
14479             * @param status the status
14480             * @return the matching wiki pages that the user has permission to view
14481             * @throws SystemException if a system exception occurred
14482             */
14483            @Override
14484            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
14485                    long nodeId, int status) throws SystemException {
14486                    return filterFindByG_U_N_S(groupId, userId, nodeId, status,
14487                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14488            }
14489    
14490            /**
14491             * 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;.
14492             *
14493             * <p>
14494             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
14495             * </p>
14496             *
14497             * @param groupId the group ID
14498             * @param userId the user ID
14499             * @param nodeId the node ID
14500             * @param status the status
14501             * @param start the lower bound of the range of wiki pages
14502             * @param end the upper bound of the range of wiki pages (not inclusive)
14503             * @return the range of matching wiki pages that the user has permission to view
14504             * @throws SystemException if a system exception occurred
14505             */
14506            @Override
14507            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
14508                    long nodeId, int status, int start, int end) throws SystemException {
14509                    return filterFindByG_U_N_S(groupId, userId, nodeId, status, start, end,
14510                            null);
14511            }
14512    
14513            /**
14514             * 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;.
14515             *
14516             * <p>
14517             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
14518             * </p>
14519             *
14520             * @param groupId the group ID
14521             * @param userId the user ID
14522             * @param nodeId the node ID
14523             * @param status the status
14524             * @param start the lower bound of the range of wiki pages
14525             * @param end the upper bound of the range of wiki pages (not inclusive)
14526             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14527             * @return the ordered range of matching wiki pages that the user has permission to view
14528             * @throws SystemException if a system exception occurred
14529             */
14530            @Override
14531            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
14532                    long nodeId, int status, int start, int end,
14533                    OrderByComparator orderByComparator) throws SystemException {
14534                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14535                            return findByG_U_N_S(groupId, userId, nodeId, status, start, end,
14536                                    orderByComparator);
14537                    }
14538    
14539                    StringBundler query = null;
14540    
14541                    if (orderByComparator != null) {
14542                            query = new StringBundler(6 +
14543                                            (orderByComparator.getOrderByFields().length * 3));
14544                    }
14545                    else {
14546                            query = new StringBundler(6);
14547                    }
14548    
14549                    if (getDB().isSupportsInlineDistinct()) {
14550                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
14551                    }
14552                    else {
14553                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
14554                    }
14555    
14556                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
14557    
14558                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
14559    
14560                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
14561    
14562                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
14563    
14564                    if (!getDB().isSupportsInlineDistinct()) {
14565                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
14566                    }
14567    
14568                    if (orderByComparator != null) {
14569                            if (getDB().isSupportsInlineDistinct()) {
14570                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14571                                            orderByComparator, true);
14572                            }
14573                            else {
14574                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
14575                                            orderByComparator, true);
14576                            }
14577                    }
14578                    else {
14579                            if (getDB().isSupportsInlineDistinct()) {
14580                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14581                            }
14582                            else {
14583                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
14584                            }
14585                    }
14586    
14587                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14588                                    WikiPage.class.getName(),
14589                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14590    
14591                    Session session = null;
14592    
14593                    try {
14594                            session = openSession();
14595    
14596                            SQLQuery q = session.createSQLQuery(sql);
14597    
14598                            if (getDB().isSupportsInlineDistinct()) {
14599                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
14600                            }
14601                            else {
14602                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
14603                            }
14604    
14605                            QueryPos qPos = QueryPos.getInstance(q);
14606    
14607                            qPos.add(groupId);
14608    
14609                            qPos.add(userId);
14610    
14611                            qPos.add(nodeId);
14612    
14613                            qPos.add(status);
14614    
14615                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
14616                    }
14617                    catch (Exception e) {
14618                            throw processException(e);
14619                    }
14620                    finally {
14621                            closeSession(session);
14622                    }
14623            }
14624    
14625            /**
14626             * 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;.
14627             *
14628             * @param pageId the primary key of the current wiki page
14629             * @param groupId the group ID
14630             * @param userId the user ID
14631             * @param nodeId the node ID
14632             * @param status the status
14633             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14634             * @return the previous, current, and next wiki page
14635             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
14636             * @throws SystemException if a system exception occurred
14637             */
14638            @Override
14639            public WikiPage[] filterFindByG_U_N_S_PrevAndNext(long pageId,
14640                    long groupId, long userId, long nodeId, int status,
14641                    OrderByComparator orderByComparator)
14642                    throws NoSuchPageException, SystemException {
14643                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14644                            return findByG_U_N_S_PrevAndNext(pageId, groupId, userId, nodeId,
14645                                    status, orderByComparator);
14646                    }
14647    
14648                    WikiPage wikiPage = findByPrimaryKey(pageId);
14649    
14650                    Session session = null;
14651    
14652                    try {
14653                            session = openSession();
14654    
14655                            WikiPage[] array = new WikiPageImpl[3];
14656    
14657                            array[0] = filterGetByG_U_N_S_PrevAndNext(session, wikiPage,
14658                                            groupId, userId, nodeId, status, orderByComparator, true);
14659    
14660                            array[1] = wikiPage;
14661    
14662                            array[2] = filterGetByG_U_N_S_PrevAndNext(session, wikiPage,
14663                                            groupId, userId, nodeId, status, orderByComparator, false);
14664    
14665                            return array;
14666                    }
14667                    catch (Exception e) {
14668                            throw processException(e);
14669                    }
14670                    finally {
14671                            closeSession(session);
14672                    }
14673            }
14674    
14675            protected WikiPage filterGetByG_U_N_S_PrevAndNext(Session session,
14676                    WikiPage wikiPage, long groupId, long userId, long nodeId, int status,
14677                    OrderByComparator orderByComparator, boolean previous) {
14678                    StringBundler query = null;
14679    
14680                    if (orderByComparator != null) {
14681                            query = new StringBundler(6 +
14682                                            (orderByComparator.getOrderByFields().length * 6));
14683                    }
14684                    else {
14685                            query = new StringBundler(3);
14686                    }
14687    
14688                    if (getDB().isSupportsInlineDistinct()) {
14689                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
14690                    }
14691                    else {
14692                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
14693                    }
14694    
14695                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
14696    
14697                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
14698    
14699                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
14700    
14701                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
14702    
14703                    if (!getDB().isSupportsInlineDistinct()) {
14704                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
14705                    }
14706    
14707                    if (orderByComparator != null) {
14708                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14709    
14710                            if (orderByConditionFields.length > 0) {
14711                                    query.append(WHERE_AND);
14712                            }
14713    
14714                            for (int i = 0; i < orderByConditionFields.length; i++) {
14715                                    if (getDB().isSupportsInlineDistinct()) {
14716                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14717                                    }
14718                                    else {
14719                                            query.append(_ORDER_BY_ENTITY_TABLE);
14720                                    }
14721    
14722                                    query.append(orderByConditionFields[i]);
14723    
14724                                    if ((i + 1) < orderByConditionFields.length) {
14725                                            if (orderByComparator.isAscending() ^ previous) {
14726                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14727                                            }
14728                                            else {
14729                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14730                                            }
14731                                    }
14732                                    else {
14733                                            if (orderByComparator.isAscending() ^ previous) {
14734                                                    query.append(WHERE_GREATER_THAN);
14735                                            }
14736                                            else {
14737                                                    query.append(WHERE_LESSER_THAN);
14738                                            }
14739                                    }
14740                            }
14741    
14742                            query.append(ORDER_BY_CLAUSE);
14743    
14744                            String[] orderByFields = orderByComparator.getOrderByFields();
14745    
14746                            for (int i = 0; i < orderByFields.length; i++) {
14747                                    if (getDB().isSupportsInlineDistinct()) {
14748                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14749                                    }
14750                                    else {
14751                                            query.append(_ORDER_BY_ENTITY_TABLE);
14752                                    }
14753    
14754                                    query.append(orderByFields[i]);
14755    
14756                                    if ((i + 1) < orderByFields.length) {
14757                                            if (orderByComparator.isAscending() ^ previous) {
14758                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14759                                            }
14760                                            else {
14761                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14762                                            }
14763                                    }
14764                                    else {
14765                                            if (orderByComparator.isAscending() ^ previous) {
14766                                                    query.append(ORDER_BY_ASC);
14767                                            }
14768                                            else {
14769                                                    query.append(ORDER_BY_DESC);
14770                                            }
14771                                    }
14772                            }
14773                    }
14774                    else {
14775                            if (getDB().isSupportsInlineDistinct()) {
14776                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14777                            }
14778                            else {
14779                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
14780                            }
14781                    }
14782    
14783                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14784                                    WikiPage.class.getName(),
14785                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14786    
14787                    SQLQuery q = session.createSQLQuery(sql);
14788    
14789                    q.setFirstResult(0);
14790                    q.setMaxResults(2);
14791    
14792                    if (getDB().isSupportsInlineDistinct()) {
14793                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
14794                    }
14795                    else {
14796                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
14797                    }
14798    
14799                    QueryPos qPos = QueryPos.getInstance(q);
14800    
14801                    qPos.add(groupId);
14802    
14803                    qPos.add(userId);
14804    
14805                    qPos.add(nodeId);
14806    
14807                    qPos.add(status);
14808    
14809                    if (orderByComparator != null) {
14810                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
14811    
14812                            for (Object value : values) {
14813                                    qPos.add(value);
14814                            }
14815                    }
14816    
14817                    List<WikiPage> list = q.list();
14818    
14819                    if (list.size() == 2) {
14820                            return list.get(1);
14821                    }
14822                    else {
14823                            return null;
14824                    }
14825            }
14826    
14827            /**
14828             * Removes all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63; from the database.
14829             *
14830             * @param groupId the group ID
14831             * @param userId the user ID
14832             * @param nodeId the node ID
14833             * @param status the status
14834             * @throws SystemException if a system exception occurred
14835             */
14836            @Override
14837            public void removeByG_U_N_S(long groupId, long userId, long nodeId,
14838                    int status) throws SystemException {
14839                    for (WikiPage wikiPage : findByG_U_N_S(groupId, userId, nodeId, status,
14840                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14841                            remove(wikiPage);
14842                    }
14843            }
14844    
14845            /**
14846             * Returns the number of wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14847             *
14848             * @param groupId the group ID
14849             * @param userId the user ID
14850             * @param nodeId the node ID
14851             * @param status the status
14852             * @return the number of matching wiki pages
14853             * @throws SystemException if a system exception occurred
14854             */
14855            @Override
14856            public int countByG_U_N_S(long groupId, long userId, long nodeId, int status)
14857                    throws SystemException {
14858                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_N_S;
14859    
14860                    Object[] finderArgs = new Object[] { groupId, userId, nodeId, status };
14861    
14862                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14863                                    this);
14864    
14865                    if (count == null) {
14866                            StringBundler query = new StringBundler(5);
14867    
14868                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
14869    
14870                            query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
14871    
14872                            query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
14873    
14874                            query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
14875    
14876                            query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
14877    
14878                            String sql = query.toString();
14879    
14880                            Session session = null;
14881    
14882                            try {
14883                                    session = openSession();
14884    
14885                                    Query q = session.createQuery(sql);
14886    
14887                                    QueryPos qPos = QueryPos.getInstance(q);
14888    
14889                                    qPos.add(groupId);
14890    
14891                                    qPos.add(userId);
14892    
14893                                    qPos.add(nodeId);
14894    
14895                                    qPos.add(status);
14896    
14897                                    count = (Long)q.uniqueResult();
14898    
14899                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14900                            }
14901                            catch (Exception e) {
14902                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14903    
14904                                    throw processException(e);
14905                            }
14906                            finally {
14907                                    closeSession(session);
14908                            }
14909                    }
14910    
14911                    return count.intValue();
14912            }
14913    
14914            /**
14915             * 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;.
14916             *
14917             * @param groupId the group ID
14918             * @param userId the user ID
14919             * @param nodeId the node ID
14920             * @param status the status
14921             * @return the number of matching wiki pages that the user has permission to view
14922             * @throws SystemException if a system exception occurred
14923             */
14924            @Override
14925            public int filterCountByG_U_N_S(long groupId, long userId, long nodeId,
14926                    int status) throws SystemException {
14927                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14928                            return countByG_U_N_S(groupId, userId, nodeId, status);
14929                    }
14930    
14931                    StringBundler query = new StringBundler(5);
14932    
14933                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
14934    
14935                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
14936    
14937                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
14938    
14939                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
14940    
14941                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
14942    
14943                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14944                                    WikiPage.class.getName(),
14945                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14946    
14947                    Session session = null;
14948    
14949                    try {
14950                            session = openSession();
14951    
14952                            SQLQuery q = session.createSQLQuery(sql);
14953    
14954                            q.addScalar(COUNT_COLUMN_NAME,
14955                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
14956    
14957                            QueryPos qPos = QueryPos.getInstance(q);
14958    
14959                            qPos.add(groupId);
14960    
14961                            qPos.add(userId);
14962    
14963                            qPos.add(nodeId);
14964    
14965                            qPos.add(status);
14966    
14967                            Long count = (Long)q.uniqueResult();
14968    
14969                            return count.intValue();
14970                    }
14971                    catch (Exception e) {
14972                            throw processException(e);
14973                    }
14974                    finally {
14975                            closeSession(session);
14976                    }
14977            }
14978    
14979            private static final String _FINDER_COLUMN_G_U_N_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
14980            private static final String _FINDER_COLUMN_G_U_N_S_USERID_2 = "wikiPage.userId = ? AND ";
14981            private static final String _FINDER_COLUMN_G_U_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
14982            private static final String _FINDER_COLUMN_G_U_N_S_STATUS_2 = "wikiPage.status = ?";
14983            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14984                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
14985                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_T_H",
14986                            new String[] {
14987                                    Long.class.getName(), Long.class.getName(),
14988                                    String.class.getName(), Boolean.class.getName(),
14989                                    
14990                            Integer.class.getName(), Integer.class.getName(),
14991                                    OrderByComparator.class.getName()
14992                            });
14993            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H =
14994                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14995                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
14996                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_T_H",
14997                            new String[] {
14998                                    Long.class.getName(), Long.class.getName(),
14999                                    String.class.getName(), Boolean.class.getName()
15000                            },
15001                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
15002                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
15003                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
15004                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
15005                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
15006            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15007                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15008                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_T_H",
15009                            new String[] {
15010                                    Long.class.getName(), Long.class.getName(),
15011                                    String.class.getName(), Boolean.class.getName()
15012                            });
15013    
15014            /**
15015             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15016             *
15017             * @param groupId the group ID
15018             * @param nodeId the node ID
15019             * @param title the title
15020             * @param head the head
15021             * @return the matching wiki pages
15022             * @throws SystemException if a system exception occurred
15023             */
15024            @Override
15025            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
15026                    String title, boolean head) throws SystemException {
15027                    return findByG_N_T_H(groupId, nodeId, title, head, QueryUtil.ALL_POS,
15028                            QueryUtil.ALL_POS, null);
15029            }
15030    
15031            /**
15032             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15033             *
15034             * <p>
15035             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
15036             * </p>
15037             *
15038             * @param groupId the group ID
15039             * @param nodeId the node ID
15040             * @param title the title
15041             * @param head the head
15042             * @param start the lower bound of the range of wiki pages
15043             * @param end the upper bound of the range of wiki pages (not inclusive)
15044             * @return the range of matching wiki pages
15045             * @throws SystemException if a system exception occurred
15046             */
15047            @Override
15048            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
15049                    String title, boolean head, int start, int end)
15050                    throws SystemException {
15051                    return findByG_N_T_H(groupId, nodeId, title, head, start, end, null);
15052            }
15053    
15054            /**
15055             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15056             *
15057             * <p>
15058             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
15059             * </p>
15060             *
15061             * @param groupId the group ID
15062             * @param nodeId the node ID
15063             * @param title the title
15064             * @param head the head
15065             * @param start the lower bound of the range of wiki pages
15066             * @param end the upper bound of the range of wiki pages (not inclusive)
15067             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15068             * @return the ordered range of matching wiki pages
15069             * @throws SystemException if a system exception occurred
15070             */
15071            @Override
15072            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
15073                    String title, boolean head, int start, int end,
15074                    OrderByComparator orderByComparator) throws SystemException {
15075                    boolean pagination = true;
15076                    FinderPath finderPath = null;
15077                    Object[] finderArgs = null;
15078    
15079                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15080                                    (orderByComparator == null)) {
15081                            pagination = false;
15082                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H;
15083                            finderArgs = new Object[] { groupId, nodeId, title, head };
15084                    }
15085                    else {
15086                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T_H;
15087                            finderArgs = new Object[] {
15088                                            groupId, nodeId, title, head,
15089                                            
15090                                            start, end, orderByComparator
15091                                    };
15092                    }
15093    
15094                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
15095                                    finderArgs, this);
15096    
15097                    if ((list != null) && !list.isEmpty()) {
15098                            for (WikiPage wikiPage : list) {
15099                                    if ((groupId != wikiPage.getGroupId()) ||
15100                                                    (nodeId != wikiPage.getNodeId()) ||
15101                                                    !Validator.equals(title, wikiPage.getTitle()) ||
15102                                                    (head != wikiPage.getHead())) {
15103                                            list = null;
15104    
15105                                            break;
15106                                    }
15107                            }
15108                    }
15109    
15110                    if (list == null) {
15111                            StringBundler query = null;
15112    
15113                            if (orderByComparator != null) {
15114                                    query = new StringBundler(6 +
15115                                                    (orderByComparator.getOrderByFields().length * 3));
15116                            }
15117                            else {
15118                                    query = new StringBundler(6);
15119                            }
15120    
15121                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
15122    
15123                            query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
15124    
15125                            query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
15126    
15127                            boolean bindTitle = false;
15128    
15129                            if (title == null) {
15130                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
15131                            }
15132                            else if (title.equals(StringPool.BLANK)) {
15133                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
15134                            }
15135                            else {
15136                                    bindTitle = true;
15137    
15138                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
15139                            }
15140    
15141                            query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
15142    
15143                            if (orderByComparator != null) {
15144                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15145                                            orderByComparator);
15146                            }
15147                            else
15148                             if (pagination) {
15149                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15150                            }
15151    
15152                            String sql = query.toString();
15153    
15154                            Session session = null;
15155    
15156                            try {
15157                                    session = openSession();
15158    
15159                                    Query q = session.createQuery(sql);
15160    
15161                                    QueryPos qPos = QueryPos.getInstance(q);
15162    
15163                                    qPos.add(groupId);
15164    
15165                                    qPos.add(nodeId);
15166    
15167                                    if (bindTitle) {
15168                                            qPos.add(title.toLowerCase());
15169                                    }
15170    
15171                                    qPos.add(head);
15172    
15173                                    if (!pagination) {
15174                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
15175                                                            start, end, false);
15176    
15177                                            Collections.sort(list);
15178    
15179                                            list = new UnmodifiableList<WikiPage>(list);
15180                                    }
15181                                    else {
15182                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
15183                                                            start, end);
15184                                    }
15185    
15186                                    cacheResult(list);
15187    
15188                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15189                            }
15190                            catch (Exception e) {
15191                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15192    
15193                                    throw processException(e);
15194                            }
15195                            finally {
15196                                    closeSession(session);
15197                            }
15198                    }
15199    
15200                    return list;
15201            }
15202    
15203            /**
15204             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15205             *
15206             * @param groupId the group ID
15207             * @param nodeId the node ID
15208             * @param title the title
15209             * @param head the head
15210             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15211             * @return the first matching wiki page
15212             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
15213             * @throws SystemException if a system exception occurred
15214             */
15215            @Override
15216            public WikiPage findByG_N_T_H_First(long groupId, long nodeId,
15217                    String title, boolean head, OrderByComparator orderByComparator)
15218                    throws NoSuchPageException, SystemException {
15219                    WikiPage wikiPage = fetchByG_N_T_H_First(groupId, nodeId, title, head,
15220                                    orderByComparator);
15221    
15222                    if (wikiPage != null) {
15223                            return wikiPage;
15224                    }
15225    
15226                    StringBundler msg = new StringBundler(10);
15227    
15228                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15229    
15230                    msg.append("groupId=");
15231                    msg.append(groupId);
15232    
15233                    msg.append(", nodeId=");
15234                    msg.append(nodeId);
15235    
15236                    msg.append(", title=");
15237                    msg.append(title);
15238    
15239                    msg.append(", head=");
15240                    msg.append(head);
15241    
15242                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15243    
15244                    throw new NoSuchPageException(msg.toString());
15245            }
15246    
15247            /**
15248             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15249             *
15250             * @param groupId the group ID
15251             * @param nodeId the node ID
15252             * @param title the title
15253             * @param head the head
15254             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15255             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
15256             * @throws SystemException if a system exception occurred
15257             */
15258            @Override
15259            public WikiPage fetchByG_N_T_H_First(long groupId, long nodeId,
15260                    String title, boolean head, OrderByComparator orderByComparator)
15261                    throws SystemException {
15262                    List<WikiPage> list = findByG_N_T_H(groupId, nodeId, title, head, 0, 1,
15263                                    orderByComparator);
15264    
15265                    if (!list.isEmpty()) {
15266                            return list.get(0);
15267                    }
15268    
15269                    return null;
15270            }
15271    
15272            /**
15273             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15274             *
15275             * @param groupId the group ID
15276             * @param nodeId the node ID
15277             * @param title the title
15278             * @param head the head
15279             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15280             * @return the last matching wiki page
15281             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
15282             * @throws SystemException if a system exception occurred
15283             */
15284            @Override
15285            public WikiPage findByG_N_T_H_Last(long groupId, long nodeId, String title,
15286                    boolean head, OrderByComparator orderByComparator)
15287                    throws NoSuchPageException, SystemException {
15288                    WikiPage wikiPage = fetchByG_N_T_H_Last(groupId, nodeId, title, head,
15289                                    orderByComparator);
15290    
15291                    if (wikiPage != null) {
15292                            return wikiPage;
15293                    }
15294    
15295                    StringBundler msg = new StringBundler(10);
15296    
15297                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15298    
15299                    msg.append("groupId=");
15300                    msg.append(groupId);
15301    
15302                    msg.append(", nodeId=");
15303                    msg.append(nodeId);
15304    
15305                    msg.append(", title=");
15306                    msg.append(title);
15307    
15308                    msg.append(", head=");
15309                    msg.append(head);
15310    
15311                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15312    
15313                    throw new NoSuchPageException(msg.toString());
15314            }
15315    
15316            /**
15317             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15318             *
15319             * @param groupId the group ID
15320             * @param nodeId the node ID
15321             * @param title the title
15322             * @param head the head
15323             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15324             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
15325             * @throws SystemException if a system exception occurred
15326             */
15327            @Override
15328            public WikiPage fetchByG_N_T_H_Last(long groupId, long nodeId,
15329                    String title, boolean head, OrderByComparator orderByComparator)
15330                    throws SystemException {
15331                    int count = countByG_N_T_H(groupId, nodeId, title, head);
15332    
15333                    if (count == 0) {
15334                            return null;
15335                    }
15336    
15337                    List<WikiPage> list = findByG_N_T_H(groupId, nodeId, title, head,
15338                                    count - 1, count, orderByComparator);
15339    
15340                    if (!list.isEmpty()) {
15341                            return list.get(0);
15342                    }
15343    
15344                    return null;
15345            }
15346    
15347            /**
15348             * 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;.
15349             *
15350             * @param pageId the primary key of the current wiki page
15351             * @param groupId the group ID
15352             * @param nodeId the node ID
15353             * @param title the title
15354             * @param head the head
15355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15356             * @return the previous, current, and next wiki page
15357             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
15358             * @throws SystemException if a system exception occurred
15359             */
15360            @Override
15361            public WikiPage[] findByG_N_T_H_PrevAndNext(long pageId, long groupId,
15362                    long nodeId, String title, boolean head,
15363                    OrderByComparator orderByComparator)
15364                    throws NoSuchPageException, SystemException {
15365                    WikiPage wikiPage = findByPrimaryKey(pageId);
15366    
15367                    Session session = null;
15368    
15369                    try {
15370                            session = openSession();
15371    
15372                            WikiPage[] array = new WikiPageImpl[3];
15373    
15374                            array[0] = getByG_N_T_H_PrevAndNext(session, wikiPage, groupId,
15375                                            nodeId, title, head, orderByComparator, true);
15376    
15377                            array[1] = wikiPage;
15378    
15379                            array[2] = getByG_N_T_H_PrevAndNext(session, wikiPage, groupId,
15380                                            nodeId, title, head, orderByComparator, false);
15381    
15382                            return array;
15383                    }
15384                    catch (Exception e) {
15385                            throw processException(e);
15386                    }
15387                    finally {
15388                            closeSession(session);
15389                    }
15390            }
15391    
15392            protected WikiPage getByG_N_T_H_PrevAndNext(Session session,
15393                    WikiPage wikiPage, long groupId, long nodeId, String title,
15394                    boolean head, OrderByComparator orderByComparator, boolean previous) {
15395                    StringBundler query = null;
15396    
15397                    if (orderByComparator != null) {
15398                            query = new StringBundler(6 +
15399                                            (orderByComparator.getOrderByFields().length * 6));
15400                    }
15401                    else {
15402                            query = new StringBundler(3);
15403                    }
15404    
15405                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
15406    
15407                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
15408    
15409                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
15410    
15411                    boolean bindTitle = false;
15412    
15413                    if (title == null) {
15414                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
15415                    }
15416                    else if (title.equals(StringPool.BLANK)) {
15417                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
15418                    }
15419                    else {
15420                            bindTitle = true;
15421    
15422                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
15423                    }
15424    
15425                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
15426    
15427                    if (orderByComparator != null) {
15428                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15429    
15430                            if (orderByConditionFields.length > 0) {
15431                                    query.append(WHERE_AND);
15432                            }
15433    
15434                            for (int i = 0; i < orderByConditionFields.length; i++) {
15435                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15436                                    query.append(orderByConditionFields[i]);
15437    
15438                                    if ((i + 1) < orderByConditionFields.length) {
15439                                            if (orderByComparator.isAscending() ^ previous) {
15440                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15441                                            }
15442                                            else {
15443                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15444                                            }
15445                                    }
15446                                    else {
15447                                            if (orderByComparator.isAscending() ^ previous) {
15448                                                    query.append(WHERE_GREATER_THAN);
15449                                            }
15450                                            else {
15451                                                    query.append(WHERE_LESSER_THAN);
15452                                            }
15453                                    }
15454                            }
15455    
15456                            query.append(ORDER_BY_CLAUSE);
15457    
15458                            String[] orderByFields = orderByComparator.getOrderByFields();
15459    
15460                            for (int i = 0; i < orderByFields.length; i++) {
15461                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15462                                    query.append(orderByFields[i]);
15463    
15464                                    if ((i + 1) < orderByFields.length) {
15465                                            if (orderByComparator.isAscending() ^ previous) {
15466                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15467                                            }
15468                                            else {
15469                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15470                                            }
15471                                    }
15472                                    else {
15473                                            if (orderByComparator.isAscending() ^ previous) {
15474                                                    query.append(ORDER_BY_ASC);
15475                                            }
15476                                            else {
15477                                                    query.append(ORDER_BY_DESC);
15478                                            }
15479                                    }
15480                            }
15481                    }
15482                    else {
15483                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15484                    }
15485    
15486                    String sql = query.toString();
15487    
15488                    Query q = session.createQuery(sql);
15489    
15490                    q.setFirstResult(0);
15491                    q.setMaxResults(2);
15492    
15493                    QueryPos qPos = QueryPos.getInstance(q);
15494    
15495                    qPos.add(groupId);
15496    
15497                    qPos.add(nodeId);
15498    
15499                    if (bindTitle) {
15500                            qPos.add(title.toLowerCase());
15501                    }
15502    
15503                    qPos.add(head);
15504    
15505                    if (orderByComparator != null) {
15506                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
15507    
15508                            for (Object value : values) {
15509                                    qPos.add(value);
15510                            }
15511                    }
15512    
15513                    List<WikiPage> list = q.list();
15514    
15515                    if (list.size() == 2) {
15516                            return list.get(1);
15517                    }
15518                    else {
15519                            return null;
15520                    }
15521            }
15522    
15523            /**
15524             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15525             *
15526             * @param groupId the group ID
15527             * @param nodeId the node ID
15528             * @param title the title
15529             * @param head the head
15530             * @return the matching wiki pages that the user has permission to view
15531             * @throws SystemException if a system exception occurred
15532             */
15533            @Override
15534            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
15535                    String title, boolean head) throws SystemException {
15536                    return filterFindByG_N_T_H(groupId, nodeId, title, head,
15537                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15538            }
15539    
15540            /**
15541             * 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;.
15542             *
15543             * <p>
15544             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
15545             * </p>
15546             *
15547             * @param groupId the group ID
15548             * @param nodeId the node ID
15549             * @param title the title
15550             * @param head the head
15551             * @param start the lower bound of the range of wiki pages
15552             * @param end the upper bound of the range of wiki pages (not inclusive)
15553             * @return the range of matching wiki pages that the user has permission to view
15554             * @throws SystemException if a system exception occurred
15555             */
15556            @Override
15557            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
15558                    String title, boolean head, int start, int end)
15559                    throws SystemException {
15560                    return filterFindByG_N_T_H(groupId, nodeId, title, head, start, end,
15561                            null);
15562            }
15563    
15564            /**
15565             * 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;.
15566             *
15567             * <p>
15568             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
15569             * </p>
15570             *
15571             * @param groupId the group ID
15572             * @param nodeId the node ID
15573             * @param title the title
15574             * @param head the head
15575             * @param start the lower bound of the range of wiki pages
15576             * @param end the upper bound of the range of wiki pages (not inclusive)
15577             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15578             * @return the ordered range of matching wiki pages that the user has permission to view
15579             * @throws SystemException if a system exception occurred
15580             */
15581            @Override
15582            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
15583                    String title, boolean head, int start, int end,
15584                    OrderByComparator orderByComparator) throws SystemException {
15585                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15586                            return findByG_N_T_H(groupId, nodeId, title, head, start, end,
15587                                    orderByComparator);
15588                    }
15589    
15590                    StringBundler query = null;
15591    
15592                    if (orderByComparator != null) {
15593                            query = new StringBundler(6 +
15594                                            (orderByComparator.getOrderByFields().length * 3));
15595                    }
15596                    else {
15597                            query = new StringBundler(6);
15598                    }
15599    
15600                    if (getDB().isSupportsInlineDistinct()) {
15601                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
15602                    }
15603                    else {
15604                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
15605                    }
15606    
15607                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
15608    
15609                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
15610    
15611                    boolean bindTitle = false;
15612    
15613                    if (title == null) {
15614                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
15615                    }
15616                    else if (title.equals(StringPool.BLANK)) {
15617                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
15618                    }
15619                    else {
15620                            bindTitle = true;
15621    
15622                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
15623                    }
15624    
15625                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
15626    
15627                    if (!getDB().isSupportsInlineDistinct()) {
15628                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
15629                    }
15630    
15631                    if (orderByComparator != null) {
15632                            if (getDB().isSupportsInlineDistinct()) {
15633                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15634                                            orderByComparator, true);
15635                            }
15636                            else {
15637                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
15638                                            orderByComparator, true);
15639                            }
15640                    }
15641                    else {
15642                            if (getDB().isSupportsInlineDistinct()) {
15643                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15644                            }
15645                            else {
15646                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
15647                            }
15648                    }
15649    
15650                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15651                                    WikiPage.class.getName(),
15652                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15653    
15654                    Session session = null;
15655    
15656                    try {
15657                            session = openSession();
15658    
15659                            SQLQuery q = session.createSQLQuery(sql);
15660    
15661                            if (getDB().isSupportsInlineDistinct()) {
15662                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
15663                            }
15664                            else {
15665                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
15666                            }
15667    
15668                            QueryPos qPos = QueryPos.getInstance(q);
15669    
15670                            qPos.add(groupId);
15671    
15672                            qPos.add(nodeId);
15673    
15674                            if (bindTitle) {
15675                                    qPos.add(title.toLowerCase());
15676                            }
15677    
15678                            qPos.add(head);
15679    
15680                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
15681                    }
15682                    catch (Exception e) {
15683                            throw processException(e);
15684                    }
15685                    finally {
15686                            closeSession(session);
15687                    }
15688            }
15689    
15690            /**
15691             * 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;.
15692             *
15693             * @param pageId the primary key of the current wiki page
15694             * @param groupId the group ID
15695             * @param nodeId the node ID
15696             * @param title the title
15697             * @param head the head
15698             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15699             * @return the previous, current, and next wiki page
15700             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
15701             * @throws SystemException if a system exception occurred
15702             */
15703            @Override
15704            public WikiPage[] filterFindByG_N_T_H_PrevAndNext(long pageId,
15705                    long groupId, long nodeId, String title, boolean head,
15706                    OrderByComparator orderByComparator)
15707                    throws NoSuchPageException, SystemException {
15708                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15709                            return findByG_N_T_H_PrevAndNext(pageId, groupId, nodeId, title,
15710                                    head, orderByComparator);
15711                    }
15712    
15713                    WikiPage wikiPage = findByPrimaryKey(pageId);
15714    
15715                    Session session = null;
15716    
15717                    try {
15718                            session = openSession();
15719    
15720                            WikiPage[] array = new WikiPageImpl[3];
15721    
15722                            array[0] = filterGetByG_N_T_H_PrevAndNext(session, wikiPage,
15723                                            groupId, nodeId, title, head, orderByComparator, true);
15724    
15725                            array[1] = wikiPage;
15726    
15727                            array[2] = filterGetByG_N_T_H_PrevAndNext(session, wikiPage,
15728                                            groupId, nodeId, title, head, orderByComparator, false);
15729    
15730                            return array;
15731                    }
15732                    catch (Exception e) {
15733                            throw processException(e);
15734                    }
15735                    finally {
15736                            closeSession(session);
15737                    }
15738            }
15739    
15740            protected WikiPage filterGetByG_N_T_H_PrevAndNext(Session session,
15741                    WikiPage wikiPage, long groupId, long nodeId, String title,
15742                    boolean head, OrderByComparator orderByComparator, boolean previous) {
15743                    StringBundler query = null;
15744    
15745                    if (orderByComparator != null) {
15746                            query = new StringBundler(6 +
15747                                            (orderByComparator.getOrderByFields().length * 6));
15748                    }
15749                    else {
15750                            query = new StringBundler(3);
15751                    }
15752    
15753                    if (getDB().isSupportsInlineDistinct()) {
15754                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
15755                    }
15756                    else {
15757                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
15758                    }
15759    
15760                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
15761    
15762                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
15763    
15764                    boolean bindTitle = false;
15765    
15766                    if (title == null) {
15767                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
15768                    }
15769                    else if (title.equals(StringPool.BLANK)) {
15770                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
15771                    }
15772                    else {
15773                            bindTitle = true;
15774    
15775                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
15776                    }
15777    
15778                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
15779    
15780                    if (!getDB().isSupportsInlineDistinct()) {
15781                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
15782                    }
15783    
15784                    if (orderByComparator != null) {
15785                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15786    
15787                            if (orderByConditionFields.length > 0) {
15788                                    query.append(WHERE_AND);
15789                            }
15790    
15791                            for (int i = 0; i < orderByConditionFields.length; i++) {
15792                                    if (getDB().isSupportsInlineDistinct()) {
15793                                            query.append(_ORDER_BY_ENTITY_ALIAS);
15794                                    }
15795                                    else {
15796                                            query.append(_ORDER_BY_ENTITY_TABLE);
15797                                    }
15798    
15799                                    query.append(orderByConditionFields[i]);
15800    
15801                                    if ((i + 1) < orderByConditionFields.length) {
15802                                            if (orderByComparator.isAscending() ^ previous) {
15803                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15804                                            }
15805                                            else {
15806                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15807                                            }
15808                                    }
15809                                    else {
15810                                            if (orderByComparator.isAscending() ^ previous) {
15811                                                    query.append(WHERE_GREATER_THAN);
15812                                            }
15813                                            else {
15814                                                    query.append(WHERE_LESSER_THAN);
15815                                            }
15816                                    }
15817                            }
15818    
15819                            query.append(ORDER_BY_CLAUSE);
15820    
15821                            String[] orderByFields = orderByComparator.getOrderByFields();
15822    
15823                            for (int i = 0; i < orderByFields.length; i++) {
15824                                    if (getDB().isSupportsInlineDistinct()) {
15825                                            query.append(_ORDER_BY_ENTITY_ALIAS);
15826                                    }
15827                                    else {
15828                                            query.append(_ORDER_BY_ENTITY_TABLE);
15829                                    }
15830    
15831                                    query.append(orderByFields[i]);
15832    
15833                                    if ((i + 1) < orderByFields.length) {
15834                                            if (orderByComparator.isAscending() ^ previous) {
15835                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15836                                            }
15837                                            else {
15838                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15839                                            }
15840                                    }
15841                                    else {
15842                                            if (orderByComparator.isAscending() ^ previous) {
15843                                                    query.append(ORDER_BY_ASC);
15844                                            }
15845                                            else {
15846                                                    query.append(ORDER_BY_DESC);
15847                                            }
15848                                    }
15849                            }
15850                    }
15851                    else {
15852                            if (getDB().isSupportsInlineDistinct()) {
15853                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15854                            }
15855                            else {
15856                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
15857                            }
15858                    }
15859    
15860                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15861                                    WikiPage.class.getName(),
15862                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15863    
15864                    SQLQuery q = session.createSQLQuery(sql);
15865    
15866                    q.setFirstResult(0);
15867                    q.setMaxResults(2);
15868    
15869                    if (getDB().isSupportsInlineDistinct()) {
15870                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
15871                    }
15872                    else {
15873                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
15874                    }
15875    
15876                    QueryPos qPos = QueryPos.getInstance(q);
15877    
15878                    qPos.add(groupId);
15879    
15880                    qPos.add(nodeId);
15881    
15882                    if (bindTitle) {
15883                            qPos.add(title.toLowerCase());
15884                    }
15885    
15886                    qPos.add(head);
15887    
15888                    if (orderByComparator != null) {
15889                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
15890    
15891                            for (Object value : values) {
15892                                    qPos.add(value);
15893                            }
15894                    }
15895    
15896                    List<WikiPage> list = q.list();
15897    
15898                    if (list.size() == 2) {
15899                            return list.get(1);
15900                    }
15901                    else {
15902                            return null;
15903                    }
15904            }
15905    
15906            /**
15907             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63; from the database.
15908             *
15909             * @param groupId the group ID
15910             * @param nodeId the node ID
15911             * @param title the title
15912             * @param head the head
15913             * @throws SystemException if a system exception occurred
15914             */
15915            @Override
15916            public void removeByG_N_T_H(long groupId, long nodeId, String title,
15917                    boolean head) throws SystemException {
15918                    for (WikiPage wikiPage : findByG_N_T_H(groupId, nodeId, title, head,
15919                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15920                            remove(wikiPage);
15921                    }
15922            }
15923    
15924            /**
15925             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15926             *
15927             * @param groupId the group ID
15928             * @param nodeId the node ID
15929             * @param title the title
15930             * @param head the head
15931             * @return the number of matching wiki pages
15932             * @throws SystemException if a system exception occurred
15933             */
15934            @Override
15935            public int countByG_N_T_H(long groupId, long nodeId, String title,
15936                    boolean head) throws SystemException {
15937                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_T_H;
15938    
15939                    Object[] finderArgs = new Object[] { groupId, nodeId, title, head };
15940    
15941                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15942                                    this);
15943    
15944                    if (count == null) {
15945                            StringBundler query = new StringBundler(5);
15946    
15947                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
15948    
15949                            query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
15950    
15951                            query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
15952    
15953                            boolean bindTitle = false;
15954    
15955                            if (title == null) {
15956                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
15957                            }
15958                            else if (title.equals(StringPool.BLANK)) {
15959                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
15960                            }
15961                            else {
15962                                    bindTitle = true;
15963    
15964                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
15965                            }
15966    
15967                            query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
15968    
15969                            String sql = query.toString();
15970    
15971                            Session session = null;
15972    
15973                            try {
15974                                    session = openSession();
15975    
15976                                    Query q = session.createQuery(sql);
15977    
15978                                    QueryPos qPos = QueryPos.getInstance(q);
15979    
15980                                    qPos.add(groupId);
15981    
15982                                    qPos.add(nodeId);
15983    
15984                                    if (bindTitle) {
15985                                            qPos.add(title.toLowerCase());
15986                                    }
15987    
15988                                    qPos.add(head);
15989    
15990                                    count = (Long)q.uniqueResult();
15991    
15992                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15993                            }
15994                            catch (Exception e) {
15995                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15996    
15997                                    throw processException(e);
15998                            }
15999                            finally {
16000                                    closeSession(session);
16001                            }
16002                    }
16003    
16004                    return count.intValue();
16005            }
16006    
16007            /**
16008             * 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;.
16009             *
16010             * @param groupId the group ID
16011             * @param nodeId the node ID
16012             * @param title the title
16013             * @param head the head
16014             * @return the number of matching wiki pages that the user has permission to view
16015             * @throws SystemException if a system exception occurred
16016             */
16017            @Override
16018            public int filterCountByG_N_T_H(long groupId, long nodeId, String title,
16019                    boolean head) throws SystemException {
16020                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16021                            return countByG_N_T_H(groupId, nodeId, title, head);
16022                    }
16023    
16024                    StringBundler query = new StringBundler(5);
16025    
16026                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
16027    
16028                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
16029    
16030                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
16031    
16032                    boolean bindTitle = false;
16033    
16034                    if (title == null) {
16035                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
16036                    }
16037                    else if (title.equals(StringPool.BLANK)) {
16038                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
16039                    }
16040                    else {
16041                            bindTitle = true;
16042    
16043                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
16044                    }
16045    
16046                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
16047    
16048                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16049                                    WikiPage.class.getName(),
16050                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16051    
16052                    Session session = null;
16053    
16054                    try {
16055                            session = openSession();
16056    
16057                            SQLQuery q = session.createSQLQuery(sql);
16058    
16059                            q.addScalar(COUNT_COLUMN_NAME,
16060                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16061    
16062                            QueryPos qPos = QueryPos.getInstance(q);
16063    
16064                            qPos.add(groupId);
16065    
16066                            qPos.add(nodeId);
16067    
16068                            if (bindTitle) {
16069                                    qPos.add(title.toLowerCase());
16070                            }
16071    
16072                            qPos.add(head);
16073    
16074                            Long count = (Long)q.uniqueResult();
16075    
16076                            return count.intValue();
16077                    }
16078                    catch (Exception e) {
16079                            throw processException(e);
16080                    }
16081                    finally {
16082                            closeSession(session);
16083                    }
16084            }
16085    
16086            private static final String _FINDER_COLUMN_G_N_T_H_GROUPID_2 = "wikiPage.groupId = ? AND ";
16087            private static final String _FINDER_COLUMN_G_N_T_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
16088            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_1 = "wikiPage.title IS NULL AND ";
16089            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_2 = "lower(wikiPage.title) = ? AND ";
16090            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '') AND ";
16091            private static final String _FINDER_COLUMN_G_N_T_H_HEAD_2 = "wikiPage.head = ?";
16092            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16093                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
16094                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H_S",
16095                            new String[] {
16096                                    Long.class.getName(), Long.class.getName(),
16097                                    Boolean.class.getName(), Integer.class.getName(),
16098                                    
16099                            Integer.class.getName(), Integer.class.getName(),
16100                                    OrderByComparator.class.getName()
16101                            });
16102            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S =
16103                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16104                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
16105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H_S",
16106                            new String[] {
16107                                    Long.class.getName(), Long.class.getName(),
16108                                    Boolean.class.getName(), Integer.class.getName()
16109                            },
16110                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
16111                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
16112                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
16113                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
16114                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
16115                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
16116            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16117                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16118                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H_S",
16119                            new String[] {
16120                                    Long.class.getName(), Long.class.getName(),
16121                                    Boolean.class.getName(), Integer.class.getName()
16122                            });
16123    
16124            /**
16125             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16126             *
16127             * @param groupId the group ID
16128             * @param nodeId the node ID
16129             * @param head the head
16130             * @param status the status
16131             * @return the matching wiki pages
16132             * @throws SystemException if a system exception occurred
16133             */
16134            @Override
16135            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
16136                    boolean head, int status) throws SystemException {
16137                    return findByG_N_H_S(groupId, nodeId, head, status, QueryUtil.ALL_POS,
16138                            QueryUtil.ALL_POS, null);
16139            }
16140    
16141            /**
16142             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16143             *
16144             * <p>
16145             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
16146             * </p>
16147             *
16148             * @param groupId the group ID
16149             * @param nodeId the node ID
16150             * @param head the head
16151             * @param status the status
16152             * @param start the lower bound of the range of wiki pages
16153             * @param end the upper bound of the range of wiki pages (not inclusive)
16154             * @return the range of matching wiki pages
16155             * @throws SystemException if a system exception occurred
16156             */
16157            @Override
16158            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
16159                    boolean head, int status, int start, int end) throws SystemException {
16160                    return findByG_N_H_S(groupId, nodeId, head, status, start, end, null);
16161            }
16162    
16163            /**
16164             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16165             *
16166             * <p>
16167             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
16168             * </p>
16169             *
16170             * @param groupId the group ID
16171             * @param nodeId the node ID
16172             * @param head the head
16173             * @param status the status
16174             * @param start the lower bound of the range of wiki pages
16175             * @param end the upper bound of the range of wiki pages (not inclusive)
16176             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16177             * @return the ordered range of matching wiki pages
16178             * @throws SystemException if a system exception occurred
16179             */
16180            @Override
16181            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
16182                    boolean head, int status, int start, int end,
16183                    OrderByComparator orderByComparator) throws SystemException {
16184                    boolean pagination = true;
16185                    FinderPath finderPath = null;
16186                    Object[] finderArgs = null;
16187    
16188                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16189                                    (orderByComparator == null)) {
16190                            pagination = false;
16191                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S;
16192                            finderArgs = new Object[] { groupId, nodeId, head, status };
16193                    }
16194                    else {
16195                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_S;
16196                            finderArgs = new Object[] {
16197                                            groupId, nodeId, head, status,
16198                                            
16199                                            start, end, orderByComparator
16200                                    };
16201                    }
16202    
16203                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
16204                                    finderArgs, this);
16205    
16206                    if ((list != null) && !list.isEmpty()) {
16207                            for (WikiPage wikiPage : list) {
16208                                    if ((groupId != wikiPage.getGroupId()) ||
16209                                                    (nodeId != wikiPage.getNodeId()) ||
16210                                                    (head != wikiPage.getHead()) ||
16211                                                    (status != wikiPage.getStatus())) {
16212                                            list = null;
16213    
16214                                            break;
16215                                    }
16216                            }
16217                    }
16218    
16219                    if (list == null) {
16220                            StringBundler query = null;
16221    
16222                            if (orderByComparator != null) {
16223                                    query = new StringBundler(6 +
16224                                                    (orderByComparator.getOrderByFields().length * 3));
16225                            }
16226                            else {
16227                                    query = new StringBundler(6);
16228                            }
16229    
16230                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
16231    
16232                            query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
16233    
16234                            query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
16235    
16236                            query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
16237    
16238                            query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
16239    
16240                            if (orderByComparator != null) {
16241                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16242                                            orderByComparator);
16243                            }
16244                            else
16245                             if (pagination) {
16246                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16247                            }
16248    
16249                            String sql = query.toString();
16250    
16251                            Session session = null;
16252    
16253                            try {
16254                                    session = openSession();
16255    
16256                                    Query q = session.createQuery(sql);
16257    
16258                                    QueryPos qPos = QueryPos.getInstance(q);
16259    
16260                                    qPos.add(groupId);
16261    
16262                                    qPos.add(nodeId);
16263    
16264                                    qPos.add(head);
16265    
16266                                    qPos.add(status);
16267    
16268                                    if (!pagination) {
16269                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
16270                                                            start, end, false);
16271    
16272                                            Collections.sort(list);
16273    
16274                                            list = new UnmodifiableList<WikiPage>(list);
16275                                    }
16276                                    else {
16277                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
16278                                                            start, end);
16279                                    }
16280    
16281                                    cacheResult(list);
16282    
16283                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
16284                            }
16285                            catch (Exception e) {
16286                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16287    
16288                                    throw processException(e);
16289                            }
16290                            finally {
16291                                    closeSession(session);
16292                            }
16293                    }
16294    
16295                    return list;
16296            }
16297    
16298            /**
16299             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16300             *
16301             * @param groupId the group ID
16302             * @param nodeId the node ID
16303             * @param head the head
16304             * @param status the status
16305             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16306             * @return the first matching wiki page
16307             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
16308             * @throws SystemException if a system exception occurred
16309             */
16310            @Override
16311            public WikiPage findByG_N_H_S_First(long groupId, long nodeId,
16312                    boolean head, int status, OrderByComparator orderByComparator)
16313                    throws NoSuchPageException, SystemException {
16314                    WikiPage wikiPage = fetchByG_N_H_S_First(groupId, nodeId, head, status,
16315                                    orderByComparator);
16316    
16317                    if (wikiPage != null) {
16318                            return wikiPage;
16319                    }
16320    
16321                    StringBundler msg = new StringBundler(10);
16322    
16323                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16324    
16325                    msg.append("groupId=");
16326                    msg.append(groupId);
16327    
16328                    msg.append(", nodeId=");
16329                    msg.append(nodeId);
16330    
16331                    msg.append(", head=");
16332                    msg.append(head);
16333    
16334                    msg.append(", status=");
16335                    msg.append(status);
16336    
16337                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16338    
16339                    throw new NoSuchPageException(msg.toString());
16340            }
16341    
16342            /**
16343             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16344             *
16345             * @param groupId the group ID
16346             * @param nodeId the node ID
16347             * @param head the head
16348             * @param status the status
16349             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16350             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
16351             * @throws SystemException if a system exception occurred
16352             */
16353            @Override
16354            public WikiPage fetchByG_N_H_S_First(long groupId, long nodeId,
16355                    boolean head, int status, OrderByComparator orderByComparator)
16356                    throws SystemException {
16357                    List<WikiPage> list = findByG_N_H_S(groupId, nodeId, head, status, 0,
16358                                    1, orderByComparator);
16359    
16360                    if (!list.isEmpty()) {
16361                            return list.get(0);
16362                    }
16363    
16364                    return null;
16365            }
16366    
16367            /**
16368             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16369             *
16370             * @param groupId the group ID
16371             * @param nodeId the node ID
16372             * @param head the head
16373             * @param status the status
16374             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16375             * @return the last matching wiki page
16376             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
16377             * @throws SystemException if a system exception occurred
16378             */
16379            @Override
16380            public WikiPage findByG_N_H_S_Last(long groupId, long nodeId, boolean head,
16381                    int status, OrderByComparator orderByComparator)
16382                    throws NoSuchPageException, SystemException {
16383                    WikiPage wikiPage = fetchByG_N_H_S_Last(groupId, nodeId, head, status,
16384                                    orderByComparator);
16385    
16386                    if (wikiPage != null) {
16387                            return wikiPage;
16388                    }
16389    
16390                    StringBundler msg = new StringBundler(10);
16391    
16392                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16393    
16394                    msg.append("groupId=");
16395                    msg.append(groupId);
16396    
16397                    msg.append(", nodeId=");
16398                    msg.append(nodeId);
16399    
16400                    msg.append(", head=");
16401                    msg.append(head);
16402    
16403                    msg.append(", status=");
16404                    msg.append(status);
16405    
16406                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16407    
16408                    throw new NoSuchPageException(msg.toString());
16409            }
16410    
16411            /**
16412             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16413             *
16414             * @param groupId the group ID
16415             * @param nodeId the node ID
16416             * @param head the head
16417             * @param status the status
16418             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16419             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
16420             * @throws SystemException if a system exception occurred
16421             */
16422            @Override
16423            public WikiPage fetchByG_N_H_S_Last(long groupId, long nodeId,
16424                    boolean head, int status, OrderByComparator orderByComparator)
16425                    throws SystemException {
16426                    int count = countByG_N_H_S(groupId, nodeId, head, status);
16427    
16428                    if (count == 0) {
16429                            return null;
16430                    }
16431    
16432                    List<WikiPage> list = findByG_N_H_S(groupId, nodeId, head, status,
16433                                    count - 1, count, orderByComparator);
16434    
16435                    if (!list.isEmpty()) {
16436                            return list.get(0);
16437                    }
16438    
16439                    return null;
16440            }
16441    
16442            /**
16443             * 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;.
16444             *
16445             * @param pageId the primary key of the current wiki page
16446             * @param groupId the group ID
16447             * @param nodeId the node ID
16448             * @param head the head
16449             * @param status the status
16450             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16451             * @return the previous, current, and next wiki page
16452             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
16453             * @throws SystemException if a system exception occurred
16454             */
16455            @Override
16456            public WikiPage[] findByG_N_H_S_PrevAndNext(long pageId, long groupId,
16457                    long nodeId, boolean head, int status,
16458                    OrderByComparator orderByComparator)
16459                    throws NoSuchPageException, SystemException {
16460                    WikiPage wikiPage = findByPrimaryKey(pageId);
16461    
16462                    Session session = null;
16463    
16464                    try {
16465                            session = openSession();
16466    
16467                            WikiPage[] array = new WikiPageImpl[3];
16468    
16469                            array[0] = getByG_N_H_S_PrevAndNext(session, wikiPage, groupId,
16470                                            nodeId, head, status, orderByComparator, true);
16471    
16472                            array[1] = wikiPage;
16473    
16474                            array[2] = getByG_N_H_S_PrevAndNext(session, wikiPage, groupId,
16475                                            nodeId, head, status, orderByComparator, false);
16476    
16477                            return array;
16478                    }
16479                    catch (Exception e) {
16480                            throw processException(e);
16481                    }
16482                    finally {
16483                            closeSession(session);
16484                    }
16485            }
16486    
16487            protected WikiPage getByG_N_H_S_PrevAndNext(Session session,
16488                    WikiPage wikiPage, long groupId, long nodeId, boolean head, int status,
16489                    OrderByComparator orderByComparator, boolean previous) {
16490                    StringBundler query = null;
16491    
16492                    if (orderByComparator != null) {
16493                            query = new StringBundler(6 +
16494                                            (orderByComparator.getOrderByFields().length * 6));
16495                    }
16496                    else {
16497                            query = new StringBundler(3);
16498                    }
16499    
16500                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
16501    
16502                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
16503    
16504                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
16505    
16506                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
16507    
16508                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
16509    
16510                    if (orderByComparator != null) {
16511                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16512    
16513                            if (orderByConditionFields.length > 0) {
16514                                    query.append(WHERE_AND);
16515                            }
16516    
16517                            for (int i = 0; i < orderByConditionFields.length; i++) {
16518                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16519                                    query.append(orderByConditionFields[i]);
16520    
16521                                    if ((i + 1) < orderByConditionFields.length) {
16522                                            if (orderByComparator.isAscending() ^ previous) {
16523                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16524                                            }
16525                                            else {
16526                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16527                                            }
16528                                    }
16529                                    else {
16530                                            if (orderByComparator.isAscending() ^ previous) {
16531                                                    query.append(WHERE_GREATER_THAN);
16532                                            }
16533                                            else {
16534                                                    query.append(WHERE_LESSER_THAN);
16535                                            }
16536                                    }
16537                            }
16538    
16539                            query.append(ORDER_BY_CLAUSE);
16540    
16541                            String[] orderByFields = orderByComparator.getOrderByFields();
16542    
16543                            for (int i = 0; i < orderByFields.length; i++) {
16544                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16545                                    query.append(orderByFields[i]);
16546    
16547                                    if ((i + 1) < orderByFields.length) {
16548                                            if (orderByComparator.isAscending() ^ previous) {
16549                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16550                                            }
16551                                            else {
16552                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16553                                            }
16554                                    }
16555                                    else {
16556                                            if (orderByComparator.isAscending() ^ previous) {
16557                                                    query.append(ORDER_BY_ASC);
16558                                            }
16559                                            else {
16560                                                    query.append(ORDER_BY_DESC);
16561                                            }
16562                                    }
16563                            }
16564                    }
16565                    else {
16566                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16567                    }
16568    
16569                    String sql = query.toString();
16570    
16571                    Query q = session.createQuery(sql);
16572    
16573                    q.setFirstResult(0);
16574                    q.setMaxResults(2);
16575    
16576                    QueryPos qPos = QueryPos.getInstance(q);
16577    
16578                    qPos.add(groupId);
16579    
16580                    qPos.add(nodeId);
16581    
16582                    qPos.add(head);
16583    
16584                    qPos.add(status);
16585    
16586                    if (orderByComparator != null) {
16587                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
16588    
16589                            for (Object value : values) {
16590                                    qPos.add(value);
16591                            }
16592                    }
16593    
16594                    List<WikiPage> list = q.list();
16595    
16596                    if (list.size() == 2) {
16597                            return list.get(1);
16598                    }
16599                    else {
16600                            return null;
16601                    }
16602            }
16603    
16604            /**
16605             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16606             *
16607             * @param groupId the group ID
16608             * @param nodeId the node ID
16609             * @param head the head
16610             * @param status the status
16611             * @return the matching wiki pages that the user has permission to view
16612             * @throws SystemException if a system exception occurred
16613             */
16614            @Override
16615            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
16616                    boolean head, int status) throws SystemException {
16617                    return filterFindByG_N_H_S(groupId, nodeId, head, status,
16618                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16619            }
16620    
16621            /**
16622             * 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;.
16623             *
16624             * <p>
16625             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
16626             * </p>
16627             *
16628             * @param groupId the group ID
16629             * @param nodeId the node ID
16630             * @param head the head
16631             * @param status the status
16632             * @param start the lower bound of the range of wiki pages
16633             * @param end the upper bound of the range of wiki pages (not inclusive)
16634             * @return the range of matching wiki pages that the user has permission to view
16635             * @throws SystemException if a system exception occurred
16636             */
16637            @Override
16638            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
16639                    boolean head, int status, int start, int end) throws SystemException {
16640                    return filterFindByG_N_H_S(groupId, nodeId, head, status, start, end,
16641                            null);
16642            }
16643    
16644            /**
16645             * 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;.
16646             *
16647             * <p>
16648             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
16649             * </p>
16650             *
16651             * @param groupId the group ID
16652             * @param nodeId the node ID
16653             * @param head the head
16654             * @param status the status
16655             * @param start the lower bound of the range of wiki pages
16656             * @param end the upper bound of the range of wiki pages (not inclusive)
16657             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16658             * @return the ordered range of matching wiki pages that the user has permission to view
16659             * @throws SystemException if a system exception occurred
16660             */
16661            @Override
16662            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
16663                    boolean head, int status, int start, int end,
16664                    OrderByComparator orderByComparator) throws SystemException {
16665                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16666                            return findByG_N_H_S(groupId, nodeId, head, status, start, end,
16667                                    orderByComparator);
16668                    }
16669    
16670                    StringBundler query = null;
16671    
16672                    if (orderByComparator != null) {
16673                            query = new StringBundler(6 +
16674                                            (orderByComparator.getOrderByFields().length * 3));
16675                    }
16676                    else {
16677                            query = new StringBundler(6);
16678                    }
16679    
16680                    if (getDB().isSupportsInlineDistinct()) {
16681                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
16682                    }
16683                    else {
16684                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
16685                    }
16686    
16687                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
16688    
16689                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
16690    
16691                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
16692    
16693                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
16694    
16695                    if (!getDB().isSupportsInlineDistinct()) {
16696                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
16697                    }
16698    
16699                    if (orderByComparator != null) {
16700                            if (getDB().isSupportsInlineDistinct()) {
16701                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16702                                            orderByComparator, true);
16703                            }
16704                            else {
16705                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16706                                            orderByComparator, true);
16707                            }
16708                    }
16709                    else {
16710                            if (getDB().isSupportsInlineDistinct()) {
16711                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16712                            }
16713                            else {
16714                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
16715                            }
16716                    }
16717    
16718                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16719                                    WikiPage.class.getName(),
16720                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16721    
16722                    Session session = null;
16723    
16724                    try {
16725                            session = openSession();
16726    
16727                            SQLQuery q = session.createSQLQuery(sql);
16728    
16729                            if (getDB().isSupportsInlineDistinct()) {
16730                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
16731                            }
16732                            else {
16733                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
16734                            }
16735    
16736                            QueryPos qPos = QueryPos.getInstance(q);
16737    
16738                            qPos.add(groupId);
16739    
16740                            qPos.add(nodeId);
16741    
16742                            qPos.add(head);
16743    
16744                            qPos.add(status);
16745    
16746                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
16747                    }
16748                    catch (Exception e) {
16749                            throw processException(e);
16750                    }
16751                    finally {
16752                            closeSession(session);
16753                    }
16754            }
16755    
16756            /**
16757             * 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;.
16758             *
16759             * @param pageId the primary key of the current wiki page
16760             * @param groupId the group ID
16761             * @param nodeId the node ID
16762             * @param head the head
16763             * @param status the status
16764             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16765             * @return the previous, current, and next wiki page
16766             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
16767             * @throws SystemException if a system exception occurred
16768             */
16769            @Override
16770            public WikiPage[] filterFindByG_N_H_S_PrevAndNext(long pageId,
16771                    long groupId, long nodeId, boolean head, int status,
16772                    OrderByComparator orderByComparator)
16773                    throws NoSuchPageException, SystemException {
16774                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16775                            return findByG_N_H_S_PrevAndNext(pageId, groupId, nodeId, head,
16776                                    status, orderByComparator);
16777                    }
16778    
16779                    WikiPage wikiPage = findByPrimaryKey(pageId);
16780    
16781                    Session session = null;
16782    
16783                    try {
16784                            session = openSession();
16785    
16786                            WikiPage[] array = new WikiPageImpl[3];
16787    
16788                            array[0] = filterGetByG_N_H_S_PrevAndNext(session, wikiPage,
16789                                            groupId, nodeId, head, status, orderByComparator, true);
16790    
16791                            array[1] = wikiPage;
16792    
16793                            array[2] = filterGetByG_N_H_S_PrevAndNext(session, wikiPage,
16794                                            groupId, nodeId, head, status, orderByComparator, false);
16795    
16796                            return array;
16797                    }
16798                    catch (Exception e) {
16799                            throw processException(e);
16800                    }
16801                    finally {
16802                            closeSession(session);
16803                    }
16804            }
16805    
16806            protected WikiPage filterGetByG_N_H_S_PrevAndNext(Session session,
16807                    WikiPage wikiPage, long groupId, long nodeId, boolean head, int status,
16808                    OrderByComparator orderByComparator, boolean previous) {
16809                    StringBundler query = null;
16810    
16811                    if (orderByComparator != null) {
16812                            query = new StringBundler(6 +
16813                                            (orderByComparator.getOrderByFields().length * 6));
16814                    }
16815                    else {
16816                            query = new StringBundler(3);
16817                    }
16818    
16819                    if (getDB().isSupportsInlineDistinct()) {
16820                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
16821                    }
16822                    else {
16823                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
16824                    }
16825    
16826                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
16827    
16828                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
16829    
16830                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
16831    
16832                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
16833    
16834                    if (!getDB().isSupportsInlineDistinct()) {
16835                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
16836                    }
16837    
16838                    if (orderByComparator != null) {
16839                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16840    
16841                            if (orderByConditionFields.length > 0) {
16842                                    query.append(WHERE_AND);
16843                            }
16844    
16845                            for (int i = 0; i < orderByConditionFields.length; i++) {
16846                                    if (getDB().isSupportsInlineDistinct()) {
16847                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16848                                    }
16849                                    else {
16850                                            query.append(_ORDER_BY_ENTITY_TABLE);
16851                                    }
16852    
16853                                    query.append(orderByConditionFields[i]);
16854    
16855                                    if ((i + 1) < orderByConditionFields.length) {
16856                                            if (orderByComparator.isAscending() ^ previous) {
16857                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16858                                            }
16859                                            else {
16860                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16861                                            }
16862                                    }
16863                                    else {
16864                                            if (orderByComparator.isAscending() ^ previous) {
16865                                                    query.append(WHERE_GREATER_THAN);
16866                                            }
16867                                            else {
16868                                                    query.append(WHERE_LESSER_THAN);
16869                                            }
16870                                    }
16871                            }
16872    
16873                            query.append(ORDER_BY_CLAUSE);
16874    
16875                            String[] orderByFields = orderByComparator.getOrderByFields();
16876    
16877                            for (int i = 0; i < orderByFields.length; i++) {
16878                                    if (getDB().isSupportsInlineDistinct()) {
16879                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16880                                    }
16881                                    else {
16882                                            query.append(_ORDER_BY_ENTITY_TABLE);
16883                                    }
16884    
16885                                    query.append(orderByFields[i]);
16886    
16887                                    if ((i + 1) < orderByFields.length) {
16888                                            if (orderByComparator.isAscending() ^ previous) {
16889                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16890                                            }
16891                                            else {
16892                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16893                                            }
16894                                    }
16895                                    else {
16896                                            if (orderByComparator.isAscending() ^ previous) {
16897                                                    query.append(ORDER_BY_ASC);
16898                                            }
16899                                            else {
16900                                                    query.append(ORDER_BY_DESC);
16901                                            }
16902                                    }
16903                            }
16904                    }
16905                    else {
16906                            if (getDB().isSupportsInlineDistinct()) {
16907                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16908                            }
16909                            else {
16910                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
16911                            }
16912                    }
16913    
16914                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16915                                    WikiPage.class.getName(),
16916                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16917    
16918                    SQLQuery q = session.createSQLQuery(sql);
16919    
16920                    q.setFirstResult(0);
16921                    q.setMaxResults(2);
16922    
16923                    if (getDB().isSupportsInlineDistinct()) {
16924                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
16925                    }
16926                    else {
16927                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
16928                    }
16929    
16930                    QueryPos qPos = QueryPos.getInstance(q);
16931    
16932                    qPos.add(groupId);
16933    
16934                    qPos.add(nodeId);
16935    
16936                    qPos.add(head);
16937    
16938                    qPos.add(status);
16939    
16940                    if (orderByComparator != null) {
16941                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
16942    
16943                            for (Object value : values) {
16944                                    qPos.add(value);
16945                            }
16946                    }
16947    
16948                    List<WikiPage> list = q.list();
16949    
16950                    if (list.size() == 2) {
16951                            return list.get(1);
16952                    }
16953                    else {
16954                            return null;
16955                    }
16956            }
16957    
16958            /**
16959             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63; from the database.
16960             *
16961             * @param groupId the group ID
16962             * @param nodeId the node ID
16963             * @param head the head
16964             * @param status the status
16965             * @throws SystemException if a system exception occurred
16966             */
16967            @Override
16968            public void removeByG_N_H_S(long groupId, long nodeId, boolean head,
16969                    int status) throws SystemException {
16970                    for (WikiPage wikiPage : findByG_N_H_S(groupId, nodeId, head, status,
16971                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16972                            remove(wikiPage);
16973                    }
16974            }
16975    
16976            /**
16977             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16978             *
16979             * @param groupId the group ID
16980             * @param nodeId the node ID
16981             * @param head the head
16982             * @param status the status
16983             * @return the number of matching wiki pages
16984             * @throws SystemException if a system exception occurred
16985             */
16986            @Override
16987            public int countByG_N_H_S(long groupId, long nodeId, boolean head,
16988                    int status) throws SystemException {
16989                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H_S;
16990    
16991                    Object[] finderArgs = new Object[] { groupId, nodeId, head, status };
16992    
16993                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
16994                                    this);
16995    
16996                    if (count == null) {
16997                            StringBundler query = new StringBundler(5);
16998    
16999                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
17000    
17001                            query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
17002    
17003                            query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
17004    
17005                            query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
17006    
17007                            query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
17008    
17009                            String sql = query.toString();
17010    
17011                            Session session = null;
17012    
17013                            try {
17014                                    session = openSession();
17015    
17016                                    Query q = session.createQuery(sql);
17017    
17018                                    QueryPos qPos = QueryPos.getInstance(q);
17019    
17020                                    qPos.add(groupId);
17021    
17022                                    qPos.add(nodeId);
17023    
17024                                    qPos.add(head);
17025    
17026                                    qPos.add(status);
17027    
17028                                    count = (Long)q.uniqueResult();
17029    
17030                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
17031                            }
17032                            catch (Exception e) {
17033                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17034    
17035                                    throw processException(e);
17036                            }
17037                            finally {
17038                                    closeSession(session);
17039                            }
17040                    }
17041    
17042                    return count.intValue();
17043            }
17044    
17045            /**
17046             * 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;.
17047             *
17048             * @param groupId the group ID
17049             * @param nodeId the node ID
17050             * @param head the head
17051             * @param status the status
17052             * @return the number of matching wiki pages that the user has permission to view
17053             * @throws SystemException if a system exception occurred
17054             */
17055            @Override
17056            public int filterCountByG_N_H_S(long groupId, long nodeId, boolean head,
17057                    int status) throws SystemException {
17058                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17059                            return countByG_N_H_S(groupId, nodeId, head, status);
17060                    }
17061    
17062                    StringBundler query = new StringBundler(5);
17063    
17064                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
17065    
17066                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
17067    
17068                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
17069    
17070                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
17071    
17072                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
17073    
17074                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17075                                    WikiPage.class.getName(),
17076                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17077    
17078                    Session session = null;
17079    
17080                    try {
17081                            session = openSession();
17082    
17083                            SQLQuery q = session.createSQLQuery(sql);
17084    
17085                            q.addScalar(COUNT_COLUMN_NAME,
17086                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17087    
17088                            QueryPos qPos = QueryPos.getInstance(q);
17089    
17090                            qPos.add(groupId);
17091    
17092                            qPos.add(nodeId);
17093    
17094                            qPos.add(head);
17095    
17096                            qPos.add(status);
17097    
17098                            Long count = (Long)q.uniqueResult();
17099    
17100                            return count.intValue();
17101                    }
17102                    catch (Exception e) {
17103                            throw processException(e);
17104                    }
17105                    finally {
17106                            closeSession(session);
17107                    }
17108            }
17109    
17110            private static final String _FINDER_COLUMN_G_N_H_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
17111            private static final String _FINDER_COLUMN_G_N_H_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
17112            private static final String _FINDER_COLUMN_G_N_H_S_HEAD_2 = "wikiPage.head = ? AND ";
17113            private static final String _FINDER_COLUMN_G_N_H_S_STATUS_2 = "wikiPage.status = ?";
17114            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17115                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
17116                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_P_S",
17117                            new String[] {
17118                                    Long.class.getName(), Boolean.class.getName(),
17119                                    String.class.getName(), Integer.class.getName(),
17120                                    
17121                            Integer.class.getName(), Integer.class.getName(),
17122                                    OrderByComparator.class.getName()
17123                            });
17124            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S =
17125                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17126                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
17127                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_P_S",
17128                            new String[] {
17129                                    Long.class.getName(), Boolean.class.getName(),
17130                                    String.class.getName(), Integer.class.getName()
17131                            },
17132                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
17133                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
17134                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
17135                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
17136                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
17137                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
17138            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17139                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17140                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_P_S",
17141                            new String[] {
17142                                    Long.class.getName(), Boolean.class.getName(),
17143                                    String.class.getName(), Integer.class.getName()
17144                            });
17145    
17146            /**
17147             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17148             *
17149             * @param nodeId the node ID
17150             * @param head the head
17151             * @param parentTitle the parent title
17152             * @param status the status
17153             * @return the matching wiki pages
17154             * @throws SystemException if a system exception occurred
17155             */
17156            @Override
17157            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
17158                    String parentTitle, int status) throws SystemException {
17159                    return findByN_H_P_S(nodeId, head, parentTitle, status,
17160                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17161            }
17162    
17163            /**
17164             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17165             *
17166             * <p>
17167             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
17168             * </p>
17169             *
17170             * @param nodeId the node ID
17171             * @param head the head
17172             * @param parentTitle the parent title
17173             * @param status the status
17174             * @param start the lower bound of the range of wiki pages
17175             * @param end the upper bound of the range of wiki pages (not inclusive)
17176             * @return the range of matching wiki pages
17177             * @throws SystemException if a system exception occurred
17178             */
17179            @Override
17180            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
17181                    String parentTitle, int status, int start, int end)
17182                    throws SystemException {
17183                    return findByN_H_P_S(nodeId, head, parentTitle, status, start, end, null);
17184            }
17185    
17186            /**
17187             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17188             *
17189             * <p>
17190             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
17191             * </p>
17192             *
17193             * @param nodeId the node ID
17194             * @param head the head
17195             * @param parentTitle the parent title
17196             * @param status the status
17197             * @param start the lower bound of the range of wiki pages
17198             * @param end the upper bound of the range of wiki pages (not inclusive)
17199             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17200             * @return the ordered range of matching wiki pages
17201             * @throws SystemException if a system exception occurred
17202             */
17203            @Override
17204            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
17205                    String parentTitle, int status, int start, int end,
17206                    OrderByComparator orderByComparator) throws SystemException {
17207                    boolean pagination = true;
17208                    FinderPath finderPath = null;
17209                    Object[] finderArgs = null;
17210    
17211                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17212                                    (orderByComparator == null)) {
17213                            pagination = false;
17214                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S;
17215                            finderArgs = new Object[] { nodeId, head, parentTitle, status };
17216                    }
17217                    else {
17218                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_S;
17219                            finderArgs = new Object[] {
17220                                            nodeId, head, parentTitle, status,
17221                                            
17222                                            start, end, orderByComparator
17223                                    };
17224                    }
17225    
17226                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
17227                                    finderArgs, this);
17228    
17229                    if ((list != null) && !list.isEmpty()) {
17230                            for (WikiPage wikiPage : list) {
17231                                    if ((nodeId != wikiPage.getNodeId()) ||
17232                                                    (head != wikiPage.getHead()) ||
17233                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle()) ||
17234                                                    (status != wikiPage.getStatus())) {
17235                                            list = null;
17236    
17237                                            break;
17238                                    }
17239                            }
17240                    }
17241    
17242                    if (list == null) {
17243                            StringBundler query = null;
17244    
17245                            if (orderByComparator != null) {
17246                                    query = new StringBundler(6 +
17247                                                    (orderByComparator.getOrderByFields().length * 3));
17248                            }
17249                            else {
17250                                    query = new StringBundler(6);
17251                            }
17252    
17253                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
17254    
17255                            query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
17256    
17257                            query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
17258    
17259                            boolean bindParentTitle = false;
17260    
17261                            if (parentTitle == null) {
17262                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
17263                            }
17264                            else if (parentTitle.equals(StringPool.BLANK)) {
17265                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
17266                            }
17267                            else {
17268                                    bindParentTitle = true;
17269    
17270                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
17271                            }
17272    
17273                            query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
17274    
17275                            if (orderByComparator != null) {
17276                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17277                                            orderByComparator);
17278                            }
17279                            else
17280                             if (pagination) {
17281                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
17282                            }
17283    
17284                            String sql = query.toString();
17285    
17286                            Session session = null;
17287    
17288                            try {
17289                                    session = openSession();
17290    
17291                                    Query q = session.createQuery(sql);
17292    
17293                                    QueryPos qPos = QueryPos.getInstance(q);
17294    
17295                                    qPos.add(nodeId);
17296    
17297                                    qPos.add(head);
17298    
17299                                    if (bindParentTitle) {
17300                                            qPos.add(parentTitle.toLowerCase());
17301                                    }
17302    
17303                                    qPos.add(status);
17304    
17305                                    if (!pagination) {
17306                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
17307                                                            start, end, false);
17308    
17309                                            Collections.sort(list);
17310    
17311                                            list = new UnmodifiableList<WikiPage>(list);
17312                                    }
17313                                    else {
17314                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
17315                                                            start, end);
17316                                    }
17317    
17318                                    cacheResult(list);
17319    
17320                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
17321                            }
17322                            catch (Exception e) {
17323                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17324    
17325                                    throw processException(e);
17326                            }
17327                            finally {
17328                                    closeSession(session);
17329                            }
17330                    }
17331    
17332                    return list;
17333            }
17334    
17335            /**
17336             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17337             *
17338             * @param nodeId the node ID
17339             * @param head the head
17340             * @param parentTitle the parent title
17341             * @param status the status
17342             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17343             * @return the first matching wiki page
17344             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
17345             * @throws SystemException if a system exception occurred
17346             */
17347            @Override
17348            public WikiPage findByN_H_P_S_First(long nodeId, boolean head,
17349                    String parentTitle, int status, OrderByComparator orderByComparator)
17350                    throws NoSuchPageException, SystemException {
17351                    WikiPage wikiPage = fetchByN_H_P_S_First(nodeId, head, parentTitle,
17352                                    status, orderByComparator);
17353    
17354                    if (wikiPage != null) {
17355                            return wikiPage;
17356                    }
17357    
17358                    StringBundler msg = new StringBundler(10);
17359    
17360                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17361    
17362                    msg.append("nodeId=");
17363                    msg.append(nodeId);
17364    
17365                    msg.append(", head=");
17366                    msg.append(head);
17367    
17368                    msg.append(", parentTitle=");
17369                    msg.append(parentTitle);
17370    
17371                    msg.append(", status=");
17372                    msg.append(status);
17373    
17374                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17375    
17376                    throw new NoSuchPageException(msg.toString());
17377            }
17378    
17379            /**
17380             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17381             *
17382             * @param nodeId the node ID
17383             * @param head the head
17384             * @param parentTitle the parent title
17385             * @param status the status
17386             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17387             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
17388             * @throws SystemException if a system exception occurred
17389             */
17390            @Override
17391            public WikiPage fetchByN_H_P_S_First(long nodeId, boolean head,
17392                    String parentTitle, int status, OrderByComparator orderByComparator)
17393                    throws SystemException {
17394                    List<WikiPage> list = findByN_H_P_S(nodeId, head, parentTitle, status,
17395                                    0, 1, orderByComparator);
17396    
17397                    if (!list.isEmpty()) {
17398                            return list.get(0);
17399                    }
17400    
17401                    return null;
17402            }
17403    
17404            /**
17405             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17406             *
17407             * @param nodeId the node ID
17408             * @param head the head
17409             * @param parentTitle the parent title
17410             * @param status the status
17411             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17412             * @return the last matching wiki page
17413             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
17414             * @throws SystemException if a system exception occurred
17415             */
17416            @Override
17417            public WikiPage findByN_H_P_S_Last(long nodeId, boolean head,
17418                    String parentTitle, int status, OrderByComparator orderByComparator)
17419                    throws NoSuchPageException, SystemException {
17420                    WikiPage wikiPage = fetchByN_H_P_S_Last(nodeId, head, parentTitle,
17421                                    status, orderByComparator);
17422    
17423                    if (wikiPage != null) {
17424                            return wikiPage;
17425                    }
17426    
17427                    StringBundler msg = new StringBundler(10);
17428    
17429                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17430    
17431                    msg.append("nodeId=");
17432                    msg.append(nodeId);
17433    
17434                    msg.append(", head=");
17435                    msg.append(head);
17436    
17437                    msg.append(", parentTitle=");
17438                    msg.append(parentTitle);
17439    
17440                    msg.append(", status=");
17441                    msg.append(status);
17442    
17443                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17444    
17445                    throw new NoSuchPageException(msg.toString());
17446            }
17447    
17448            /**
17449             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17450             *
17451             * @param nodeId the node ID
17452             * @param head the head
17453             * @param parentTitle the parent title
17454             * @param status the status
17455             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17456             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
17457             * @throws SystemException if a system exception occurred
17458             */
17459            @Override
17460            public WikiPage fetchByN_H_P_S_Last(long nodeId, boolean head,
17461                    String parentTitle, int status, OrderByComparator orderByComparator)
17462                    throws SystemException {
17463                    int count = countByN_H_P_S(nodeId, head, parentTitle, status);
17464    
17465                    if (count == 0) {
17466                            return null;
17467                    }
17468    
17469                    List<WikiPage> list = findByN_H_P_S(nodeId, head, parentTitle, status,
17470                                    count - 1, count, orderByComparator);
17471    
17472                    if (!list.isEmpty()) {
17473                            return list.get(0);
17474                    }
17475    
17476                    return null;
17477            }
17478    
17479            /**
17480             * 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;.
17481             *
17482             * @param pageId the primary key of the current wiki page
17483             * @param nodeId the node ID
17484             * @param head the head
17485             * @param parentTitle the parent title
17486             * @param status the status
17487             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17488             * @return the previous, current, and next wiki page
17489             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
17490             * @throws SystemException if a system exception occurred
17491             */
17492            @Override
17493            public WikiPage[] findByN_H_P_S_PrevAndNext(long pageId, long nodeId,
17494                    boolean head, String parentTitle, int status,
17495                    OrderByComparator orderByComparator)
17496                    throws NoSuchPageException, SystemException {
17497                    WikiPage wikiPage = findByPrimaryKey(pageId);
17498    
17499                    Session session = null;
17500    
17501                    try {
17502                            session = openSession();
17503    
17504                            WikiPage[] array = new WikiPageImpl[3];
17505    
17506                            array[0] = getByN_H_P_S_PrevAndNext(session, wikiPage, nodeId,
17507                                            head, parentTitle, status, orderByComparator, true);
17508    
17509                            array[1] = wikiPage;
17510    
17511                            array[2] = getByN_H_P_S_PrevAndNext(session, wikiPage, nodeId,
17512                                            head, parentTitle, status, orderByComparator, false);
17513    
17514                            return array;
17515                    }
17516                    catch (Exception e) {
17517                            throw processException(e);
17518                    }
17519                    finally {
17520                            closeSession(session);
17521                    }
17522            }
17523    
17524            protected WikiPage getByN_H_P_S_PrevAndNext(Session session,
17525                    WikiPage wikiPage, long nodeId, boolean head, String parentTitle,
17526                    int status, OrderByComparator orderByComparator, boolean previous) {
17527                    StringBundler query = null;
17528    
17529                    if (orderByComparator != null) {
17530                            query = new StringBundler(6 +
17531                                            (orderByComparator.getOrderByFields().length * 6));
17532                    }
17533                    else {
17534                            query = new StringBundler(3);
17535                    }
17536    
17537                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
17538    
17539                    query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
17540    
17541                    query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
17542    
17543                    boolean bindParentTitle = false;
17544    
17545                    if (parentTitle == null) {
17546                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
17547                    }
17548                    else if (parentTitle.equals(StringPool.BLANK)) {
17549                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
17550                    }
17551                    else {
17552                            bindParentTitle = true;
17553    
17554                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
17555                    }
17556    
17557                    query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
17558    
17559                    if (orderByComparator != null) {
17560                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17561    
17562                            if (orderByConditionFields.length > 0) {
17563                                    query.append(WHERE_AND);
17564                            }
17565    
17566                            for (int i = 0; i < orderByConditionFields.length; i++) {
17567                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17568                                    query.append(orderByConditionFields[i]);
17569    
17570                                    if ((i + 1) < orderByConditionFields.length) {
17571                                            if (orderByComparator.isAscending() ^ previous) {
17572                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17573                                            }
17574                                            else {
17575                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17576                                            }
17577                                    }
17578                                    else {
17579                                            if (orderByComparator.isAscending() ^ previous) {
17580                                                    query.append(WHERE_GREATER_THAN);
17581                                            }
17582                                            else {
17583                                                    query.append(WHERE_LESSER_THAN);
17584                                            }
17585                                    }
17586                            }
17587    
17588                            query.append(ORDER_BY_CLAUSE);
17589    
17590                            String[] orderByFields = orderByComparator.getOrderByFields();
17591    
17592                            for (int i = 0; i < orderByFields.length; i++) {
17593                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17594                                    query.append(orderByFields[i]);
17595    
17596                                    if ((i + 1) < orderByFields.length) {
17597                                            if (orderByComparator.isAscending() ^ previous) {
17598                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17599                                            }
17600                                            else {
17601                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17602                                            }
17603                                    }
17604                                    else {
17605                                            if (orderByComparator.isAscending() ^ previous) {
17606                                                    query.append(ORDER_BY_ASC);
17607                                            }
17608                                            else {
17609                                                    query.append(ORDER_BY_DESC);
17610                                            }
17611                                    }
17612                            }
17613                    }
17614                    else {
17615                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
17616                    }
17617    
17618                    String sql = query.toString();
17619    
17620                    Query q = session.createQuery(sql);
17621    
17622                    q.setFirstResult(0);
17623                    q.setMaxResults(2);
17624    
17625                    QueryPos qPos = QueryPos.getInstance(q);
17626    
17627                    qPos.add(nodeId);
17628    
17629                    qPos.add(head);
17630    
17631                    if (bindParentTitle) {
17632                            qPos.add(parentTitle.toLowerCase());
17633                    }
17634    
17635                    qPos.add(status);
17636    
17637                    if (orderByComparator != null) {
17638                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
17639    
17640                            for (Object value : values) {
17641                                    qPos.add(value);
17642                            }
17643                    }
17644    
17645                    List<WikiPage> list = q.list();
17646    
17647                    if (list.size() == 2) {
17648                            return list.get(1);
17649                    }
17650                    else {
17651                            return null;
17652                    }
17653            }
17654    
17655            /**
17656             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63; from the database.
17657             *
17658             * @param nodeId the node ID
17659             * @param head the head
17660             * @param parentTitle the parent title
17661             * @param status the status
17662             * @throws SystemException if a system exception occurred
17663             */
17664            @Override
17665            public void removeByN_H_P_S(long nodeId, boolean head, String parentTitle,
17666                    int status) throws SystemException {
17667                    for (WikiPage wikiPage : findByN_H_P_S(nodeId, head, parentTitle,
17668                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17669                            remove(wikiPage);
17670                    }
17671            }
17672    
17673            /**
17674             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17675             *
17676             * @param nodeId the node ID
17677             * @param head the head
17678             * @param parentTitle the parent title
17679             * @param status the status
17680             * @return the number of matching wiki pages
17681             * @throws SystemException if a system exception occurred
17682             */
17683            @Override
17684            public int countByN_H_P_S(long nodeId, boolean head, String parentTitle,
17685                    int status) throws SystemException {
17686                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_P_S;
17687    
17688                    Object[] finderArgs = new Object[] { nodeId, head, parentTitle, status };
17689    
17690                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
17691                                    this);
17692    
17693                    if (count == null) {
17694                            StringBundler query = new StringBundler(5);
17695    
17696                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
17697    
17698                            query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
17699    
17700                            query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
17701    
17702                            boolean bindParentTitle = false;
17703    
17704                            if (parentTitle == null) {
17705                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
17706                            }
17707                            else if (parentTitle.equals(StringPool.BLANK)) {
17708                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
17709                            }
17710                            else {
17711                                    bindParentTitle = true;
17712    
17713                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
17714                            }
17715    
17716                            query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
17717    
17718                            String sql = query.toString();
17719    
17720                            Session session = null;
17721    
17722                            try {
17723                                    session = openSession();
17724    
17725                                    Query q = session.createQuery(sql);
17726    
17727                                    QueryPos qPos = QueryPos.getInstance(q);
17728    
17729                                    qPos.add(nodeId);
17730    
17731                                    qPos.add(head);
17732    
17733                                    if (bindParentTitle) {
17734                                            qPos.add(parentTitle.toLowerCase());
17735                                    }
17736    
17737                                    qPos.add(status);
17738    
17739                                    count = (Long)q.uniqueResult();
17740    
17741                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
17742                            }
17743                            catch (Exception e) {
17744                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17745    
17746                                    throw processException(e);
17747                            }
17748                            finally {
17749                                    closeSession(session);
17750                            }
17751                    }
17752    
17753                    return count.intValue();
17754            }
17755    
17756            private static final String _FINDER_COLUMN_N_H_P_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
17757            private static final String _FINDER_COLUMN_N_H_P_S_HEAD_2 = "wikiPage.head = ? AND ";
17758            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL AND ";
17759            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ? AND ";
17760            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '') AND ";
17761            private static final String _FINDER_COLUMN_N_H_P_S_STATUS_2 = "wikiPage.status = ?";
17762            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_NOTS =
17763                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17764                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
17765                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_P_NotS",
17766                            new String[] {
17767                                    Long.class.getName(), Boolean.class.getName(),
17768                                    String.class.getName(), Integer.class.getName(),
17769                                    
17770                            Integer.class.getName(), Integer.class.getName(),
17771                                    OrderByComparator.class.getName()
17772                            });
17773            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_N_H_P_NOTS =
17774                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17775                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17776                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByN_H_P_NotS",
17777                            new String[] {
17778                                    Long.class.getName(), Boolean.class.getName(),
17779                                    String.class.getName(), Integer.class.getName()
17780                            });
17781    
17782            /**
17783             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
17784             *
17785             * @param nodeId the node ID
17786             * @param head the head
17787             * @param parentTitle the parent title
17788             * @param status the status
17789             * @return the matching wiki pages
17790             * @throws SystemException if a system exception occurred
17791             */
17792            @Override
17793            public List<WikiPage> findByN_H_P_NotS(long nodeId, boolean head,
17794                    String parentTitle, int status) throws SystemException {
17795                    return findByN_H_P_NotS(nodeId, head, parentTitle, status,
17796                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17797            }
17798    
17799            /**
17800             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
17801             *
17802             * <p>
17803             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
17804             * </p>
17805             *
17806             * @param nodeId the node ID
17807             * @param head the head
17808             * @param parentTitle the parent title
17809             * @param status the status
17810             * @param start the lower bound of the range of wiki pages
17811             * @param end the upper bound of the range of wiki pages (not inclusive)
17812             * @return the range of matching wiki pages
17813             * @throws SystemException if a system exception occurred
17814             */
17815            @Override
17816            public List<WikiPage> findByN_H_P_NotS(long nodeId, boolean head,
17817                    String parentTitle, int status, int start, int end)
17818                    throws SystemException {
17819                    return findByN_H_P_NotS(nodeId, head, parentTitle, status, start, end,
17820                            null);
17821            }
17822    
17823            /**
17824             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
17825             *
17826             * <p>
17827             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
17828             * </p>
17829             *
17830             * @param nodeId the node ID
17831             * @param head the head
17832             * @param parentTitle the parent title
17833             * @param status the status
17834             * @param start the lower bound of the range of wiki pages
17835             * @param end the upper bound of the range of wiki pages (not inclusive)
17836             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17837             * @return the ordered range of matching wiki pages
17838             * @throws SystemException if a system exception occurred
17839             */
17840            @Override
17841            public List<WikiPage> findByN_H_P_NotS(long nodeId, boolean head,
17842                    String parentTitle, int status, int start, int end,
17843                    OrderByComparator orderByComparator) throws SystemException {
17844                    boolean pagination = true;
17845                    FinderPath finderPath = null;
17846                    Object[] finderArgs = null;
17847    
17848                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_NOTS;
17849                    finderArgs = new Object[] {
17850                                    nodeId, head, parentTitle, status,
17851                                    
17852                                    start, end, orderByComparator
17853                            };
17854    
17855                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
17856                                    finderArgs, this);
17857    
17858                    if ((list != null) && !list.isEmpty()) {
17859                            for (WikiPage wikiPage : list) {
17860                                    if ((nodeId != wikiPage.getNodeId()) ||
17861                                                    (head != wikiPage.getHead()) ||
17862                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle()) ||
17863                                                    (status == wikiPage.getStatus())) {
17864                                            list = null;
17865    
17866                                            break;
17867                                    }
17868                            }
17869                    }
17870    
17871                    if (list == null) {
17872                            StringBundler query = null;
17873    
17874                            if (orderByComparator != null) {
17875                                    query = new StringBundler(6 +
17876                                                    (orderByComparator.getOrderByFields().length * 3));
17877                            }
17878                            else {
17879                                    query = new StringBundler(6);
17880                            }
17881    
17882                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
17883    
17884                            query.append(_FINDER_COLUMN_N_H_P_NOTS_NODEID_2);
17885    
17886                            query.append(_FINDER_COLUMN_N_H_P_NOTS_HEAD_2);
17887    
17888                            boolean bindParentTitle = false;
17889    
17890                            if (parentTitle == null) {
17891                                    query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_1);
17892                            }
17893                            else if (parentTitle.equals(StringPool.BLANK)) {
17894                                    query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_3);
17895                            }
17896                            else {
17897                                    bindParentTitle = true;
17898    
17899                                    query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_2);
17900                            }
17901    
17902                            query.append(_FINDER_COLUMN_N_H_P_NOTS_STATUS_2);
17903    
17904                            if (orderByComparator != null) {
17905                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17906                                            orderByComparator);
17907                            }
17908                            else
17909                             if (pagination) {
17910                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
17911                            }
17912    
17913                            String sql = query.toString();
17914    
17915                            Session session = null;
17916    
17917                            try {
17918                                    session = openSession();
17919    
17920                                    Query q = session.createQuery(sql);
17921    
17922                                    QueryPos qPos = QueryPos.getInstance(q);
17923    
17924                                    qPos.add(nodeId);
17925    
17926                                    qPos.add(head);
17927    
17928                                    if (bindParentTitle) {
17929                                            qPos.add(parentTitle.toLowerCase());
17930                                    }
17931    
17932                                    qPos.add(status);
17933    
17934                                    if (!pagination) {
17935                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
17936                                                            start, end, false);
17937    
17938                                            Collections.sort(list);
17939    
17940                                            list = new UnmodifiableList<WikiPage>(list);
17941                                    }
17942                                    else {
17943                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
17944                                                            start, end);
17945                                    }
17946    
17947                                    cacheResult(list);
17948    
17949                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
17950                            }
17951                            catch (Exception e) {
17952                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17953    
17954                                    throw processException(e);
17955                            }
17956                            finally {
17957                                    closeSession(session);
17958                            }
17959                    }
17960    
17961                    return list;
17962            }
17963    
17964            /**
17965             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
17966             *
17967             * @param nodeId the node ID
17968             * @param head the head
17969             * @param parentTitle the parent title
17970             * @param status the status
17971             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17972             * @return the first matching wiki page
17973             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
17974             * @throws SystemException if a system exception occurred
17975             */
17976            @Override
17977            public WikiPage findByN_H_P_NotS_First(long nodeId, boolean head,
17978                    String parentTitle, int status, OrderByComparator orderByComparator)
17979                    throws NoSuchPageException, SystemException {
17980                    WikiPage wikiPage = fetchByN_H_P_NotS_First(nodeId, head, parentTitle,
17981                                    status, orderByComparator);
17982    
17983                    if (wikiPage != null) {
17984                            return wikiPage;
17985                    }
17986    
17987                    StringBundler msg = new StringBundler(10);
17988    
17989                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17990    
17991                    msg.append("nodeId=");
17992                    msg.append(nodeId);
17993    
17994                    msg.append(", head=");
17995                    msg.append(head);
17996    
17997                    msg.append(", parentTitle=");
17998                    msg.append(parentTitle);
17999    
18000                    msg.append(", status=");
18001                    msg.append(status);
18002    
18003                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18004    
18005                    throw new NoSuchPageException(msg.toString());
18006            }
18007    
18008            /**
18009             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
18010             *
18011             * @param nodeId the node ID
18012             * @param head the head
18013             * @param parentTitle the parent title
18014             * @param status the status
18015             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18016             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
18017             * @throws SystemException if a system exception occurred
18018             */
18019            @Override
18020            public WikiPage fetchByN_H_P_NotS_First(long nodeId, boolean head,
18021                    String parentTitle, int status, OrderByComparator orderByComparator)
18022                    throws SystemException {
18023                    List<WikiPage> list = findByN_H_P_NotS(nodeId, head, parentTitle,
18024                                    status, 0, 1, orderByComparator);
18025    
18026                    if (!list.isEmpty()) {
18027                            return list.get(0);
18028                    }
18029    
18030                    return null;
18031            }
18032    
18033            /**
18034             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
18035             *
18036             * @param nodeId the node ID
18037             * @param head the head
18038             * @param parentTitle the parent title
18039             * @param status the status
18040             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18041             * @return the last matching wiki page
18042             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
18043             * @throws SystemException if a system exception occurred
18044             */
18045            @Override
18046            public WikiPage findByN_H_P_NotS_Last(long nodeId, boolean head,
18047                    String parentTitle, int status, OrderByComparator orderByComparator)
18048                    throws NoSuchPageException, SystemException {
18049                    WikiPage wikiPage = fetchByN_H_P_NotS_Last(nodeId, head, parentTitle,
18050                                    status, orderByComparator);
18051    
18052                    if (wikiPage != null) {
18053                            return wikiPage;
18054                    }
18055    
18056                    StringBundler msg = new StringBundler(10);
18057    
18058                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18059    
18060                    msg.append("nodeId=");
18061                    msg.append(nodeId);
18062    
18063                    msg.append(", head=");
18064                    msg.append(head);
18065    
18066                    msg.append(", parentTitle=");
18067                    msg.append(parentTitle);
18068    
18069                    msg.append(", status=");
18070                    msg.append(status);
18071    
18072                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18073    
18074                    throw new NoSuchPageException(msg.toString());
18075            }
18076    
18077            /**
18078             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
18079             *
18080             * @param nodeId the node ID
18081             * @param head the head
18082             * @param parentTitle the parent title
18083             * @param status the status
18084             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18085             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
18086             * @throws SystemException if a system exception occurred
18087             */
18088            @Override
18089            public WikiPage fetchByN_H_P_NotS_Last(long nodeId, boolean head,
18090                    String parentTitle, int status, OrderByComparator orderByComparator)
18091                    throws SystemException {
18092                    int count = countByN_H_P_NotS(nodeId, head, parentTitle, status);
18093    
18094                    if (count == 0) {
18095                            return null;
18096                    }
18097    
18098                    List<WikiPage> list = findByN_H_P_NotS(nodeId, head, parentTitle,
18099                                    status, count - 1, count, orderByComparator);
18100    
18101                    if (!list.isEmpty()) {
18102                            return list.get(0);
18103                    }
18104    
18105                    return null;
18106            }
18107    
18108            /**
18109             * 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;.
18110             *
18111             * @param pageId the primary key of the current wiki page
18112             * @param nodeId the node ID
18113             * @param head the head
18114             * @param parentTitle the parent title
18115             * @param status the status
18116             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18117             * @return the previous, current, and next wiki page
18118             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
18119             * @throws SystemException if a system exception occurred
18120             */
18121            @Override
18122            public WikiPage[] findByN_H_P_NotS_PrevAndNext(long pageId, long nodeId,
18123                    boolean head, String parentTitle, int status,
18124                    OrderByComparator orderByComparator)
18125                    throws NoSuchPageException, SystemException {
18126                    WikiPage wikiPage = findByPrimaryKey(pageId);
18127    
18128                    Session session = null;
18129    
18130                    try {
18131                            session = openSession();
18132    
18133                            WikiPage[] array = new WikiPageImpl[3];
18134    
18135                            array[0] = getByN_H_P_NotS_PrevAndNext(session, wikiPage, nodeId,
18136                                            head, parentTitle, status, orderByComparator, true);
18137    
18138                            array[1] = wikiPage;
18139    
18140                            array[2] = getByN_H_P_NotS_PrevAndNext(session, wikiPage, nodeId,
18141                                            head, parentTitle, status, orderByComparator, false);
18142    
18143                            return array;
18144                    }
18145                    catch (Exception e) {
18146                            throw processException(e);
18147                    }
18148                    finally {
18149                            closeSession(session);
18150                    }
18151            }
18152    
18153            protected WikiPage getByN_H_P_NotS_PrevAndNext(Session session,
18154                    WikiPage wikiPage, long nodeId, boolean head, String parentTitle,
18155                    int status, OrderByComparator orderByComparator, boolean previous) {
18156                    StringBundler query = null;
18157    
18158                    if (orderByComparator != null) {
18159                            query = new StringBundler(6 +
18160                                            (orderByComparator.getOrderByFields().length * 6));
18161                    }
18162                    else {
18163                            query = new StringBundler(3);
18164                    }
18165    
18166                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
18167    
18168                    query.append(_FINDER_COLUMN_N_H_P_NOTS_NODEID_2);
18169    
18170                    query.append(_FINDER_COLUMN_N_H_P_NOTS_HEAD_2);
18171    
18172                    boolean bindParentTitle = false;
18173    
18174                    if (parentTitle == null) {
18175                            query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_1);
18176                    }
18177                    else if (parentTitle.equals(StringPool.BLANK)) {
18178                            query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_3);
18179                    }
18180                    else {
18181                            bindParentTitle = true;
18182    
18183                            query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_2);
18184                    }
18185    
18186                    query.append(_FINDER_COLUMN_N_H_P_NOTS_STATUS_2);
18187    
18188                    if (orderByComparator != null) {
18189                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18190    
18191                            if (orderByConditionFields.length > 0) {
18192                                    query.append(WHERE_AND);
18193                            }
18194    
18195                            for (int i = 0; i < orderByConditionFields.length; i++) {
18196                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18197                                    query.append(orderByConditionFields[i]);
18198    
18199                                    if ((i + 1) < orderByConditionFields.length) {
18200                                            if (orderByComparator.isAscending() ^ previous) {
18201                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18202                                            }
18203                                            else {
18204                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18205                                            }
18206                                    }
18207                                    else {
18208                                            if (orderByComparator.isAscending() ^ previous) {
18209                                                    query.append(WHERE_GREATER_THAN);
18210                                            }
18211                                            else {
18212                                                    query.append(WHERE_LESSER_THAN);
18213                                            }
18214                                    }
18215                            }
18216    
18217                            query.append(ORDER_BY_CLAUSE);
18218    
18219                            String[] orderByFields = orderByComparator.getOrderByFields();
18220    
18221                            for (int i = 0; i < orderByFields.length; i++) {
18222                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18223                                    query.append(orderByFields[i]);
18224    
18225                                    if ((i + 1) < orderByFields.length) {
18226                                            if (orderByComparator.isAscending() ^ previous) {
18227                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18228                                            }
18229                                            else {
18230                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18231                                            }
18232                                    }
18233                                    else {
18234                                            if (orderByComparator.isAscending() ^ previous) {
18235                                                    query.append(ORDER_BY_ASC);
18236                                            }
18237                                            else {
18238                                                    query.append(ORDER_BY_DESC);
18239                                            }
18240                                    }
18241                            }
18242                    }
18243                    else {
18244                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
18245                    }
18246    
18247                    String sql = query.toString();
18248    
18249                    Query q = session.createQuery(sql);
18250    
18251                    q.setFirstResult(0);
18252                    q.setMaxResults(2);
18253    
18254                    QueryPos qPos = QueryPos.getInstance(q);
18255    
18256                    qPos.add(nodeId);
18257    
18258                    qPos.add(head);
18259    
18260                    if (bindParentTitle) {
18261                            qPos.add(parentTitle.toLowerCase());
18262                    }
18263    
18264                    qPos.add(status);
18265    
18266                    if (orderByComparator != null) {
18267                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
18268    
18269                            for (Object value : values) {
18270                                    qPos.add(value);
18271                            }
18272                    }
18273    
18274                    List<WikiPage> list = q.list();
18275    
18276                    if (list.size() == 2) {
18277                            return list.get(1);
18278                    }
18279                    else {
18280                            return null;
18281                    }
18282            }
18283    
18284            /**
18285             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63; from the database.
18286             *
18287             * @param nodeId the node ID
18288             * @param head the head
18289             * @param parentTitle the parent title
18290             * @param status the status
18291             * @throws SystemException if a system exception occurred
18292             */
18293            @Override
18294            public void removeByN_H_P_NotS(long nodeId, boolean head,
18295                    String parentTitle, int status) throws SystemException {
18296                    for (WikiPage wikiPage : findByN_H_P_NotS(nodeId, head, parentTitle,
18297                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18298                            remove(wikiPage);
18299                    }
18300            }
18301    
18302            /**
18303             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
18304             *
18305             * @param nodeId the node ID
18306             * @param head the head
18307             * @param parentTitle the parent title
18308             * @param status the status
18309             * @return the number of matching wiki pages
18310             * @throws SystemException if a system exception occurred
18311             */
18312            @Override
18313            public int countByN_H_P_NotS(long nodeId, boolean head, String parentTitle,
18314                    int status) throws SystemException {
18315                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_N_H_P_NOTS;
18316    
18317                    Object[] finderArgs = new Object[] { nodeId, head, parentTitle, status };
18318    
18319                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
18320                                    this);
18321    
18322                    if (count == null) {
18323                            StringBundler query = new StringBundler(5);
18324    
18325                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
18326    
18327                            query.append(_FINDER_COLUMN_N_H_P_NOTS_NODEID_2);
18328    
18329                            query.append(_FINDER_COLUMN_N_H_P_NOTS_HEAD_2);
18330    
18331                            boolean bindParentTitle = false;
18332    
18333                            if (parentTitle == null) {
18334                                    query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_1);
18335                            }
18336                            else if (parentTitle.equals(StringPool.BLANK)) {
18337                                    query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_3);
18338                            }
18339                            else {
18340                                    bindParentTitle = true;
18341    
18342                                    query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_2);
18343                            }
18344    
18345                            query.append(_FINDER_COLUMN_N_H_P_NOTS_STATUS_2);
18346    
18347                            String sql = query.toString();
18348    
18349                            Session session = null;
18350    
18351                            try {
18352                                    session = openSession();
18353    
18354                                    Query q = session.createQuery(sql);
18355    
18356                                    QueryPos qPos = QueryPos.getInstance(q);
18357    
18358                                    qPos.add(nodeId);
18359    
18360                                    qPos.add(head);
18361    
18362                                    if (bindParentTitle) {
18363                                            qPos.add(parentTitle.toLowerCase());
18364                                    }
18365    
18366                                    qPos.add(status);
18367    
18368                                    count = (Long)q.uniqueResult();
18369    
18370                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
18371                            }
18372                            catch (Exception e) {
18373                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18374    
18375                                    throw processException(e);
18376                            }
18377                            finally {
18378                                    closeSession(session);
18379                            }
18380                    }
18381    
18382                    return count.intValue();
18383            }
18384    
18385            private static final String _FINDER_COLUMN_N_H_P_NOTS_NODEID_2 = "wikiPage.nodeId = ? AND ";
18386            private static final String _FINDER_COLUMN_N_H_P_NOTS_HEAD_2 = "wikiPage.head = ? AND ";
18387            private static final String _FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL AND ";
18388            private static final String _FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ? AND ";
18389            private static final String _FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '') AND ";
18390            private static final String _FINDER_COLUMN_N_H_P_NOTS_STATUS_2 = "wikiPage.status != ?";
18391            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_R_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
18392                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
18393                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_R_S",
18394                            new String[] {
18395                                    Long.class.getName(), Boolean.class.getName(),
18396                                    String.class.getName(), Integer.class.getName(),
18397                                    
18398                            Integer.class.getName(), Integer.class.getName(),
18399                                    OrderByComparator.class.getName()
18400                            });
18401            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_R_S =
18402                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
18403                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
18404                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_R_S",
18405                            new String[] {
18406                                    Long.class.getName(), Boolean.class.getName(),
18407                                    String.class.getName(), Integer.class.getName()
18408                            },
18409                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
18410                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
18411                            WikiPageModelImpl.REDIRECTTITLE_COLUMN_BITMASK |
18412                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
18413                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
18414                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
18415            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_R_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
18416                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
18417                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_R_S",
18418                            new String[] {
18419                                    Long.class.getName(), Boolean.class.getName(),
18420                                    String.class.getName(), Integer.class.getName()
18421                            });
18422    
18423            /**
18424             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
18425             *
18426             * @param nodeId the node ID
18427             * @param head the head
18428             * @param redirectTitle the redirect title
18429             * @param status the status
18430             * @return the matching wiki pages
18431             * @throws SystemException if a system exception occurred
18432             */
18433            @Override
18434            public List<WikiPage> findByN_H_R_S(long nodeId, boolean head,
18435                    String redirectTitle, int status) throws SystemException {
18436                    return findByN_H_R_S(nodeId, head, redirectTitle, status,
18437                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
18438            }
18439    
18440            /**
18441             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
18442             *
18443             * <p>
18444             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
18445             * </p>
18446             *
18447             * @param nodeId the node ID
18448             * @param head the head
18449             * @param redirectTitle the redirect title
18450             * @param status the status
18451             * @param start the lower bound of the range of wiki pages
18452             * @param end the upper bound of the range of wiki pages (not inclusive)
18453             * @return the range of matching wiki pages
18454             * @throws SystemException if a system exception occurred
18455             */
18456            @Override
18457            public List<WikiPage> findByN_H_R_S(long nodeId, boolean head,
18458                    String redirectTitle, int status, int start, int end)
18459                    throws SystemException {
18460                    return findByN_H_R_S(nodeId, head, redirectTitle, status, start, end,
18461                            null);
18462            }
18463    
18464            /**
18465             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
18466             *
18467             * <p>
18468             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
18469             * </p>
18470             *
18471             * @param nodeId the node ID
18472             * @param head the head
18473             * @param redirectTitle the redirect title
18474             * @param status the status
18475             * @param start the lower bound of the range of wiki pages
18476             * @param end the upper bound of the range of wiki pages (not inclusive)
18477             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18478             * @return the ordered range of matching wiki pages
18479             * @throws SystemException if a system exception occurred
18480             */
18481            @Override
18482            public List<WikiPage> findByN_H_R_S(long nodeId, boolean head,
18483                    String redirectTitle, int status, int start, int end,
18484                    OrderByComparator orderByComparator) throws SystemException {
18485                    boolean pagination = true;
18486                    FinderPath finderPath = null;
18487                    Object[] finderArgs = null;
18488    
18489                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
18490                                    (orderByComparator == null)) {
18491                            pagination = false;
18492                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_R_S;
18493                            finderArgs = new Object[] { nodeId, head, redirectTitle, status };
18494                    }
18495                    else {
18496                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_R_S;
18497                            finderArgs = new Object[] {
18498                                            nodeId, head, redirectTitle, status,
18499                                            
18500                                            start, end, orderByComparator
18501                                    };
18502                    }
18503    
18504                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
18505                                    finderArgs, this);
18506    
18507                    if ((list != null) && !list.isEmpty()) {
18508                            for (WikiPage wikiPage : list) {
18509                                    if ((nodeId != wikiPage.getNodeId()) ||
18510                                                    (head != wikiPage.getHead()) ||
18511                                                    !Validator.equals(redirectTitle,
18512                                                            wikiPage.getRedirectTitle()) ||
18513                                                    (status != wikiPage.getStatus())) {
18514                                            list = null;
18515    
18516                                            break;
18517                                    }
18518                            }
18519                    }
18520    
18521                    if (list == null) {
18522                            StringBundler query = null;
18523    
18524                            if (orderByComparator != null) {
18525                                    query = new StringBundler(6 +
18526                                                    (orderByComparator.getOrderByFields().length * 3));
18527                            }
18528                            else {
18529                                    query = new StringBundler(6);
18530                            }
18531    
18532                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
18533    
18534                            query.append(_FINDER_COLUMN_N_H_R_S_NODEID_2);
18535    
18536                            query.append(_FINDER_COLUMN_N_H_R_S_HEAD_2);
18537    
18538                            boolean bindRedirectTitle = false;
18539    
18540                            if (redirectTitle == null) {
18541                                    query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_1);
18542                            }
18543                            else if (redirectTitle.equals(StringPool.BLANK)) {
18544                                    query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_3);
18545                            }
18546                            else {
18547                                    bindRedirectTitle = true;
18548    
18549                                    query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_2);
18550                            }
18551    
18552                            query.append(_FINDER_COLUMN_N_H_R_S_STATUS_2);
18553    
18554                            if (orderByComparator != null) {
18555                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18556                                            orderByComparator);
18557                            }
18558                            else
18559                             if (pagination) {
18560                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
18561                            }
18562    
18563                            String sql = query.toString();
18564    
18565                            Session session = null;
18566    
18567                            try {
18568                                    session = openSession();
18569    
18570                                    Query q = session.createQuery(sql);
18571    
18572                                    QueryPos qPos = QueryPos.getInstance(q);
18573    
18574                                    qPos.add(nodeId);
18575    
18576                                    qPos.add(head);
18577    
18578                                    if (bindRedirectTitle) {
18579                                            qPos.add(redirectTitle.toLowerCase());
18580                                    }
18581    
18582                                    qPos.add(status);
18583    
18584                                    if (!pagination) {
18585                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
18586                                                            start, end, false);
18587    
18588                                            Collections.sort(list);
18589    
18590                                            list = new UnmodifiableList<WikiPage>(list);
18591                                    }
18592                                    else {
18593                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
18594                                                            start, end);
18595                                    }
18596    
18597                                    cacheResult(list);
18598    
18599                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
18600                            }
18601                            catch (Exception e) {
18602                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18603    
18604                                    throw processException(e);
18605                            }
18606                            finally {
18607                                    closeSession(session);
18608                            }
18609                    }
18610    
18611                    return list;
18612            }
18613    
18614            /**
18615             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
18616             *
18617             * @param nodeId the node ID
18618             * @param head the head
18619             * @param redirectTitle the redirect title
18620             * @param status the status
18621             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18622             * @return the first matching wiki page
18623             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
18624             * @throws SystemException if a system exception occurred
18625             */
18626            @Override
18627            public WikiPage findByN_H_R_S_First(long nodeId, boolean head,
18628                    String redirectTitle, int status, OrderByComparator orderByComparator)
18629                    throws NoSuchPageException, SystemException {
18630                    WikiPage wikiPage = fetchByN_H_R_S_First(nodeId, head, redirectTitle,
18631                                    status, orderByComparator);
18632    
18633                    if (wikiPage != null) {
18634                            return wikiPage;
18635                    }
18636    
18637                    StringBundler msg = new StringBundler(10);
18638    
18639                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18640    
18641                    msg.append("nodeId=");
18642                    msg.append(nodeId);
18643    
18644                    msg.append(", head=");
18645                    msg.append(head);
18646    
18647                    msg.append(", redirectTitle=");
18648                    msg.append(redirectTitle);
18649    
18650                    msg.append(", status=");
18651                    msg.append(status);
18652    
18653                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18654    
18655                    throw new NoSuchPageException(msg.toString());
18656            }
18657    
18658            /**
18659             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
18660             *
18661             * @param nodeId the node ID
18662             * @param head the head
18663             * @param redirectTitle the redirect title
18664             * @param status the status
18665             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18666             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
18667             * @throws SystemException if a system exception occurred
18668             */
18669            @Override
18670            public WikiPage fetchByN_H_R_S_First(long nodeId, boolean head,
18671                    String redirectTitle, int status, OrderByComparator orderByComparator)
18672                    throws SystemException {
18673                    List<WikiPage> list = findByN_H_R_S(nodeId, head, redirectTitle,
18674                                    status, 0, 1, orderByComparator);
18675    
18676                    if (!list.isEmpty()) {
18677                            return list.get(0);
18678                    }
18679    
18680                    return null;
18681            }
18682    
18683            /**
18684             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
18685             *
18686             * @param nodeId the node ID
18687             * @param head the head
18688             * @param redirectTitle the redirect title
18689             * @param status the status
18690             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18691             * @return the last matching wiki page
18692             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
18693             * @throws SystemException if a system exception occurred
18694             */
18695            @Override
18696            public WikiPage findByN_H_R_S_Last(long nodeId, boolean head,
18697                    String redirectTitle, int status, OrderByComparator orderByComparator)
18698                    throws NoSuchPageException, SystemException {
18699                    WikiPage wikiPage = fetchByN_H_R_S_Last(nodeId, head, redirectTitle,
18700                                    status, orderByComparator);
18701    
18702                    if (wikiPage != null) {
18703                            return wikiPage;
18704                    }
18705    
18706                    StringBundler msg = new StringBundler(10);
18707    
18708                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18709    
18710                    msg.append("nodeId=");
18711                    msg.append(nodeId);
18712    
18713                    msg.append(", head=");
18714                    msg.append(head);
18715    
18716                    msg.append(", redirectTitle=");
18717                    msg.append(redirectTitle);
18718    
18719                    msg.append(", status=");
18720                    msg.append(status);
18721    
18722                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18723    
18724                    throw new NoSuchPageException(msg.toString());
18725            }
18726    
18727            /**
18728             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
18729             *
18730             * @param nodeId the node ID
18731             * @param head the head
18732             * @param redirectTitle the redirect title
18733             * @param status the status
18734             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18735             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
18736             * @throws SystemException if a system exception occurred
18737             */
18738            @Override
18739            public WikiPage fetchByN_H_R_S_Last(long nodeId, boolean head,
18740                    String redirectTitle, int status, OrderByComparator orderByComparator)
18741                    throws SystemException {
18742                    int count = countByN_H_R_S(nodeId, head, redirectTitle, status);
18743    
18744                    if (count == 0) {
18745                            return null;
18746                    }
18747    
18748                    List<WikiPage> list = findByN_H_R_S(nodeId, head, redirectTitle,
18749                                    status, count - 1, count, orderByComparator);
18750    
18751                    if (!list.isEmpty()) {
18752                            return list.get(0);
18753                    }
18754    
18755                    return null;
18756            }
18757    
18758            /**
18759             * 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;.
18760             *
18761             * @param pageId the primary key of the current wiki page
18762             * @param nodeId the node ID
18763             * @param head the head
18764             * @param redirectTitle the redirect title
18765             * @param status the status
18766             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18767             * @return the previous, current, and next wiki page
18768             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
18769             * @throws SystemException if a system exception occurred
18770             */
18771            @Override
18772            public WikiPage[] findByN_H_R_S_PrevAndNext(long pageId, long nodeId,
18773                    boolean head, String redirectTitle, int status,
18774                    OrderByComparator orderByComparator)
18775                    throws NoSuchPageException, SystemException {
18776                    WikiPage wikiPage = findByPrimaryKey(pageId);
18777    
18778                    Session session = null;
18779    
18780                    try {
18781                            session = openSession();
18782    
18783                            WikiPage[] array = new WikiPageImpl[3];
18784    
18785                            array[0] = getByN_H_R_S_PrevAndNext(session, wikiPage, nodeId,
18786                                            head, redirectTitle, status, orderByComparator, true);
18787    
18788                            array[1] = wikiPage;
18789    
18790                            array[2] = getByN_H_R_S_PrevAndNext(session, wikiPage, nodeId,
18791                                            head, redirectTitle, status, orderByComparator, false);
18792    
18793                            return array;
18794                    }
18795                    catch (Exception e) {
18796                            throw processException(e);
18797                    }
18798                    finally {
18799                            closeSession(session);
18800                    }
18801            }
18802    
18803            protected WikiPage getByN_H_R_S_PrevAndNext(Session session,
18804                    WikiPage wikiPage, long nodeId, boolean head, String redirectTitle,
18805                    int status, OrderByComparator orderByComparator, boolean previous) {
18806                    StringBundler query = null;
18807    
18808                    if (orderByComparator != null) {
18809                            query = new StringBundler(6 +
18810                                            (orderByComparator.getOrderByFields().length * 6));
18811                    }
18812                    else {
18813                            query = new StringBundler(3);
18814                    }
18815    
18816                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
18817    
18818                    query.append(_FINDER_COLUMN_N_H_R_S_NODEID_2);
18819    
18820                    query.append(_FINDER_COLUMN_N_H_R_S_HEAD_2);
18821    
18822                    boolean bindRedirectTitle = false;
18823    
18824                    if (redirectTitle == null) {
18825                            query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_1);
18826                    }
18827                    else if (redirectTitle.equals(StringPool.BLANK)) {
18828                            query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_3);
18829                    }
18830                    else {
18831                            bindRedirectTitle = true;
18832    
18833                            query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_2);
18834                    }
18835    
18836                    query.append(_FINDER_COLUMN_N_H_R_S_STATUS_2);
18837    
18838                    if (orderByComparator != null) {
18839                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18840    
18841                            if (orderByConditionFields.length > 0) {
18842                                    query.append(WHERE_AND);
18843                            }
18844    
18845                            for (int i = 0; i < orderByConditionFields.length; i++) {
18846                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18847                                    query.append(orderByConditionFields[i]);
18848    
18849                                    if ((i + 1) < orderByConditionFields.length) {
18850                                            if (orderByComparator.isAscending() ^ previous) {
18851                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18852                                            }
18853                                            else {
18854                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18855                                            }
18856                                    }
18857                                    else {
18858                                            if (orderByComparator.isAscending() ^ previous) {
18859                                                    query.append(WHERE_GREATER_THAN);
18860                                            }
18861                                            else {
18862                                                    query.append(WHERE_LESSER_THAN);
18863                                            }
18864                                    }
18865                            }
18866    
18867                            query.append(ORDER_BY_CLAUSE);
18868    
18869                            String[] orderByFields = orderByComparator.getOrderByFields();
18870    
18871                            for (int i = 0; i < orderByFields.length; i++) {
18872                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18873                                    query.append(orderByFields[i]);
18874    
18875                                    if ((i + 1) < orderByFields.length) {
18876                                            if (orderByComparator.isAscending() ^ previous) {
18877                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18878                                            }
18879                                            else {
18880                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18881                                            }
18882                                    }
18883                                    else {
18884                                            if (orderByComparator.isAscending() ^ previous) {
18885                                                    query.append(ORDER_BY_ASC);
18886                                            }
18887                                            else {
18888                                                    query.append(ORDER_BY_DESC);
18889                                            }
18890                                    }
18891                            }
18892                    }
18893                    else {
18894                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
18895                    }
18896    
18897                    String sql = query.toString();
18898    
18899                    Query q = session.createQuery(sql);
18900    
18901                    q.setFirstResult(0);
18902                    q.setMaxResults(2);
18903    
18904                    QueryPos qPos = QueryPos.getInstance(q);
18905    
18906                    qPos.add(nodeId);
18907    
18908                    qPos.add(head);
18909    
18910                    if (bindRedirectTitle) {
18911                            qPos.add(redirectTitle.toLowerCase());
18912                    }
18913    
18914                    qPos.add(status);
18915    
18916                    if (orderByComparator != null) {
18917                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
18918    
18919                            for (Object value : values) {
18920                                    qPos.add(value);
18921                            }
18922                    }
18923    
18924                    List<WikiPage> list = q.list();
18925    
18926                    if (list.size() == 2) {
18927                            return list.get(1);
18928                    }
18929                    else {
18930                            return null;
18931                    }
18932            }
18933    
18934            /**
18935             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63; from the database.
18936             *
18937             * @param nodeId the node ID
18938             * @param head the head
18939             * @param redirectTitle the redirect title
18940             * @param status the status
18941             * @throws SystemException if a system exception occurred
18942             */
18943            @Override
18944            public void removeByN_H_R_S(long nodeId, boolean head,
18945                    String redirectTitle, int status) throws SystemException {
18946                    for (WikiPage wikiPage : findByN_H_R_S(nodeId, head, redirectTitle,
18947                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18948                            remove(wikiPage);
18949                    }
18950            }
18951    
18952            /**
18953             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
18954             *
18955             * @param nodeId the node ID
18956             * @param head the head
18957             * @param redirectTitle the redirect title
18958             * @param status the status
18959             * @return the number of matching wiki pages
18960             * @throws SystemException if a system exception occurred
18961             */
18962            @Override
18963            public int countByN_H_R_S(long nodeId, boolean head, String redirectTitle,
18964                    int status) throws SystemException {
18965                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_R_S;
18966    
18967                    Object[] finderArgs = new Object[] { nodeId, head, redirectTitle, status };
18968    
18969                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
18970                                    this);
18971    
18972                    if (count == null) {
18973                            StringBundler query = new StringBundler(5);
18974    
18975                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
18976    
18977                            query.append(_FINDER_COLUMN_N_H_R_S_NODEID_2);
18978    
18979                            query.append(_FINDER_COLUMN_N_H_R_S_HEAD_2);
18980    
18981                            boolean bindRedirectTitle = false;
18982    
18983                            if (redirectTitle == null) {
18984                                    query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_1);
18985                            }
18986                            else if (redirectTitle.equals(StringPool.BLANK)) {
18987                                    query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_3);
18988                            }
18989                            else {
18990                                    bindRedirectTitle = true;
18991    
18992                                    query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_2);
18993                            }
18994    
18995                            query.append(_FINDER_COLUMN_N_H_R_S_STATUS_2);
18996    
18997                            String sql = query.toString();
18998    
18999                            Session session = null;
19000    
19001                            try {
19002                                    session = openSession();
19003    
19004                                    Query q = session.createQuery(sql);
19005    
19006                                    QueryPos qPos = QueryPos.getInstance(q);
19007    
19008                                    qPos.add(nodeId);
19009    
19010                                    qPos.add(head);
19011    
19012                                    if (bindRedirectTitle) {
19013                                            qPos.add(redirectTitle.toLowerCase());
19014                                    }
19015    
19016                                    qPos.add(status);
19017    
19018                                    count = (Long)q.uniqueResult();
19019    
19020                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
19021                            }
19022                            catch (Exception e) {
19023                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19024    
19025                                    throw processException(e);
19026                            }
19027                            finally {
19028                                    closeSession(session);
19029                            }
19030                    }
19031    
19032                    return count.intValue();
19033            }
19034    
19035            private static final String _FINDER_COLUMN_N_H_R_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
19036            private static final String _FINDER_COLUMN_N_H_R_S_HEAD_2 = "wikiPage.head = ? AND ";
19037            private static final String _FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_1 = "wikiPage.redirectTitle IS NULL AND ";
19038            private static final String _FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_2 = "lower(wikiPage.redirectTitle) = ? AND ";
19039            private static final String _FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_3 = "(wikiPage.redirectTitle IS NULL OR wikiPage.redirectTitle = '') AND ";
19040            private static final String _FINDER_COLUMN_N_H_R_S_STATUS_2 = "wikiPage.status = ?";
19041            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_R_NOTS =
19042                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
19043                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
19044                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_R_NotS",
19045                            new String[] {
19046                                    Long.class.getName(), Boolean.class.getName(),
19047                                    String.class.getName(), Integer.class.getName(),
19048                                    
19049                            Integer.class.getName(), Integer.class.getName(),
19050                                    OrderByComparator.class.getName()
19051                            });
19052            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_N_H_R_NOTS =
19053                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
19054                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
19055                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByN_H_R_NotS",
19056                            new String[] {
19057                                    Long.class.getName(), Boolean.class.getName(),
19058                                    String.class.getName(), Integer.class.getName()
19059                            });
19060    
19061            /**
19062             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
19063             *
19064             * @param nodeId the node ID
19065             * @param head the head
19066             * @param redirectTitle the redirect title
19067             * @param status the status
19068             * @return the matching wiki pages
19069             * @throws SystemException if a system exception occurred
19070             */
19071            @Override
19072            public List<WikiPage> findByN_H_R_NotS(long nodeId, boolean head,
19073                    String redirectTitle, int status) throws SystemException {
19074                    return findByN_H_R_NotS(nodeId, head, redirectTitle, status,
19075                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19076            }
19077    
19078            /**
19079             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
19080             *
19081             * <p>
19082             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
19083             * </p>
19084             *
19085             * @param nodeId the node ID
19086             * @param head the head
19087             * @param redirectTitle the redirect title
19088             * @param status the status
19089             * @param start the lower bound of the range of wiki pages
19090             * @param end the upper bound of the range of wiki pages (not inclusive)
19091             * @return the range of matching wiki pages
19092             * @throws SystemException if a system exception occurred
19093             */
19094            @Override
19095            public List<WikiPage> findByN_H_R_NotS(long nodeId, boolean head,
19096                    String redirectTitle, int status, int start, int end)
19097                    throws SystemException {
19098                    return findByN_H_R_NotS(nodeId, head, redirectTitle, status, start,
19099                            end, null);
19100            }
19101    
19102            /**
19103             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
19104             *
19105             * <p>
19106             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
19107             * </p>
19108             *
19109             * @param nodeId the node ID
19110             * @param head the head
19111             * @param redirectTitle the redirect title
19112             * @param status the status
19113             * @param start the lower bound of the range of wiki pages
19114             * @param end the upper bound of the range of wiki pages (not inclusive)
19115             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19116             * @return the ordered range of matching wiki pages
19117             * @throws SystemException if a system exception occurred
19118             */
19119            @Override
19120            public List<WikiPage> findByN_H_R_NotS(long nodeId, boolean head,
19121                    String redirectTitle, int status, int start, int end,
19122                    OrderByComparator orderByComparator) throws SystemException {
19123                    boolean pagination = true;
19124                    FinderPath finderPath = null;
19125                    Object[] finderArgs = null;
19126    
19127                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_R_NOTS;
19128                    finderArgs = new Object[] {
19129                                    nodeId, head, redirectTitle, status,
19130                                    
19131                                    start, end, orderByComparator
19132                            };
19133    
19134                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
19135                                    finderArgs, this);
19136    
19137                    if ((list != null) && !list.isEmpty()) {
19138                            for (WikiPage wikiPage : list) {
19139                                    if ((nodeId != wikiPage.getNodeId()) ||
19140                                                    (head != wikiPage.getHead()) ||
19141                                                    !Validator.equals(redirectTitle,
19142                                                            wikiPage.getRedirectTitle()) ||
19143                                                    (status == wikiPage.getStatus())) {
19144                                            list = null;
19145    
19146                                            break;
19147                                    }
19148                            }
19149                    }
19150    
19151                    if (list == null) {
19152                            StringBundler query = null;
19153    
19154                            if (orderByComparator != null) {
19155                                    query = new StringBundler(6 +
19156                                                    (orderByComparator.getOrderByFields().length * 3));
19157                            }
19158                            else {
19159                                    query = new StringBundler(6);
19160                            }
19161    
19162                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
19163    
19164                            query.append(_FINDER_COLUMN_N_H_R_NOTS_NODEID_2);
19165    
19166                            query.append(_FINDER_COLUMN_N_H_R_NOTS_HEAD_2);
19167    
19168                            boolean bindRedirectTitle = false;
19169    
19170                            if (redirectTitle == null) {
19171                                    query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_1);
19172                            }
19173                            else if (redirectTitle.equals(StringPool.BLANK)) {
19174                                    query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_3);
19175                            }
19176                            else {
19177                                    bindRedirectTitle = true;
19178    
19179                                    query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_2);
19180                            }
19181    
19182                            query.append(_FINDER_COLUMN_N_H_R_NOTS_STATUS_2);
19183    
19184                            if (orderByComparator != null) {
19185                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19186                                            orderByComparator);
19187                            }
19188                            else
19189                             if (pagination) {
19190                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
19191                            }
19192    
19193                            String sql = query.toString();
19194    
19195                            Session session = null;
19196    
19197                            try {
19198                                    session = openSession();
19199    
19200                                    Query q = session.createQuery(sql);
19201    
19202                                    QueryPos qPos = QueryPos.getInstance(q);
19203    
19204                                    qPos.add(nodeId);
19205    
19206                                    qPos.add(head);
19207    
19208                                    if (bindRedirectTitle) {
19209                                            qPos.add(redirectTitle.toLowerCase());
19210                                    }
19211    
19212                                    qPos.add(status);
19213    
19214                                    if (!pagination) {
19215                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
19216                                                            start, end, false);
19217    
19218                                            Collections.sort(list);
19219    
19220                                            list = new UnmodifiableList<WikiPage>(list);
19221                                    }
19222                                    else {
19223                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
19224                                                            start, end);
19225                                    }
19226    
19227                                    cacheResult(list);
19228    
19229                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
19230                            }
19231                            catch (Exception e) {
19232                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19233    
19234                                    throw processException(e);
19235                            }
19236                            finally {
19237                                    closeSession(session);
19238                            }
19239                    }
19240    
19241                    return list;
19242            }
19243    
19244            /**
19245             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
19246             *
19247             * @param nodeId the node ID
19248             * @param head the head
19249             * @param redirectTitle the redirect title
19250             * @param status the status
19251             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19252             * @return the first matching wiki page
19253             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
19254             * @throws SystemException if a system exception occurred
19255             */
19256            @Override
19257            public WikiPage findByN_H_R_NotS_First(long nodeId, boolean head,
19258                    String redirectTitle, int status, OrderByComparator orderByComparator)
19259                    throws NoSuchPageException, SystemException {
19260                    WikiPage wikiPage = fetchByN_H_R_NotS_First(nodeId, head,
19261                                    redirectTitle, status, orderByComparator);
19262    
19263                    if (wikiPage != null) {
19264                            return wikiPage;
19265                    }
19266    
19267                    StringBundler msg = new StringBundler(10);
19268    
19269                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
19270    
19271                    msg.append("nodeId=");
19272                    msg.append(nodeId);
19273    
19274                    msg.append(", head=");
19275                    msg.append(head);
19276    
19277                    msg.append(", redirectTitle=");
19278                    msg.append(redirectTitle);
19279    
19280                    msg.append(", status=");
19281                    msg.append(status);
19282    
19283                    msg.append(StringPool.CLOSE_CURLY_BRACE);
19284    
19285                    throw new NoSuchPageException(msg.toString());
19286            }
19287    
19288            /**
19289             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
19290             *
19291             * @param nodeId the node ID
19292             * @param head the head
19293             * @param redirectTitle the redirect title
19294             * @param status the status
19295             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19296             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
19297             * @throws SystemException if a system exception occurred
19298             */
19299            @Override
19300            public WikiPage fetchByN_H_R_NotS_First(long nodeId, boolean head,
19301                    String redirectTitle, int status, OrderByComparator orderByComparator)
19302                    throws SystemException {
19303                    List<WikiPage> list = findByN_H_R_NotS(nodeId, head, redirectTitle,
19304                                    status, 0, 1, orderByComparator);
19305    
19306                    if (!list.isEmpty()) {
19307                            return list.get(0);
19308                    }
19309    
19310                    return null;
19311            }
19312    
19313            /**
19314             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
19315             *
19316             * @param nodeId the node ID
19317             * @param head the head
19318             * @param redirectTitle the redirect title
19319             * @param status the status
19320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19321             * @return the last matching wiki page
19322             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
19323             * @throws SystemException if a system exception occurred
19324             */
19325            @Override
19326            public WikiPage findByN_H_R_NotS_Last(long nodeId, boolean head,
19327                    String redirectTitle, int status, OrderByComparator orderByComparator)
19328                    throws NoSuchPageException, SystemException {
19329                    WikiPage wikiPage = fetchByN_H_R_NotS_Last(nodeId, head, redirectTitle,
19330                                    status, orderByComparator);
19331    
19332                    if (wikiPage != null) {
19333                            return wikiPage;
19334                    }
19335    
19336                    StringBundler msg = new StringBundler(10);
19337    
19338                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
19339    
19340                    msg.append("nodeId=");
19341                    msg.append(nodeId);
19342    
19343                    msg.append(", head=");
19344                    msg.append(head);
19345    
19346                    msg.append(", redirectTitle=");
19347                    msg.append(redirectTitle);
19348    
19349                    msg.append(", status=");
19350                    msg.append(status);
19351    
19352                    msg.append(StringPool.CLOSE_CURLY_BRACE);
19353    
19354                    throw new NoSuchPageException(msg.toString());
19355            }
19356    
19357            /**
19358             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
19359             *
19360             * @param nodeId the node ID
19361             * @param head the head
19362             * @param redirectTitle the redirect title
19363             * @param status the status
19364             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19365             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
19366             * @throws SystemException if a system exception occurred
19367             */
19368            @Override
19369            public WikiPage fetchByN_H_R_NotS_Last(long nodeId, boolean head,
19370                    String redirectTitle, int status, OrderByComparator orderByComparator)
19371                    throws SystemException {
19372                    int count = countByN_H_R_NotS(nodeId, head, redirectTitle, status);
19373    
19374                    if (count == 0) {
19375                            return null;
19376                    }
19377    
19378                    List<WikiPage> list = findByN_H_R_NotS(nodeId, head, redirectTitle,
19379                                    status, count - 1, count, orderByComparator);
19380    
19381                    if (!list.isEmpty()) {
19382                            return list.get(0);
19383                    }
19384    
19385                    return null;
19386            }
19387    
19388            /**
19389             * 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;.
19390             *
19391             * @param pageId the primary key of the current wiki page
19392             * @param nodeId the node ID
19393             * @param head the head
19394             * @param redirectTitle the redirect title
19395             * @param status the status
19396             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19397             * @return the previous, current, and next wiki page
19398             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
19399             * @throws SystemException if a system exception occurred
19400             */
19401            @Override
19402            public WikiPage[] findByN_H_R_NotS_PrevAndNext(long pageId, long nodeId,
19403                    boolean head, String redirectTitle, int status,
19404                    OrderByComparator orderByComparator)
19405                    throws NoSuchPageException, SystemException {
19406                    WikiPage wikiPage = findByPrimaryKey(pageId);
19407    
19408                    Session session = null;
19409    
19410                    try {
19411                            session = openSession();
19412    
19413                            WikiPage[] array = new WikiPageImpl[3];
19414    
19415                            array[0] = getByN_H_R_NotS_PrevAndNext(session, wikiPage, nodeId,
19416                                            head, redirectTitle, status, orderByComparator, true);
19417    
19418                            array[1] = wikiPage;
19419    
19420                            array[2] = getByN_H_R_NotS_PrevAndNext(session, wikiPage, nodeId,
19421                                            head, redirectTitle, status, orderByComparator, false);
19422    
19423                            return array;
19424                    }
19425                    catch (Exception e) {
19426                            throw processException(e);
19427                    }
19428                    finally {
19429                            closeSession(session);
19430                    }
19431            }
19432    
19433            protected WikiPage getByN_H_R_NotS_PrevAndNext(Session session,
19434                    WikiPage wikiPage, long nodeId, boolean head, String redirectTitle,
19435                    int status, OrderByComparator orderByComparator, boolean previous) {
19436                    StringBundler query = null;
19437    
19438                    if (orderByComparator != null) {
19439                            query = new StringBundler(6 +
19440                                            (orderByComparator.getOrderByFields().length * 6));
19441                    }
19442                    else {
19443                            query = new StringBundler(3);
19444                    }
19445    
19446                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
19447    
19448                    query.append(_FINDER_COLUMN_N_H_R_NOTS_NODEID_2);
19449    
19450                    query.append(_FINDER_COLUMN_N_H_R_NOTS_HEAD_2);
19451    
19452                    boolean bindRedirectTitle = false;
19453    
19454                    if (redirectTitle == null) {
19455                            query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_1);
19456                    }
19457                    else if (redirectTitle.equals(StringPool.BLANK)) {
19458                            query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_3);
19459                    }
19460                    else {
19461                            bindRedirectTitle = true;
19462    
19463                            query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_2);
19464                    }
19465    
19466                    query.append(_FINDER_COLUMN_N_H_R_NOTS_STATUS_2);
19467    
19468                    if (orderByComparator != null) {
19469                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
19470    
19471                            if (orderByConditionFields.length > 0) {
19472                                    query.append(WHERE_AND);
19473                            }
19474    
19475                            for (int i = 0; i < orderByConditionFields.length; i++) {
19476                                    query.append(_ORDER_BY_ENTITY_ALIAS);
19477                                    query.append(orderByConditionFields[i]);
19478    
19479                                    if ((i + 1) < orderByConditionFields.length) {
19480                                            if (orderByComparator.isAscending() ^ previous) {
19481                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
19482                                            }
19483                                            else {
19484                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
19485                                            }
19486                                    }
19487                                    else {
19488                                            if (orderByComparator.isAscending() ^ previous) {
19489                                                    query.append(WHERE_GREATER_THAN);
19490                                            }
19491                                            else {
19492                                                    query.append(WHERE_LESSER_THAN);
19493                                            }
19494                                    }
19495                            }
19496    
19497                            query.append(ORDER_BY_CLAUSE);
19498    
19499                            String[] orderByFields = orderByComparator.getOrderByFields();
19500    
19501                            for (int i = 0; i < orderByFields.length; i++) {
19502                                    query.append(_ORDER_BY_ENTITY_ALIAS);
19503                                    query.append(orderByFields[i]);
19504    
19505                                    if ((i + 1) < orderByFields.length) {
19506                                            if (orderByComparator.isAscending() ^ previous) {
19507                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
19508                                            }
19509                                            else {
19510                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
19511                                            }
19512                                    }
19513                                    else {
19514                                            if (orderByComparator.isAscending() ^ previous) {
19515                                                    query.append(ORDER_BY_ASC);
19516                                            }
19517                                            else {
19518                                                    query.append(ORDER_BY_DESC);
19519                                            }
19520                                    }
19521                            }
19522                    }
19523                    else {
19524                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
19525                    }
19526    
19527                    String sql = query.toString();
19528    
19529                    Query q = session.createQuery(sql);
19530    
19531                    q.setFirstResult(0);
19532                    q.setMaxResults(2);
19533    
19534                    QueryPos qPos = QueryPos.getInstance(q);
19535    
19536                    qPos.add(nodeId);
19537    
19538                    qPos.add(head);
19539    
19540                    if (bindRedirectTitle) {
19541                            qPos.add(redirectTitle.toLowerCase());
19542                    }
19543    
19544                    qPos.add(status);
19545    
19546                    if (orderByComparator != null) {
19547                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
19548    
19549                            for (Object value : values) {
19550                                    qPos.add(value);
19551                            }
19552                    }
19553    
19554                    List<WikiPage> list = q.list();
19555    
19556                    if (list.size() == 2) {
19557                            return list.get(1);
19558                    }
19559                    else {
19560                            return null;
19561                    }
19562            }
19563    
19564            /**
19565             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63; from the database.
19566             *
19567             * @param nodeId the node ID
19568             * @param head the head
19569             * @param redirectTitle the redirect title
19570             * @param status the status
19571             * @throws SystemException if a system exception occurred
19572             */
19573            @Override
19574            public void removeByN_H_R_NotS(long nodeId, boolean head,
19575                    String redirectTitle, int status) throws SystemException {
19576                    for (WikiPage wikiPage : findByN_H_R_NotS(nodeId, head, redirectTitle,
19577                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
19578                            remove(wikiPage);
19579                    }
19580            }
19581    
19582            /**
19583             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
19584             *
19585             * @param nodeId the node ID
19586             * @param head the head
19587             * @param redirectTitle the redirect title
19588             * @param status the status
19589             * @return the number of matching wiki pages
19590             * @throws SystemException if a system exception occurred
19591             */
19592            @Override
19593            public int countByN_H_R_NotS(long nodeId, boolean head,
19594                    String redirectTitle, int status) throws SystemException {
19595                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_N_H_R_NOTS;
19596    
19597                    Object[] finderArgs = new Object[] { nodeId, head, redirectTitle, status };
19598    
19599                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
19600                                    this);
19601    
19602                    if (count == null) {
19603                            StringBundler query = new StringBundler(5);
19604    
19605                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
19606    
19607                            query.append(_FINDER_COLUMN_N_H_R_NOTS_NODEID_2);
19608    
19609                            query.append(_FINDER_COLUMN_N_H_R_NOTS_HEAD_2);
19610    
19611                            boolean bindRedirectTitle = false;
19612    
19613                            if (redirectTitle == null) {
19614                                    query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_1);
19615                            }
19616                            else if (redirectTitle.equals(StringPool.BLANK)) {
19617                                    query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_3);
19618                            }
19619                            else {
19620                                    bindRedirectTitle = true;
19621    
19622                                    query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_2);
19623                            }
19624    
19625                            query.append(_FINDER_COLUMN_N_H_R_NOTS_STATUS_2);
19626    
19627                            String sql = query.toString();
19628    
19629                            Session session = null;
19630    
19631                            try {
19632                                    session = openSession();
19633    
19634                                    Query q = session.createQuery(sql);
19635    
19636                                    QueryPos qPos = QueryPos.getInstance(q);
19637    
19638                                    qPos.add(nodeId);
19639    
19640                                    qPos.add(head);
19641    
19642                                    if (bindRedirectTitle) {
19643                                            qPos.add(redirectTitle.toLowerCase());
19644                                    }
19645    
19646                                    qPos.add(status);
19647    
19648                                    count = (Long)q.uniqueResult();
19649    
19650                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
19651                            }
19652                            catch (Exception e) {
19653                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19654    
19655                                    throw processException(e);
19656                            }
19657                            finally {
19658                                    closeSession(session);
19659                            }
19660                    }
19661    
19662                    return count.intValue();
19663            }
19664    
19665            private static final String _FINDER_COLUMN_N_H_R_NOTS_NODEID_2 = "wikiPage.nodeId = ? AND ";
19666            private static final String _FINDER_COLUMN_N_H_R_NOTS_HEAD_2 = "wikiPage.head = ? AND ";
19667            private static final String _FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_1 = "wikiPage.redirectTitle IS NULL AND ";
19668            private static final String _FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_2 = "lower(wikiPage.redirectTitle) = ? AND ";
19669            private static final String _FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_3 = "(wikiPage.redirectTitle IS NULL OR wikiPage.redirectTitle = '') AND ";
19670            private static final String _FINDER_COLUMN_N_H_R_NOTS_STATUS_2 = "wikiPage.status != ?";
19671            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_P_S =
19672                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
19673                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
19674                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H_P_S",
19675                            new String[] {
19676                                    Long.class.getName(), Long.class.getName(),
19677                                    Boolean.class.getName(), String.class.getName(),
19678                                    Integer.class.getName(),
19679                                    
19680                            Integer.class.getName(), Integer.class.getName(),
19681                                    OrderByComparator.class.getName()
19682                            });
19683            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S =
19684                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
19685                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
19686                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H_P_S",
19687                            new String[] {
19688                                    Long.class.getName(), Long.class.getName(),
19689                                    Boolean.class.getName(), String.class.getName(),
19690                                    Integer.class.getName()
19691                            },
19692                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
19693                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
19694                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
19695                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
19696                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
19697                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
19698                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
19699            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
19700                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
19701                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H_P_S",
19702                            new String[] {
19703                                    Long.class.getName(), Long.class.getName(),
19704                                    Boolean.class.getName(), String.class.getName(),
19705                                    Integer.class.getName()
19706                            });
19707    
19708            /**
19709             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
19710             *
19711             * @param groupId the group ID
19712             * @param nodeId the node ID
19713             * @param head the head
19714             * @param parentTitle the parent title
19715             * @param status the status
19716             * @return the matching wiki pages
19717             * @throws SystemException if a system exception occurred
19718             */
19719            @Override
19720            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
19721                    boolean head, String parentTitle, int status) throws SystemException {
19722                    return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
19723                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19724            }
19725    
19726            /**
19727             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
19728             *
19729             * <p>
19730             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
19731             * </p>
19732             *
19733             * @param groupId the group ID
19734             * @param nodeId the node ID
19735             * @param head the head
19736             * @param parentTitle the parent title
19737             * @param status the status
19738             * @param start the lower bound of the range of wiki pages
19739             * @param end the upper bound of the range of wiki pages (not inclusive)
19740             * @return the range of matching wiki pages
19741             * @throws SystemException if a system exception occurred
19742             */
19743            @Override
19744            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
19745                    boolean head, String parentTitle, int status, int start, int end)
19746                    throws SystemException {
19747                    return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
19748                            start, end, null);
19749            }
19750    
19751            /**
19752             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
19753             *
19754             * <p>
19755             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
19756             * </p>
19757             *
19758             * @param groupId the group ID
19759             * @param nodeId the node ID
19760             * @param head the head
19761             * @param parentTitle the parent title
19762             * @param status the status
19763             * @param start the lower bound of the range of wiki pages
19764             * @param end the upper bound of the range of wiki pages (not inclusive)
19765             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19766             * @return the ordered range of matching wiki pages
19767             * @throws SystemException if a system exception occurred
19768             */
19769            @Override
19770            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
19771                    boolean head, String parentTitle, int status, int start, int end,
19772                    OrderByComparator orderByComparator) throws SystemException {
19773                    boolean pagination = true;
19774                    FinderPath finderPath = null;
19775                    Object[] finderArgs = null;
19776    
19777                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
19778                                    (orderByComparator == null)) {
19779                            pagination = false;
19780                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S;
19781                            finderArgs = new Object[] { groupId, nodeId, head, parentTitle, status };
19782                    }
19783                    else {
19784                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_P_S;
19785                            finderArgs = new Object[] {
19786                                            groupId, nodeId, head, parentTitle, status,
19787                                            
19788                                            start, end, orderByComparator
19789                                    };
19790                    }
19791    
19792                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
19793                                    finderArgs, this);
19794    
19795                    if ((list != null) && !list.isEmpty()) {
19796                            for (WikiPage wikiPage : list) {
19797                                    if ((groupId != wikiPage.getGroupId()) ||
19798                                                    (nodeId != wikiPage.getNodeId()) ||
19799                                                    (head != wikiPage.getHead()) ||
19800                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle()) ||
19801                                                    (status != wikiPage.getStatus())) {
19802                                            list = null;
19803    
19804                                            break;
19805                                    }
19806                            }
19807                    }
19808    
19809                    if (list == null) {
19810                            StringBundler query = null;
19811    
19812                            if (orderByComparator != null) {
19813                                    query = new StringBundler(7 +
19814                                                    (orderByComparator.getOrderByFields().length * 3));
19815                            }
19816                            else {
19817                                    query = new StringBundler(7);
19818                            }
19819    
19820                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
19821    
19822                            query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
19823    
19824                            query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
19825    
19826                            query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
19827    
19828                            boolean bindParentTitle = false;
19829    
19830                            if (parentTitle == null) {
19831                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
19832                            }
19833                            else if (parentTitle.equals(StringPool.BLANK)) {
19834                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
19835                            }
19836                            else {
19837                                    bindParentTitle = true;
19838    
19839                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
19840                            }
19841    
19842                            query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
19843    
19844                            if (orderByComparator != null) {
19845                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19846                                            orderByComparator);
19847                            }
19848                            else
19849                             if (pagination) {
19850                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
19851                            }
19852    
19853                            String sql = query.toString();
19854    
19855                            Session session = null;
19856    
19857                            try {
19858                                    session = openSession();
19859    
19860                                    Query q = session.createQuery(sql);
19861    
19862                                    QueryPos qPos = QueryPos.getInstance(q);
19863    
19864                                    qPos.add(groupId);
19865    
19866                                    qPos.add(nodeId);
19867    
19868                                    qPos.add(head);
19869    
19870                                    if (bindParentTitle) {
19871                                            qPos.add(parentTitle.toLowerCase());
19872                                    }
19873    
19874                                    qPos.add(status);
19875    
19876                                    if (!pagination) {
19877                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
19878                                                            start, end, false);
19879    
19880                                            Collections.sort(list);
19881    
19882                                            list = new UnmodifiableList<WikiPage>(list);
19883                                    }
19884                                    else {
19885                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
19886                                                            start, end);
19887                                    }
19888    
19889                                    cacheResult(list);
19890    
19891                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
19892                            }
19893                            catch (Exception e) {
19894                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19895    
19896                                    throw processException(e);
19897                            }
19898                            finally {
19899                                    closeSession(session);
19900                            }
19901                    }
19902    
19903                    return list;
19904            }
19905    
19906            /**
19907             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
19908             *
19909             * @param groupId the group ID
19910             * @param nodeId the node ID
19911             * @param head the head
19912             * @param parentTitle the parent title
19913             * @param status the status
19914             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19915             * @return the first matching wiki page
19916             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
19917             * @throws SystemException if a system exception occurred
19918             */
19919            @Override
19920            public WikiPage findByG_N_H_P_S_First(long groupId, long nodeId,
19921                    boolean head, String parentTitle, int status,
19922                    OrderByComparator orderByComparator)
19923                    throws NoSuchPageException, SystemException {
19924                    WikiPage wikiPage = fetchByG_N_H_P_S_First(groupId, nodeId, head,
19925                                    parentTitle, status, orderByComparator);
19926    
19927                    if (wikiPage != null) {
19928                            return wikiPage;
19929                    }
19930    
19931                    StringBundler msg = new StringBundler(12);
19932    
19933                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
19934    
19935                    msg.append("groupId=");
19936                    msg.append(groupId);
19937    
19938                    msg.append(", nodeId=");
19939                    msg.append(nodeId);
19940    
19941                    msg.append(", head=");
19942                    msg.append(head);
19943    
19944                    msg.append(", parentTitle=");
19945                    msg.append(parentTitle);
19946    
19947                    msg.append(", status=");
19948                    msg.append(status);
19949    
19950                    msg.append(StringPool.CLOSE_CURLY_BRACE);
19951    
19952                    throw new NoSuchPageException(msg.toString());
19953            }
19954    
19955            /**
19956             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
19957             *
19958             * @param groupId the group ID
19959             * @param nodeId the node ID
19960             * @param head the head
19961             * @param parentTitle the parent title
19962             * @param status the status
19963             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19964             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
19965             * @throws SystemException if a system exception occurred
19966             */
19967            @Override
19968            public WikiPage fetchByG_N_H_P_S_First(long groupId, long nodeId,
19969                    boolean head, String parentTitle, int status,
19970                    OrderByComparator orderByComparator) throws SystemException {
19971                    List<WikiPage> list = findByG_N_H_P_S(groupId, nodeId, head,
19972                                    parentTitle, status, 0, 1, orderByComparator);
19973    
19974                    if (!list.isEmpty()) {
19975                            return list.get(0);
19976                    }
19977    
19978                    return null;
19979            }
19980    
19981            /**
19982             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
19983             *
19984             * @param groupId the group ID
19985             * @param nodeId the node ID
19986             * @param head the head
19987             * @param parentTitle the parent title
19988             * @param status the status
19989             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19990             * @return the last matching wiki page
19991             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
19992             * @throws SystemException if a system exception occurred
19993             */
19994            @Override
19995            public WikiPage findByG_N_H_P_S_Last(long groupId, long nodeId,
19996                    boolean head, String parentTitle, int status,
19997                    OrderByComparator orderByComparator)
19998                    throws NoSuchPageException, SystemException {
19999                    WikiPage wikiPage = fetchByG_N_H_P_S_Last(groupId, nodeId, head,
20000                                    parentTitle, status, orderByComparator);
20001    
20002                    if (wikiPage != null) {
20003                            return wikiPage;
20004                    }
20005    
20006                    StringBundler msg = new StringBundler(12);
20007    
20008                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
20009    
20010                    msg.append("groupId=");
20011                    msg.append(groupId);
20012    
20013                    msg.append(", nodeId=");
20014                    msg.append(nodeId);
20015    
20016                    msg.append(", head=");
20017                    msg.append(head);
20018    
20019                    msg.append(", parentTitle=");
20020                    msg.append(parentTitle);
20021    
20022                    msg.append(", status=");
20023                    msg.append(status);
20024    
20025                    msg.append(StringPool.CLOSE_CURLY_BRACE);
20026    
20027                    throw new NoSuchPageException(msg.toString());
20028            }
20029    
20030            /**
20031             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
20032             *
20033             * @param groupId the group ID
20034             * @param nodeId the node ID
20035             * @param head the head
20036             * @param parentTitle the parent title
20037             * @param status the status
20038             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
20039             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
20040             * @throws SystemException if a system exception occurred
20041             */
20042            @Override
20043            public WikiPage fetchByG_N_H_P_S_Last(long groupId, long nodeId,
20044                    boolean head, String parentTitle, int status,
20045                    OrderByComparator orderByComparator) throws SystemException {
20046                    int count = countByG_N_H_P_S(groupId, nodeId, head, parentTitle, status);
20047    
20048                    if (count == 0) {
20049                            return null;
20050                    }
20051    
20052                    List<WikiPage> list = findByG_N_H_P_S(groupId, nodeId, head,
20053                                    parentTitle, status, count - 1, count, orderByComparator);
20054    
20055                    if (!list.isEmpty()) {
20056                            return list.get(0);
20057                    }
20058    
20059                    return null;
20060            }
20061    
20062            /**
20063             * 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;.
20064             *
20065             * @param pageId the primary key of the current wiki page
20066             * @param groupId the group ID
20067             * @param nodeId the node ID
20068             * @param head the head
20069             * @param parentTitle the parent title
20070             * @param status the status
20071             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
20072             * @return the previous, current, and next wiki page
20073             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
20074             * @throws SystemException if a system exception occurred
20075             */
20076            @Override
20077            public WikiPage[] findByG_N_H_P_S_PrevAndNext(long pageId, long groupId,
20078                    long nodeId, boolean head, String parentTitle, int status,
20079                    OrderByComparator orderByComparator)
20080                    throws NoSuchPageException, SystemException {
20081                    WikiPage wikiPage = findByPrimaryKey(pageId);
20082    
20083                    Session session = null;
20084    
20085                    try {
20086                            session = openSession();
20087    
20088                            WikiPage[] array = new WikiPageImpl[3];
20089    
20090                            array[0] = getByG_N_H_P_S_PrevAndNext(session, wikiPage, groupId,
20091                                            nodeId, head, parentTitle, status, orderByComparator, true);
20092    
20093                            array[1] = wikiPage;
20094    
20095                            array[2] = getByG_N_H_P_S_PrevAndNext(session, wikiPage, groupId,
20096                                            nodeId, head, parentTitle, status, orderByComparator, false);
20097    
20098                            return array;
20099                    }
20100                    catch (Exception e) {
20101                            throw processException(e);
20102                    }
20103                    finally {
20104                            closeSession(session);
20105                    }
20106            }
20107    
20108            protected WikiPage getByG_N_H_P_S_PrevAndNext(Session session,
20109                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
20110                    String parentTitle, int status, OrderByComparator orderByComparator,
20111                    boolean previous) {
20112                    StringBundler query = null;
20113    
20114                    if (orderByComparator != null) {
20115                            query = new StringBundler(6 +
20116                                            (orderByComparator.getOrderByFields().length * 6));
20117                    }
20118                    else {
20119                            query = new StringBundler(3);
20120                    }
20121    
20122                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
20123    
20124                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
20125    
20126                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
20127    
20128                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
20129    
20130                    boolean bindParentTitle = false;
20131    
20132                    if (parentTitle == null) {
20133                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
20134                    }
20135                    else if (parentTitle.equals(StringPool.BLANK)) {
20136                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
20137                    }
20138                    else {
20139                            bindParentTitle = true;
20140    
20141                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
20142                    }
20143    
20144                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
20145    
20146                    if (orderByComparator != null) {
20147                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
20148    
20149                            if (orderByConditionFields.length > 0) {
20150                                    query.append(WHERE_AND);
20151                            }
20152    
20153                            for (int i = 0; i < orderByConditionFields.length; i++) {
20154                                    query.append(_ORDER_BY_ENTITY_ALIAS);
20155                                    query.append(orderByConditionFields[i]);
20156    
20157                                    if ((i + 1) < orderByConditionFields.length) {
20158                                            if (orderByComparator.isAscending() ^ previous) {
20159                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
20160                                            }
20161                                            else {
20162                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
20163                                            }
20164                                    }
20165                                    else {
20166                                            if (orderByComparator.isAscending() ^ previous) {
20167                                                    query.append(WHERE_GREATER_THAN);
20168                                            }
20169                                            else {
20170                                                    query.append(WHERE_LESSER_THAN);
20171                                            }
20172                                    }
20173                            }
20174    
20175                            query.append(ORDER_BY_CLAUSE);
20176    
20177                            String[] orderByFields = orderByComparator.getOrderByFields();
20178    
20179                            for (int i = 0; i < orderByFields.length; i++) {
20180                                    query.append(_ORDER_BY_ENTITY_ALIAS);
20181                                    query.append(orderByFields[i]);
20182    
20183                                    if ((i + 1) < orderByFields.length) {
20184                                            if (orderByComparator.isAscending() ^ previous) {
20185                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
20186                                            }
20187                                            else {
20188                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
20189                                            }
20190                                    }
20191                                    else {
20192                                            if (orderByComparator.isAscending() ^ previous) {
20193                                                    query.append(ORDER_BY_ASC);
20194                                            }
20195                                            else {
20196                                                    query.append(ORDER_BY_DESC);
20197                                            }
20198                                    }
20199                            }
20200                    }
20201                    else {
20202                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
20203                    }
20204    
20205                    String sql = query.toString();
20206    
20207                    Query q = session.createQuery(sql);
20208    
20209                    q.setFirstResult(0);
20210                    q.setMaxResults(2);
20211    
20212                    QueryPos qPos = QueryPos.getInstance(q);
20213    
20214                    qPos.add(groupId);
20215    
20216                    qPos.add(nodeId);
20217    
20218                    qPos.add(head);
20219    
20220                    if (bindParentTitle) {
20221                            qPos.add(parentTitle.toLowerCase());
20222                    }
20223    
20224                    qPos.add(status);
20225    
20226                    if (orderByComparator != null) {
20227                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
20228    
20229                            for (Object value : values) {
20230                                    qPos.add(value);
20231                            }
20232                    }
20233    
20234                    List<WikiPage> list = q.list();
20235    
20236                    if (list.size() == 2) {
20237                            return list.get(1);
20238                    }
20239                    else {
20240                            return null;
20241                    }
20242            }
20243    
20244            /**
20245             * 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;.
20246             *
20247             * @param groupId the group ID
20248             * @param nodeId the node ID
20249             * @param head the head
20250             * @param parentTitle the parent title
20251             * @param status the status
20252             * @return the matching wiki pages that the user has permission to view
20253             * @throws SystemException if a system exception occurred
20254             */
20255            @Override
20256            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
20257                    boolean head, String parentTitle, int status) throws SystemException {
20258                    return filterFindByG_N_H_P_S(groupId, nodeId, head, parentTitle,
20259                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
20260            }
20261    
20262            /**
20263             * 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;.
20264             *
20265             * <p>
20266             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
20267             * </p>
20268             *
20269             * @param groupId the group ID
20270             * @param nodeId the node ID
20271             * @param head the head
20272             * @param parentTitle the parent title
20273             * @param status the status
20274             * @param start the lower bound of the range of wiki pages
20275             * @param end the upper bound of the range of wiki pages (not inclusive)
20276             * @return the range of matching wiki pages that the user has permission to view
20277             * @throws SystemException if a system exception occurred
20278             */
20279            @Override
20280            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
20281                    boolean head, String parentTitle, int status, int start, int end)
20282                    throws SystemException {
20283                    return filterFindByG_N_H_P_S(groupId, nodeId, head, parentTitle,
20284                            status, start, end, null);
20285            }
20286    
20287            /**
20288             * 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;.
20289             *
20290             * <p>
20291             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
20292             * </p>
20293             *
20294             * @param groupId the group ID
20295             * @param nodeId the node ID
20296             * @param head the head
20297             * @param parentTitle the parent title
20298             * @param status the status
20299             * @param start the lower bound of the range of wiki pages
20300             * @param end the upper bound of the range of wiki pages (not inclusive)
20301             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20302             * @return the ordered range of matching wiki pages that the user has permission to view
20303             * @throws SystemException if a system exception occurred
20304             */
20305            @Override
20306            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
20307                    boolean head, String parentTitle, int status, int start, int end,
20308                    OrderByComparator orderByComparator) throws SystemException {
20309                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
20310                            return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
20311                                    start, end, orderByComparator);
20312                    }
20313    
20314                    StringBundler query = null;
20315    
20316                    if (orderByComparator != null) {
20317                            query = new StringBundler(7 +
20318                                            (orderByComparator.getOrderByFields().length * 3));
20319                    }
20320                    else {
20321                            query = new StringBundler(7);
20322                    }
20323    
20324                    if (getDB().isSupportsInlineDistinct()) {
20325                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
20326                    }
20327                    else {
20328                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
20329                    }
20330    
20331                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
20332    
20333                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
20334    
20335                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
20336    
20337                    boolean bindParentTitle = false;
20338    
20339                    if (parentTitle == null) {
20340                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
20341                    }
20342                    else if (parentTitle.equals(StringPool.BLANK)) {
20343                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
20344                    }
20345                    else {
20346                            bindParentTitle = true;
20347    
20348                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
20349                    }
20350    
20351                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
20352    
20353                    if (!getDB().isSupportsInlineDistinct()) {
20354                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
20355                    }
20356    
20357                    if (orderByComparator != null) {
20358                            if (getDB().isSupportsInlineDistinct()) {
20359                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
20360                                            orderByComparator, true);
20361                            }
20362                            else {
20363                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
20364                                            orderByComparator, true);
20365                            }
20366                    }
20367                    else {
20368                            if (getDB().isSupportsInlineDistinct()) {
20369                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
20370                            }
20371                            else {
20372                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
20373                            }
20374                    }
20375    
20376                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
20377                                    WikiPage.class.getName(),
20378                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
20379    
20380                    Session session = null;
20381    
20382                    try {
20383                            session = openSession();
20384    
20385                            SQLQuery q = session.createSQLQuery(sql);
20386    
20387                            if (getDB().isSupportsInlineDistinct()) {
20388                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
20389                            }
20390                            else {
20391                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
20392                            }
20393    
20394                            QueryPos qPos = QueryPos.getInstance(q);
20395    
20396                            qPos.add(groupId);
20397    
20398                            qPos.add(nodeId);
20399    
20400                            qPos.add(head);
20401    
20402                            if (bindParentTitle) {
20403                                    qPos.add(parentTitle.toLowerCase());
20404                            }
20405    
20406                            qPos.add(status);
20407    
20408                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
20409                    }
20410                    catch (Exception e) {
20411                            throw processException(e);
20412                    }
20413                    finally {
20414                            closeSession(session);
20415                    }
20416            }
20417    
20418            /**
20419             * 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;.
20420             *
20421             * @param pageId the primary key of the current wiki page
20422             * @param groupId the group ID
20423             * @param nodeId the node ID
20424             * @param head the head
20425             * @param parentTitle the parent title
20426             * @param status the status
20427             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
20428             * @return the previous, current, and next wiki page
20429             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
20430             * @throws SystemException if a system exception occurred
20431             */
20432            @Override
20433            public WikiPage[] filterFindByG_N_H_P_S_PrevAndNext(long pageId,
20434                    long groupId, long nodeId, boolean head, String parentTitle,
20435                    int status, OrderByComparator orderByComparator)
20436                    throws NoSuchPageException, SystemException {
20437                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
20438                            return findByG_N_H_P_S_PrevAndNext(pageId, groupId, nodeId, head,
20439                                    parentTitle, status, orderByComparator);
20440                    }
20441    
20442                    WikiPage wikiPage = findByPrimaryKey(pageId);
20443    
20444                    Session session = null;
20445    
20446                    try {
20447                            session = openSession();
20448    
20449                            WikiPage[] array = new WikiPageImpl[3];
20450    
20451                            array[0] = filterGetByG_N_H_P_S_PrevAndNext(session, wikiPage,
20452                                            groupId, nodeId, head, parentTitle, status,
20453                                            orderByComparator, true);
20454    
20455                            array[1] = wikiPage;
20456    
20457                            array[2] = filterGetByG_N_H_P_S_PrevAndNext(session, wikiPage,
20458                                            groupId, nodeId, head, parentTitle, status,
20459                                            orderByComparator, false);
20460    
20461                            return array;
20462                    }
20463                    catch (Exception e) {
20464                            throw processException(e);
20465                    }
20466                    finally {
20467                            closeSession(session);
20468                    }
20469            }
20470    
20471            protected WikiPage filterGetByG_N_H_P_S_PrevAndNext(Session session,
20472                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
20473                    String parentTitle, int status, OrderByComparator orderByComparator,
20474                    boolean previous) {
20475                    StringBundler query = null;
20476    
20477                    if (orderByComparator != null) {
20478                            query = new StringBundler(6 +
20479                                            (orderByComparator.getOrderByFields().length * 6));
20480                    }
20481                    else {
20482                            query = new StringBundler(3);
20483                    }
20484    
20485                    if (getDB().isSupportsInlineDistinct()) {
20486                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
20487                    }
20488                    else {
20489                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
20490                    }
20491    
20492                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
20493    
20494                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
20495    
20496                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
20497    
20498                    boolean bindParentTitle = false;
20499    
20500                    if (parentTitle == null) {
20501                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
20502                    }
20503                    else if (parentTitle.equals(StringPool.BLANK)) {
20504                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
20505                    }
20506                    else {
20507                            bindParentTitle = true;
20508    
20509                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
20510                    }
20511    
20512                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
20513    
20514                    if (!getDB().isSupportsInlineDistinct()) {
20515                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
20516                    }
20517    
20518                    if (orderByComparator != null) {
20519                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
20520    
20521                            if (orderByConditionFields.length > 0) {
20522                                    query.append(WHERE_AND);
20523                            }
20524    
20525                            for (int i = 0; i < orderByConditionFields.length; i++) {
20526                                    if (getDB().isSupportsInlineDistinct()) {
20527                                            query.append(_ORDER_BY_ENTITY_ALIAS);
20528                                    }
20529                                    else {
20530                                            query.append(_ORDER_BY_ENTITY_TABLE);
20531                                    }
20532    
20533                                    query.append(orderByConditionFields[i]);
20534    
20535                                    if ((i + 1) < orderByConditionFields.length) {
20536                                            if (orderByComparator.isAscending() ^ previous) {
20537                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
20538                                            }
20539                                            else {
20540                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
20541                                            }
20542                                    }
20543                                    else {
20544                                            if (orderByComparator.isAscending() ^ previous) {
20545                                                    query.append(WHERE_GREATER_THAN);
20546                                            }
20547                                            else {
20548                                                    query.append(WHERE_LESSER_THAN);
20549                                            }
20550                                    }
20551                            }
20552    
20553                            query.append(ORDER_BY_CLAUSE);
20554    
20555                            String[] orderByFields = orderByComparator.getOrderByFields();
20556    
20557                            for (int i = 0; i < orderByFields.length; i++) {
20558                                    if (getDB().isSupportsInlineDistinct()) {
20559                                            query.append(_ORDER_BY_ENTITY_ALIAS);
20560                                    }
20561                                    else {
20562                                            query.append(_ORDER_BY_ENTITY_TABLE);
20563                                    }
20564    
20565                                    query.append(orderByFields[i]);
20566    
20567                                    if ((i + 1) < orderByFields.length) {
20568                                            if (orderByComparator.isAscending() ^ previous) {
20569                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
20570                                            }
20571                                            else {
20572                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
20573                                            }
20574                                    }
20575                                    else {
20576                                            if (orderByComparator.isAscending() ^ previous) {
20577                                                    query.append(ORDER_BY_ASC);
20578                                            }
20579                                            else {
20580                                                    query.append(ORDER_BY_DESC);
20581                                            }
20582                                    }
20583                            }
20584                    }
20585                    else {
20586                            if (getDB().isSupportsInlineDistinct()) {
20587                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
20588                            }
20589                            else {
20590                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
20591                            }
20592                    }
20593    
20594                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
20595                                    WikiPage.class.getName(),
20596                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
20597    
20598                    SQLQuery q = session.createSQLQuery(sql);
20599    
20600                    q.setFirstResult(0);
20601                    q.setMaxResults(2);
20602    
20603                    if (getDB().isSupportsInlineDistinct()) {
20604                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
20605                    }
20606                    else {
20607                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
20608                    }
20609    
20610                    QueryPos qPos = QueryPos.getInstance(q);
20611    
20612                    qPos.add(groupId);
20613    
20614                    qPos.add(nodeId);
20615    
20616                    qPos.add(head);
20617    
20618                    if (bindParentTitle) {
20619                            qPos.add(parentTitle.toLowerCase());
20620                    }
20621    
20622                    qPos.add(status);
20623    
20624                    if (orderByComparator != null) {
20625                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
20626    
20627                            for (Object value : values) {
20628                                    qPos.add(value);
20629                            }
20630                    }
20631    
20632                    List<WikiPage> list = q.list();
20633    
20634                    if (list.size() == 2) {
20635                            return list.get(1);
20636                    }
20637                    else {
20638                            return null;
20639                    }
20640            }
20641    
20642            /**
20643             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63; from the database.
20644             *
20645             * @param groupId the group ID
20646             * @param nodeId the node ID
20647             * @param head the head
20648             * @param parentTitle the parent title
20649             * @param status the status
20650             * @throws SystemException if a system exception occurred
20651             */
20652            @Override
20653            public void removeByG_N_H_P_S(long groupId, long nodeId, boolean head,
20654                    String parentTitle, int status) throws SystemException {
20655                    for (WikiPage wikiPage : findByG_N_H_P_S(groupId, nodeId, head,
20656                                    parentTitle, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
20657                            remove(wikiPage);
20658                    }
20659            }
20660    
20661            /**
20662             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
20663             *
20664             * @param groupId the group ID
20665             * @param nodeId the node ID
20666             * @param head the head
20667             * @param parentTitle the parent title
20668             * @param status the status
20669             * @return the number of matching wiki pages
20670             * @throws SystemException if a system exception occurred
20671             */
20672            @Override
20673            public int countByG_N_H_P_S(long groupId, long nodeId, boolean head,
20674                    String parentTitle, int status) throws SystemException {
20675                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H_P_S;
20676    
20677                    Object[] finderArgs = new Object[] {
20678                                    groupId, nodeId, head, parentTitle, status
20679                            };
20680    
20681                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
20682                                    this);
20683    
20684                    if (count == null) {
20685                            StringBundler query = new StringBundler(6);
20686    
20687                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
20688    
20689                            query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
20690    
20691                            query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
20692    
20693                            query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
20694    
20695                            boolean bindParentTitle = false;
20696    
20697                            if (parentTitle == null) {
20698                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
20699                            }
20700                            else if (parentTitle.equals(StringPool.BLANK)) {
20701                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
20702                            }
20703                            else {
20704                                    bindParentTitle = true;
20705    
20706                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
20707                            }
20708    
20709                            query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
20710    
20711                            String sql = query.toString();
20712    
20713                            Session session = null;
20714    
20715                            try {
20716                                    session = openSession();
20717    
20718                                    Query q = session.createQuery(sql);
20719    
20720                                    QueryPos qPos = QueryPos.getInstance(q);
20721    
20722                                    qPos.add(groupId);
20723    
20724                                    qPos.add(nodeId);
20725    
20726                                    qPos.add(head);
20727    
20728                                    if (bindParentTitle) {
20729                                            qPos.add(parentTitle.toLowerCase());
20730                                    }
20731    
20732                                    qPos.add(status);
20733    
20734                                    count = (Long)q.uniqueResult();
20735    
20736                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
20737                            }
20738                            catch (Exception e) {
20739                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
20740    
20741                                    throw processException(e);
20742                            }
20743                            finally {
20744                                    closeSession(session);
20745                            }
20746                    }
20747    
20748                    return count.intValue();
20749            }
20750    
20751            /**
20752             * 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;.
20753             *
20754             * @param groupId the group ID
20755             * @param nodeId the node ID
20756             * @param head the head
20757             * @param parentTitle the parent title
20758             * @param status the status
20759             * @return the number of matching wiki pages that the user has permission to view
20760             * @throws SystemException if a system exception occurred
20761             */
20762            @Override
20763            public int filterCountByG_N_H_P_S(long groupId, long nodeId, boolean head,
20764                    String parentTitle, int status) throws SystemException {
20765                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
20766                            return countByG_N_H_P_S(groupId, nodeId, head, parentTitle, status);
20767                    }
20768    
20769                    StringBundler query = new StringBundler(6);
20770    
20771                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
20772    
20773                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
20774    
20775                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
20776    
20777                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
20778    
20779                    boolean bindParentTitle = false;
20780    
20781                    if (parentTitle == null) {
20782                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
20783                    }
20784                    else if (parentTitle.equals(StringPool.BLANK)) {
20785                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
20786                    }
20787                    else {
20788                            bindParentTitle = true;
20789    
20790                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
20791                    }
20792    
20793                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
20794    
20795                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
20796                                    WikiPage.class.getName(),
20797                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
20798    
20799                    Session session = null;
20800    
20801                    try {
20802                            session = openSession();
20803    
20804                            SQLQuery q = session.createSQLQuery(sql);
20805    
20806                            q.addScalar(COUNT_COLUMN_NAME,
20807                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
20808    
20809                            QueryPos qPos = QueryPos.getInstance(q);
20810    
20811                            qPos.add(groupId);
20812    
20813                            qPos.add(nodeId);
20814    
20815                            qPos.add(head);
20816    
20817                            if (bindParentTitle) {
20818                                    qPos.add(parentTitle.toLowerCase());
20819                            }
20820    
20821                            qPos.add(status);
20822    
20823                            Long count = (Long)q.uniqueResult();
20824    
20825                            return count.intValue();
20826                    }
20827                    catch (Exception e) {
20828                            throw processException(e);
20829                    }
20830                    finally {
20831                            closeSession(session);
20832                    }
20833            }
20834    
20835            private static final String _FINDER_COLUMN_G_N_H_P_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
20836            private static final String _FINDER_COLUMN_G_N_H_P_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
20837            private static final String _FINDER_COLUMN_G_N_H_P_S_HEAD_2 = "wikiPage.head = ? AND ";
20838            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL AND ";
20839            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ? AND ";
20840            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '') AND ";
20841            private static final String _FINDER_COLUMN_G_N_H_P_S_STATUS_2 = "wikiPage.status = ?";
20842    
20843            public WikiPagePersistenceImpl() {
20844                    setModelClass(WikiPage.class);
20845            }
20846    
20847            /**
20848             * Caches the wiki page in the entity cache if it is enabled.
20849             *
20850             * @param wikiPage the wiki page
20851             */
20852            @Override
20853            public void cacheResult(WikiPage wikiPage) {
20854                    EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
20855                            WikiPageImpl.class, wikiPage.getPrimaryKey(), wikiPage);
20856    
20857                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
20858                            new Object[] { wikiPage.getUuid(), wikiPage.getGroupId() }, wikiPage);
20859    
20860                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
20861                            new Object[] {
20862                                    wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
20863                                    wikiPage.getVersion()
20864                            }, wikiPage);
20865    
20866                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
20867                            new Object[] {
20868                                    wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion()
20869                            }, wikiPage);
20870    
20871                    wikiPage.resetOriginalValues();
20872            }
20873    
20874            /**
20875             * Caches the wiki pages in the entity cache if it is enabled.
20876             *
20877             * @param wikiPages the wiki pages
20878             */
20879            @Override
20880            public void cacheResult(List<WikiPage> wikiPages) {
20881                    for (WikiPage wikiPage : wikiPages) {
20882                            if (EntityCacheUtil.getResult(
20883                                                    WikiPageModelImpl.ENTITY_CACHE_ENABLED,
20884                                                    WikiPageImpl.class, wikiPage.getPrimaryKey()) == null) {
20885                                    cacheResult(wikiPage);
20886                            }
20887                            else {
20888                                    wikiPage.resetOriginalValues();
20889                            }
20890                    }
20891            }
20892    
20893            /**
20894             * Clears the cache for all wiki pages.
20895             *
20896             * <p>
20897             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
20898             * </p>
20899             */
20900            @Override
20901            public void clearCache() {
20902                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
20903                            CacheRegistryUtil.clear(WikiPageImpl.class.getName());
20904                    }
20905    
20906                    EntityCacheUtil.clearCache(WikiPageImpl.class.getName());
20907    
20908                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
20909                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
20910                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
20911            }
20912    
20913            /**
20914             * Clears the cache for the wiki page.
20915             *
20916             * <p>
20917             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
20918             * </p>
20919             */
20920            @Override
20921            public void clearCache(WikiPage wikiPage) {
20922                    EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
20923                            WikiPageImpl.class, wikiPage.getPrimaryKey());
20924    
20925                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
20926                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
20927    
20928                    clearUniqueFindersCache(wikiPage);
20929            }
20930    
20931            @Override
20932            public void clearCache(List<WikiPage> wikiPages) {
20933                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
20934                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
20935    
20936                    for (WikiPage wikiPage : wikiPages) {
20937                            EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
20938                                    WikiPageImpl.class, wikiPage.getPrimaryKey());
20939    
20940                            clearUniqueFindersCache(wikiPage);
20941                    }
20942            }
20943    
20944            protected void cacheUniqueFindersCache(WikiPage wikiPage) {
20945                    if (wikiPage.isNew()) {
20946                            Object[] args = new Object[] {
20947                                            wikiPage.getUuid(), wikiPage.getGroupId()
20948                                    };
20949    
20950                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
20951                                    Long.valueOf(1));
20952                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
20953                                    wikiPage);
20954    
20955                            args = new Object[] {
20956                                            wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
20957                                            wikiPage.getVersion()
20958                                    };
20959    
20960                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_N_V, args,
20961                                    Long.valueOf(1));
20962                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V, args, wikiPage);
20963    
20964                            args = new Object[] {
20965                                            wikiPage.getNodeId(), wikiPage.getTitle(),
20966                                            wikiPage.getVersion()
20967                                    };
20968    
20969                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T_V, args,
20970                                    Long.valueOf(1));
20971                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V, args, wikiPage);
20972                    }
20973                    else {
20974                            WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
20975    
20976                            if ((wikiPageModelImpl.getColumnBitmask() &
20977                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
20978                                    Object[] args = new Object[] {
20979                                                    wikiPage.getUuid(), wikiPage.getGroupId()
20980                                            };
20981    
20982                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
20983                                            Long.valueOf(1));
20984                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
20985                                            wikiPage);
20986                            }
20987    
20988                            if ((wikiPageModelImpl.getColumnBitmask() &
20989                                            FINDER_PATH_FETCH_BY_R_N_V.getColumnBitmask()) != 0) {
20990                                    Object[] args = new Object[] {
20991                                                    wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
20992                                                    wikiPage.getVersion()
20993                                            };
20994    
20995                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_N_V, args,
20996                                            Long.valueOf(1));
20997                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V, args,
20998                                            wikiPage);
20999                            }
21000    
21001                            if ((wikiPageModelImpl.getColumnBitmask() &
21002                                            FINDER_PATH_FETCH_BY_N_T_V.getColumnBitmask()) != 0) {
21003                                    Object[] args = new Object[] {
21004                                                    wikiPage.getNodeId(), wikiPage.getTitle(),
21005                                                    wikiPage.getVersion()
21006                                            };
21007    
21008                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T_V, args,
21009                                            Long.valueOf(1));
21010                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V, args,
21011                                            wikiPage);
21012                            }
21013                    }
21014            }
21015    
21016            protected void clearUniqueFindersCache(WikiPage wikiPage) {
21017                    WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
21018    
21019                    Object[] args = new Object[] { wikiPage.getUuid(), wikiPage.getGroupId() };
21020    
21021                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
21022                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
21023    
21024                    if ((wikiPageModelImpl.getColumnBitmask() &
21025                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
21026                            args = new Object[] {
21027                                            wikiPageModelImpl.getOriginalUuid(),
21028                                            wikiPageModelImpl.getOriginalGroupId()
21029                                    };
21030    
21031                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
21032                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
21033                    }
21034    
21035                    args = new Object[] {
21036                                    wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
21037                                    wikiPage.getVersion()
21038                            };
21039    
21040                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_V, args);
21041                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V, args);
21042    
21043                    if ((wikiPageModelImpl.getColumnBitmask() &
21044                                    FINDER_PATH_FETCH_BY_R_N_V.getColumnBitmask()) != 0) {
21045                            args = new Object[] {
21046                                            wikiPageModelImpl.getOriginalResourcePrimKey(),
21047                                            wikiPageModelImpl.getOriginalNodeId(),
21048                                            wikiPageModelImpl.getOriginalVersion()
21049                                    };
21050    
21051                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_V, args);
21052                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V, args);
21053                    }
21054    
21055                    args = new Object[] {
21056                                    wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion()
21057                            };
21058    
21059                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_V, args);
21060                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V, args);
21061    
21062                    if ((wikiPageModelImpl.getColumnBitmask() &
21063                                    FINDER_PATH_FETCH_BY_N_T_V.getColumnBitmask()) != 0) {
21064                            args = new Object[] {
21065                                            wikiPageModelImpl.getOriginalNodeId(),
21066                                            wikiPageModelImpl.getOriginalTitle(),
21067                                            wikiPageModelImpl.getOriginalVersion()
21068                                    };
21069    
21070                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_V, args);
21071                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V, args);
21072                    }
21073            }
21074    
21075            /**
21076             * Creates a new wiki page with the primary key. Does not add the wiki page to the database.
21077             *
21078             * @param pageId the primary key for the new wiki page
21079             * @return the new wiki page
21080             */
21081            @Override
21082            public WikiPage create(long pageId) {
21083                    WikiPage wikiPage = new WikiPageImpl();
21084    
21085                    wikiPage.setNew(true);
21086                    wikiPage.setPrimaryKey(pageId);
21087    
21088                    String uuid = PortalUUIDUtil.generate();
21089    
21090                    wikiPage.setUuid(uuid);
21091    
21092                    return wikiPage;
21093            }
21094    
21095            /**
21096             * Removes the wiki page with the primary key from the database. Also notifies the appropriate model listeners.
21097             *
21098             * @param pageId the primary key of the wiki page
21099             * @return the wiki page that was removed
21100             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
21101             * @throws SystemException if a system exception occurred
21102             */
21103            @Override
21104            public WikiPage remove(long pageId)
21105                    throws NoSuchPageException, SystemException {
21106                    return remove((Serializable)pageId);
21107            }
21108    
21109            /**
21110             * Removes the wiki page with the primary key from the database. Also notifies the appropriate model listeners.
21111             *
21112             * @param primaryKey the primary key of the wiki page
21113             * @return the wiki page that was removed
21114             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
21115             * @throws SystemException if a system exception occurred
21116             */
21117            @Override
21118            public WikiPage remove(Serializable primaryKey)
21119                    throws NoSuchPageException, SystemException {
21120                    Session session = null;
21121    
21122                    try {
21123                            session = openSession();
21124    
21125                            WikiPage wikiPage = (WikiPage)session.get(WikiPageImpl.class,
21126                                            primaryKey);
21127    
21128                            if (wikiPage == null) {
21129                                    if (_log.isWarnEnabled()) {
21130                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
21131                                    }
21132    
21133                                    throw new NoSuchPageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
21134                                            primaryKey);
21135                            }
21136    
21137                            return remove(wikiPage);
21138                    }
21139                    catch (NoSuchPageException nsee) {
21140                            throw nsee;
21141                    }
21142                    catch (Exception e) {
21143                            throw processException(e);
21144                    }
21145                    finally {
21146                            closeSession(session);
21147                    }
21148            }
21149    
21150            @Override
21151            protected WikiPage removeImpl(WikiPage wikiPage) throws SystemException {
21152                    wikiPage = toUnwrappedModel(wikiPage);
21153    
21154                    Session session = null;
21155    
21156                    try {
21157                            session = openSession();
21158    
21159                            if (!session.contains(wikiPage)) {
21160                                    wikiPage = (WikiPage)session.get(WikiPageImpl.class,
21161                                                    wikiPage.getPrimaryKeyObj());
21162                            }
21163    
21164                            if (wikiPage != null) {
21165                                    session.delete(wikiPage);
21166                            }
21167                    }
21168                    catch (Exception e) {
21169                            throw processException(e);
21170                    }
21171                    finally {
21172                            closeSession(session);
21173                    }
21174    
21175                    if (wikiPage != null) {
21176                            clearCache(wikiPage);
21177                    }
21178    
21179                    return wikiPage;
21180            }
21181    
21182            @Override
21183            public WikiPage updateImpl(com.liferay.portlet.wiki.model.WikiPage wikiPage)
21184                    throws SystemException {
21185                    wikiPage = toUnwrappedModel(wikiPage);
21186    
21187                    boolean isNew = wikiPage.isNew();
21188    
21189                    WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
21190    
21191                    if (Validator.isNull(wikiPage.getUuid())) {
21192                            String uuid = PortalUUIDUtil.generate();
21193    
21194                            wikiPage.setUuid(uuid);
21195                    }
21196    
21197                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
21198    
21199                    if (userId > 0) {
21200                            long companyId = wikiPage.getCompanyId();
21201    
21202                            long groupId = wikiPage.getGroupId();
21203    
21204                            long pageId = 0;
21205    
21206                            if (!isNew) {
21207                                    pageId = wikiPage.getPrimaryKey();
21208                            }
21209    
21210                            try {
21211                                    wikiPage.setTitle(SanitizerUtil.sanitize(companyId, groupId,
21212                                                    userId,
21213                                                    com.liferay.portlet.wiki.model.WikiPage.class.getName(),
21214                                                    pageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
21215                                                    wikiPage.getTitle(), null));
21216                            }
21217                            catch (SanitizerException se) {
21218                                    throw new SystemException(se);
21219                            }
21220                    }
21221    
21222                    Session session = null;
21223    
21224                    try {
21225                            session = openSession();
21226    
21227                            if (wikiPage.isNew()) {
21228                                    session.save(wikiPage);
21229    
21230                                    wikiPage.setNew(false);
21231                            }
21232                            else {
21233                                    session.merge(wikiPage);
21234                            }
21235                    }
21236                    catch (Exception e) {
21237                            throw processException(e);
21238                    }
21239                    finally {
21240                            closeSession(session);
21241                    }
21242    
21243                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
21244    
21245                    if (isNew || !WikiPageModelImpl.COLUMN_BITMASK_ENABLED) {
21246                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
21247                    }
21248    
21249                    else {
21250                            if ((wikiPageModelImpl.getColumnBitmask() &
21251                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
21252                                    Object[] args = new Object[] { wikiPageModelImpl.getOriginalUuid() };
21253    
21254                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
21255                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
21256                                            args);
21257    
21258                                    args = new Object[] { wikiPageModelImpl.getUuid() };
21259    
21260                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
21261                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
21262                                            args);
21263                            }
21264    
21265                            if ((wikiPageModelImpl.getColumnBitmask() &
21266                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
21267                                    Object[] args = new Object[] {
21268                                                    wikiPageModelImpl.getOriginalUuid(),
21269                                                    wikiPageModelImpl.getOriginalCompanyId()
21270                                            };
21271    
21272                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
21273                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
21274                                            args);
21275    
21276                                    args = new Object[] {
21277                                                    wikiPageModelImpl.getUuid(),
21278                                                    wikiPageModelImpl.getCompanyId()
21279                                            };
21280    
21281                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
21282                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
21283                                            args);
21284                            }
21285    
21286                            if ((wikiPageModelImpl.getColumnBitmask() &
21287                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY.getColumnBitmask()) != 0) {
21288                                    Object[] args = new Object[] {
21289                                                    wikiPageModelImpl.getOriginalResourcePrimKey()
21290                                            };
21291    
21292                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEPRIMKEY,
21293                                            args);
21294                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY,
21295                                            args);
21296    
21297                                    args = new Object[] { wikiPageModelImpl.getResourcePrimKey() };
21298    
21299                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEPRIMKEY,
21300                                            args);
21301                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY,
21302                                            args);
21303                            }
21304    
21305                            if ((wikiPageModelImpl.getColumnBitmask() &
21306                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID.getColumnBitmask()) != 0) {
21307                                    Object[] args = new Object[] {
21308                                                    wikiPageModelImpl.getOriginalNodeId()
21309                                            };
21310    
21311                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NODEID, args);
21312                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID,
21313                                            args);
21314    
21315                                    args = new Object[] { wikiPageModelImpl.getNodeId() };
21316    
21317                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NODEID, args);
21318                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID,
21319                                            args);
21320                            }
21321    
21322                            if ((wikiPageModelImpl.getColumnBitmask() &
21323                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT.getColumnBitmask()) != 0) {
21324                                    Object[] args = new Object[] {
21325                                                    wikiPageModelImpl.getOriginalFormat()
21326                                            };
21327    
21328                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FORMAT, args);
21329                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT,
21330                                            args);
21331    
21332                                    args = new Object[] { wikiPageModelImpl.getFormat() };
21333    
21334                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FORMAT, args);
21335                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT,
21336                                            args);
21337                            }
21338    
21339                            if ((wikiPageModelImpl.getColumnBitmask() &
21340                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N.getColumnBitmask()) != 0) {
21341                                    Object[] args = new Object[] {
21342                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
21343                                                    wikiPageModelImpl.getOriginalNodeId()
21344                                            };
21345    
21346                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N, args);
21347                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N,
21348                                            args);
21349    
21350                                    args = new Object[] {
21351                                                    wikiPageModelImpl.getResourcePrimKey(),
21352                                                    wikiPageModelImpl.getNodeId()
21353                                            };
21354    
21355                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N, args);
21356                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N,
21357                                            args);
21358                            }
21359    
21360                            if ((wikiPageModelImpl.getColumnBitmask() &
21361                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S.getColumnBitmask()) != 0) {
21362                                    Object[] args = new Object[] {
21363                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
21364                                                    wikiPageModelImpl.getOriginalStatus()
21365                                            };
21366    
21367                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
21368                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
21369                                            args);
21370    
21371                                    args = new Object[] {
21372                                                    wikiPageModelImpl.getResourcePrimKey(),
21373                                                    wikiPageModelImpl.getStatus()
21374                                            };
21375    
21376                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
21377                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
21378                                            args);
21379                            }
21380    
21381                            if ((wikiPageModelImpl.getColumnBitmask() &
21382                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T.getColumnBitmask()) != 0) {
21383                                    Object[] args = new Object[] {
21384                                                    wikiPageModelImpl.getOriginalNodeId(),
21385                                                    wikiPageModelImpl.getOriginalTitle()
21386                                            };
21387    
21388                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
21389                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T,
21390                                            args);
21391    
21392                                    args = new Object[] {
21393                                                    wikiPageModelImpl.getNodeId(),
21394                                                    wikiPageModelImpl.getTitle()
21395                                            };
21396    
21397                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
21398                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T,
21399                                            args);
21400                            }
21401    
21402                            if ((wikiPageModelImpl.getColumnBitmask() &
21403                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H.getColumnBitmask()) != 0) {
21404                                    Object[] args = new Object[] {
21405                                                    wikiPageModelImpl.getOriginalNodeId(),
21406                                                    wikiPageModelImpl.getOriginalHead()
21407                                            };
21408    
21409                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H, args);
21410                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H,
21411                                            args);
21412    
21413                                    args = new Object[] {
21414                                                    wikiPageModelImpl.getNodeId(),
21415                                                    wikiPageModelImpl.getHead()
21416                                            };
21417    
21418                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H, args);
21419                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H,
21420                                            args);
21421                            }
21422    
21423                            if ((wikiPageModelImpl.getColumnBitmask() &
21424                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P.getColumnBitmask()) != 0) {
21425                                    Object[] args = new Object[] {
21426                                                    wikiPageModelImpl.getOriginalNodeId(),
21427                                                    wikiPageModelImpl.getOriginalParentTitle()
21428                                            };
21429    
21430                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_P, args);
21431                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P,
21432                                            args);
21433    
21434                                    args = new Object[] {
21435                                                    wikiPageModelImpl.getNodeId(),
21436                                                    wikiPageModelImpl.getParentTitle()
21437                                            };
21438    
21439                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_P, args);
21440                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P,
21441                                            args);
21442                            }
21443    
21444                            if ((wikiPageModelImpl.getColumnBitmask() &
21445                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R.getColumnBitmask()) != 0) {
21446                                    Object[] args = new Object[] {
21447                                                    wikiPageModelImpl.getOriginalNodeId(),
21448                                                    wikiPageModelImpl.getOriginalRedirectTitle()
21449                                            };
21450    
21451                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_R, args);
21452                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R,
21453                                            args);
21454    
21455                                    args = new Object[] {
21456                                                    wikiPageModelImpl.getNodeId(),
21457                                                    wikiPageModelImpl.getRedirectTitle()
21458                                            };
21459    
21460                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_R, args);
21461                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R,
21462                                            args);
21463                            }
21464    
21465                            if ((wikiPageModelImpl.getColumnBitmask() &
21466                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S.getColumnBitmask()) != 0) {
21467                                    Object[] args = new Object[] {
21468                                                    wikiPageModelImpl.getOriginalNodeId(),
21469                                                    wikiPageModelImpl.getOriginalStatus()
21470                                            };
21471    
21472                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_S, args);
21473                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S,
21474                                            args);
21475    
21476                                    args = new Object[] {
21477                                                    wikiPageModelImpl.getNodeId(),
21478                                                    wikiPageModelImpl.getStatus()
21479                                            };
21480    
21481                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_S, args);
21482                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S,
21483                                            args);
21484                            }
21485    
21486                            if ((wikiPageModelImpl.getColumnBitmask() &
21487                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H.getColumnBitmask()) != 0) {
21488                                    Object[] args = new Object[] {
21489                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
21490                                                    wikiPageModelImpl.getOriginalNodeId(),
21491                                                    wikiPageModelImpl.getOriginalHead()
21492                                            };
21493    
21494                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_H, args);
21495                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H,
21496                                            args);
21497    
21498                                    args = new Object[] {
21499                                                    wikiPageModelImpl.getResourcePrimKey(),
21500                                                    wikiPageModelImpl.getNodeId(),
21501                                                    wikiPageModelImpl.getHead()
21502                                            };
21503    
21504                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_H, args);
21505                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H,
21506                                            args);
21507                            }
21508    
21509                            if ((wikiPageModelImpl.getColumnBitmask() &
21510                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S.getColumnBitmask()) != 0) {
21511                                    Object[] args = new Object[] {
21512                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
21513                                                    wikiPageModelImpl.getOriginalNodeId(),
21514                                                    wikiPageModelImpl.getOriginalStatus()
21515                                            };
21516    
21517                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_S, args);
21518                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S,
21519                                            args);
21520    
21521                                    args = new Object[] {
21522                                                    wikiPageModelImpl.getResourcePrimKey(),
21523                                                    wikiPageModelImpl.getNodeId(),
21524                                                    wikiPageModelImpl.getStatus()
21525                                            };
21526    
21527                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_S, args);
21528                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S,
21529                                            args);
21530                            }
21531    
21532                            if ((wikiPageModelImpl.getColumnBitmask() &
21533                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H.getColumnBitmask()) != 0) {
21534                                    Object[] args = new Object[] {
21535                                                    wikiPageModelImpl.getOriginalGroupId(),
21536                                                    wikiPageModelImpl.getOriginalNodeId(),
21537                                                    wikiPageModelImpl.getOriginalHead()
21538                                            };
21539    
21540                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H, args);
21541                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H,
21542                                            args);
21543    
21544                                    args = new Object[] {
21545                                                    wikiPageModelImpl.getGroupId(),
21546                                                    wikiPageModelImpl.getNodeId(),
21547                                                    wikiPageModelImpl.getHead()
21548                                            };
21549    
21550                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H, args);
21551                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H,
21552                                            args);
21553                            }
21554    
21555                            if ((wikiPageModelImpl.getColumnBitmask() &
21556                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S.getColumnBitmask()) != 0) {
21557                                    Object[] args = new Object[] {
21558                                                    wikiPageModelImpl.getOriginalGroupId(),
21559                                                    wikiPageModelImpl.getOriginalNodeId(),
21560                                                    wikiPageModelImpl.getOriginalStatus()
21561                                            };
21562    
21563                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_S, args);
21564                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S,
21565                                            args);
21566    
21567                                    args = new Object[] {
21568                                                    wikiPageModelImpl.getGroupId(),
21569                                                    wikiPageModelImpl.getNodeId(),
21570                                                    wikiPageModelImpl.getStatus()
21571                                            };
21572    
21573                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_S, args);
21574                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S,
21575                                            args);
21576                            }
21577    
21578                            if ((wikiPageModelImpl.getColumnBitmask() &
21579                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S.getColumnBitmask()) != 0) {
21580                                    Object[] args = new Object[] {
21581                                                    wikiPageModelImpl.getOriginalUserId(),
21582                                                    wikiPageModelImpl.getOriginalNodeId(),
21583                                                    wikiPageModelImpl.getOriginalStatus()
21584                                            };
21585    
21586                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_N_S, args);
21587                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S,
21588                                            args);
21589    
21590                                    args = new Object[] {
21591                                                    wikiPageModelImpl.getUserId(),
21592                                                    wikiPageModelImpl.getNodeId(),
21593                                                    wikiPageModelImpl.getStatus()
21594                                            };
21595    
21596                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_N_S, args);
21597                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S,
21598                                            args);
21599                            }
21600    
21601                            if ((wikiPageModelImpl.getColumnBitmask() &
21602                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H.getColumnBitmask()) != 0) {
21603                                    Object[] args = new Object[] {
21604                                                    wikiPageModelImpl.getOriginalNodeId(),
21605                                                    wikiPageModelImpl.getOriginalTitle(),
21606                                                    wikiPageModelImpl.getOriginalHead()
21607                                            };
21608    
21609                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_H, args);
21610                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H,
21611                                            args);
21612    
21613                                    args = new Object[] {
21614                                                    wikiPageModelImpl.getNodeId(),
21615                                                    wikiPageModelImpl.getTitle(),
21616                                                    wikiPageModelImpl.getHead()
21617                                            };
21618    
21619                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_H, args);
21620                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H,
21621                                            args);
21622                            }
21623    
21624                            if ((wikiPageModelImpl.getColumnBitmask() &
21625                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S.getColumnBitmask()) != 0) {
21626                                    Object[] args = new Object[] {
21627                                                    wikiPageModelImpl.getOriginalNodeId(),
21628                                                    wikiPageModelImpl.getOriginalTitle(),
21629                                                    wikiPageModelImpl.getOriginalStatus()
21630                                            };
21631    
21632                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_S, args);
21633                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S,
21634                                            args);
21635    
21636                                    args = new Object[] {
21637                                                    wikiPageModelImpl.getNodeId(),
21638                                                    wikiPageModelImpl.getTitle(),
21639                                                    wikiPageModelImpl.getStatus()
21640                                            };
21641    
21642                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_S, args);
21643                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S,
21644                                            args);
21645                            }
21646    
21647                            if ((wikiPageModelImpl.getColumnBitmask() &
21648                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P.getColumnBitmask()) != 0) {
21649                                    Object[] args = new Object[] {
21650                                                    wikiPageModelImpl.getOriginalNodeId(),
21651                                                    wikiPageModelImpl.getOriginalHead(),
21652                                                    wikiPageModelImpl.getOriginalParentTitle()
21653                                            };
21654    
21655                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P, args);
21656                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P,
21657                                            args);
21658    
21659                                    args = new Object[] {
21660                                                    wikiPageModelImpl.getNodeId(),
21661                                                    wikiPageModelImpl.getHead(),
21662                                                    wikiPageModelImpl.getParentTitle()
21663                                            };
21664    
21665                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P, args);
21666                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P,
21667                                            args);
21668                            }
21669    
21670                            if ((wikiPageModelImpl.getColumnBitmask() &
21671                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S.getColumnBitmask()) != 0) {
21672                                    Object[] args = new Object[] {
21673                                                    wikiPageModelImpl.getOriginalNodeId(),
21674                                                    wikiPageModelImpl.getOriginalHead(),
21675                                                    wikiPageModelImpl.getOriginalStatus()
21676                                            };
21677    
21678                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_S, args);
21679                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S,
21680                                            args);
21681    
21682                                    args = new Object[] {
21683                                                    wikiPageModelImpl.getNodeId(),
21684                                                    wikiPageModelImpl.getHead(),
21685                                                    wikiPageModelImpl.getStatus()
21686                                            };
21687    
21688                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_S, args);
21689                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S,
21690                                            args);
21691                            }
21692    
21693                            if ((wikiPageModelImpl.getColumnBitmask() &
21694                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S.getColumnBitmask()) != 0) {
21695                                    Object[] args = new Object[] {
21696                                                    wikiPageModelImpl.getOriginalGroupId(),
21697                                                    wikiPageModelImpl.getOriginalUserId(),
21698                                                    wikiPageModelImpl.getOriginalNodeId(),
21699                                                    wikiPageModelImpl.getOriginalStatus()
21700                                            };
21701    
21702                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_N_S, args);
21703                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S,
21704                                            args);
21705    
21706                                    args = new Object[] {
21707                                                    wikiPageModelImpl.getGroupId(),
21708                                                    wikiPageModelImpl.getUserId(),
21709                                                    wikiPageModelImpl.getNodeId(),
21710                                                    wikiPageModelImpl.getStatus()
21711                                            };
21712    
21713                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_N_S, args);
21714                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S,
21715                                            args);
21716                            }
21717    
21718                            if ((wikiPageModelImpl.getColumnBitmask() &
21719                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H.getColumnBitmask()) != 0) {
21720                                    Object[] args = new Object[] {
21721                                                    wikiPageModelImpl.getOriginalGroupId(),
21722                                                    wikiPageModelImpl.getOriginalNodeId(),
21723                                                    wikiPageModelImpl.getOriginalTitle(),
21724                                                    wikiPageModelImpl.getOriginalHead()
21725                                            };
21726    
21727                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T_H, args);
21728                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H,
21729                                            args);
21730    
21731                                    args = new Object[] {
21732                                                    wikiPageModelImpl.getGroupId(),
21733                                                    wikiPageModelImpl.getNodeId(),
21734                                                    wikiPageModelImpl.getTitle(),
21735                                                    wikiPageModelImpl.getHead()
21736                                            };
21737    
21738                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T_H, args);
21739                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H,
21740                                            args);
21741                            }
21742    
21743                            if ((wikiPageModelImpl.getColumnBitmask() &
21744                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S.getColumnBitmask()) != 0) {
21745                                    Object[] args = new Object[] {
21746                                                    wikiPageModelImpl.getOriginalGroupId(),
21747                                                    wikiPageModelImpl.getOriginalNodeId(),
21748                                                    wikiPageModelImpl.getOriginalHead(),
21749                                                    wikiPageModelImpl.getOriginalStatus()
21750                                            };
21751    
21752                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_S, args);
21753                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S,
21754                                            args);
21755    
21756                                    args = new Object[] {
21757                                                    wikiPageModelImpl.getGroupId(),
21758                                                    wikiPageModelImpl.getNodeId(),
21759                                                    wikiPageModelImpl.getHead(),
21760                                                    wikiPageModelImpl.getStatus()
21761                                            };
21762    
21763                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_S, args);
21764                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S,
21765                                            args);
21766                            }
21767    
21768                            if ((wikiPageModelImpl.getColumnBitmask() &
21769                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S.getColumnBitmask()) != 0) {
21770                                    Object[] args = new Object[] {
21771                                                    wikiPageModelImpl.getOriginalNodeId(),
21772                                                    wikiPageModelImpl.getOriginalHead(),
21773                                                    wikiPageModelImpl.getOriginalParentTitle(),
21774                                                    wikiPageModelImpl.getOriginalStatus()
21775                                            };
21776    
21777                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P_S, args);
21778                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S,
21779                                            args);
21780    
21781                                    args = new Object[] {
21782                                                    wikiPageModelImpl.getNodeId(),
21783                                                    wikiPageModelImpl.getHead(),
21784                                                    wikiPageModelImpl.getParentTitle(),
21785                                                    wikiPageModelImpl.getStatus()
21786                                            };
21787    
21788                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P_S, args);
21789                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S,
21790                                            args);
21791                            }
21792    
21793                            if ((wikiPageModelImpl.getColumnBitmask() &
21794                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_R_S.getColumnBitmask()) != 0) {
21795                                    Object[] args = new Object[] {
21796                                                    wikiPageModelImpl.getOriginalNodeId(),
21797                                                    wikiPageModelImpl.getOriginalHead(),
21798                                                    wikiPageModelImpl.getOriginalRedirectTitle(),
21799                                                    wikiPageModelImpl.getOriginalStatus()
21800                                            };
21801    
21802                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_R_S, args);
21803                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_R_S,
21804                                            args);
21805    
21806                                    args = new Object[] {
21807                                                    wikiPageModelImpl.getNodeId(),
21808                                                    wikiPageModelImpl.getHead(),
21809                                                    wikiPageModelImpl.getRedirectTitle(),
21810                                                    wikiPageModelImpl.getStatus()
21811                                            };
21812    
21813                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_R_S, args);
21814                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_R_S,
21815                                            args);
21816                            }
21817    
21818                            if ((wikiPageModelImpl.getColumnBitmask() &
21819                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S.getColumnBitmask()) != 0) {
21820                                    Object[] args = new Object[] {
21821                                                    wikiPageModelImpl.getOriginalGroupId(),
21822                                                    wikiPageModelImpl.getOriginalNodeId(),
21823                                                    wikiPageModelImpl.getOriginalHead(),
21824                                                    wikiPageModelImpl.getOriginalParentTitle(),
21825                                                    wikiPageModelImpl.getOriginalStatus()
21826                                            };
21827    
21828                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_P_S,
21829                                            args);
21830                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S,
21831                                            args);
21832    
21833                                    args = new Object[] {
21834                                                    wikiPageModelImpl.getGroupId(),
21835                                                    wikiPageModelImpl.getNodeId(),
21836                                                    wikiPageModelImpl.getHead(),
21837                                                    wikiPageModelImpl.getParentTitle(),
21838                                                    wikiPageModelImpl.getStatus()
21839                                            };
21840    
21841                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_P_S,
21842                                            args);
21843                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S,
21844                                            args);
21845                            }
21846                    }
21847    
21848                    EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
21849                            WikiPageImpl.class, wikiPage.getPrimaryKey(), wikiPage);
21850    
21851                    clearUniqueFindersCache(wikiPage);
21852                    cacheUniqueFindersCache(wikiPage);
21853    
21854                    return wikiPage;
21855            }
21856    
21857            protected WikiPage toUnwrappedModel(WikiPage wikiPage) {
21858                    if (wikiPage instanceof WikiPageImpl) {
21859                            return wikiPage;
21860                    }
21861    
21862                    WikiPageImpl wikiPageImpl = new WikiPageImpl();
21863    
21864                    wikiPageImpl.setNew(wikiPage.isNew());
21865                    wikiPageImpl.setPrimaryKey(wikiPage.getPrimaryKey());
21866    
21867                    wikiPageImpl.setUuid(wikiPage.getUuid());
21868                    wikiPageImpl.setPageId(wikiPage.getPageId());
21869                    wikiPageImpl.setResourcePrimKey(wikiPage.getResourcePrimKey());
21870                    wikiPageImpl.setGroupId(wikiPage.getGroupId());
21871                    wikiPageImpl.setCompanyId(wikiPage.getCompanyId());
21872                    wikiPageImpl.setUserId(wikiPage.getUserId());
21873                    wikiPageImpl.setUserName(wikiPage.getUserName());
21874                    wikiPageImpl.setCreateDate(wikiPage.getCreateDate());
21875                    wikiPageImpl.setModifiedDate(wikiPage.getModifiedDate());
21876                    wikiPageImpl.setNodeId(wikiPage.getNodeId());
21877                    wikiPageImpl.setTitle(wikiPage.getTitle());
21878                    wikiPageImpl.setVersion(wikiPage.getVersion());
21879                    wikiPageImpl.setMinorEdit(wikiPage.isMinorEdit());
21880                    wikiPageImpl.setContent(wikiPage.getContent());
21881                    wikiPageImpl.setSummary(wikiPage.getSummary());
21882                    wikiPageImpl.setFormat(wikiPage.getFormat());
21883                    wikiPageImpl.setHead(wikiPage.isHead());
21884                    wikiPageImpl.setParentTitle(wikiPage.getParentTitle());
21885                    wikiPageImpl.setRedirectTitle(wikiPage.getRedirectTitle());
21886                    wikiPageImpl.setStatus(wikiPage.getStatus());
21887                    wikiPageImpl.setStatusByUserId(wikiPage.getStatusByUserId());
21888                    wikiPageImpl.setStatusByUserName(wikiPage.getStatusByUserName());
21889                    wikiPageImpl.setStatusDate(wikiPage.getStatusDate());
21890    
21891                    return wikiPageImpl;
21892            }
21893    
21894            /**
21895             * Returns the wiki page with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
21896             *
21897             * @param primaryKey the primary key of the wiki page
21898             * @return the wiki page
21899             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
21900             * @throws SystemException if a system exception occurred
21901             */
21902            @Override
21903            public WikiPage findByPrimaryKey(Serializable primaryKey)
21904                    throws NoSuchPageException, SystemException {
21905                    WikiPage wikiPage = fetchByPrimaryKey(primaryKey);
21906    
21907                    if (wikiPage == null) {
21908                            if (_log.isWarnEnabled()) {
21909                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
21910                            }
21911    
21912                            throw new NoSuchPageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
21913                                    primaryKey);
21914                    }
21915    
21916                    return wikiPage;
21917            }
21918    
21919            /**
21920             * Returns the wiki page with the primary key or throws a {@link com.liferay.portlet.wiki.NoSuchPageException} if it could not be found.
21921             *
21922             * @param pageId the primary key of the wiki page
21923             * @return the wiki page
21924             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
21925             * @throws SystemException if a system exception occurred
21926             */
21927            @Override
21928            public WikiPage findByPrimaryKey(long pageId)
21929                    throws NoSuchPageException, SystemException {
21930                    return findByPrimaryKey((Serializable)pageId);
21931            }
21932    
21933            /**
21934             * Returns the wiki page with the primary key or returns <code>null</code> if it could not be found.
21935             *
21936             * @param primaryKey the primary key of the wiki page
21937             * @return the wiki page, or <code>null</code> if a wiki page with the primary key could not be found
21938             * @throws SystemException if a system exception occurred
21939             */
21940            @Override
21941            public WikiPage fetchByPrimaryKey(Serializable primaryKey)
21942                    throws SystemException {
21943                    WikiPage wikiPage = (WikiPage)EntityCacheUtil.getResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
21944                                    WikiPageImpl.class, primaryKey);
21945    
21946                    if (wikiPage == _nullWikiPage) {
21947                            return null;
21948                    }
21949    
21950                    if (wikiPage == null) {
21951                            Session session = null;
21952    
21953                            try {
21954                                    session = openSession();
21955    
21956                                    wikiPage = (WikiPage)session.get(WikiPageImpl.class, primaryKey);
21957    
21958                                    if (wikiPage != null) {
21959                                            cacheResult(wikiPage);
21960                                    }
21961                                    else {
21962                                            EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
21963                                                    WikiPageImpl.class, primaryKey, _nullWikiPage);
21964                                    }
21965                            }
21966                            catch (Exception e) {
21967                                    EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
21968                                            WikiPageImpl.class, primaryKey);
21969    
21970                                    throw processException(e);
21971                            }
21972                            finally {
21973                                    closeSession(session);
21974                            }
21975                    }
21976    
21977                    return wikiPage;
21978            }
21979    
21980            /**
21981             * Returns the wiki page with the primary key or returns <code>null</code> if it could not be found.
21982             *
21983             * @param pageId the primary key of the wiki page
21984             * @return the wiki page, or <code>null</code> if a wiki page with the primary key could not be found
21985             * @throws SystemException if a system exception occurred
21986             */
21987            @Override
21988            public WikiPage fetchByPrimaryKey(long pageId) throws SystemException {
21989                    return fetchByPrimaryKey((Serializable)pageId);
21990            }
21991    
21992            /**
21993             * Returns all the wiki pages.
21994             *
21995             * @return the wiki pages
21996             * @throws SystemException if a system exception occurred
21997             */
21998            @Override
21999            public List<WikiPage> findAll() throws SystemException {
22000                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
22001            }
22002    
22003            /**
22004             * Returns a range of all the wiki pages.
22005             *
22006             * <p>
22007             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
22008             * </p>
22009             *
22010             * @param start the lower bound of the range of wiki pages
22011             * @param end the upper bound of the range of wiki pages (not inclusive)
22012             * @return the range of wiki pages
22013             * @throws SystemException if a system exception occurred
22014             */
22015            @Override
22016            public List<WikiPage> findAll(int start, int end) throws SystemException {
22017                    return findAll(start, end, null);
22018            }
22019    
22020            /**
22021             * Returns an ordered range of all the wiki pages.
22022             *
22023             * <p>
22024             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <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.
22025             * </p>
22026             *
22027             * @param start the lower bound of the range of wiki pages
22028             * @param end the upper bound of the range of wiki pages (not inclusive)
22029             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
22030             * @return the ordered range of wiki pages
22031             * @throws SystemException if a system exception occurred
22032             */
22033            @Override
22034            public List<WikiPage> findAll(int start, int end,
22035                    OrderByComparator orderByComparator) throws SystemException {
22036                    boolean pagination = true;
22037                    FinderPath finderPath = null;
22038                    Object[] finderArgs = null;
22039    
22040                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
22041                                    (orderByComparator == null)) {
22042                            pagination = false;
22043                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
22044                            finderArgs = FINDER_ARGS_EMPTY;
22045                    }
22046                    else {
22047                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
22048                            finderArgs = new Object[] { start, end, orderByComparator };
22049                    }
22050    
22051                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
22052                                    finderArgs, this);
22053    
22054                    if (list == null) {
22055                            StringBundler query = null;
22056                            String sql = null;
22057    
22058                            if (orderByComparator != null) {
22059                                    query = new StringBundler(2 +
22060                                                    (orderByComparator.getOrderByFields().length * 3));
22061    
22062                                    query.append(_SQL_SELECT_WIKIPAGE);
22063    
22064                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
22065                                            orderByComparator);
22066    
22067                                    sql = query.toString();
22068                            }
22069                            else {
22070                                    sql = _SQL_SELECT_WIKIPAGE;
22071    
22072                                    if (pagination) {
22073                                            sql = sql.concat(WikiPageModelImpl.ORDER_BY_JPQL);
22074                                    }
22075                            }
22076    
22077                            Session session = null;
22078    
22079                            try {
22080                                    session = openSession();
22081    
22082                                    Query q = session.createQuery(sql);
22083    
22084                                    if (!pagination) {
22085                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
22086                                                            start, end, false);
22087    
22088                                            Collections.sort(list);
22089    
22090                                            list = new UnmodifiableList<WikiPage>(list);
22091                                    }
22092                                    else {
22093                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
22094                                                            start, end);
22095                                    }
22096    
22097                                    cacheResult(list);
22098    
22099                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
22100                            }
22101                            catch (Exception e) {
22102                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
22103    
22104                                    throw processException(e);
22105                            }
22106                            finally {
22107                                    closeSession(session);
22108                            }
22109                    }
22110    
22111                    return list;
22112            }
22113    
22114            /**
22115             * Removes all the wiki pages from the database.
22116             *
22117             * @throws SystemException if a system exception occurred
22118             */
22119            @Override
22120            public void removeAll() throws SystemException {
22121                    for (WikiPage wikiPage : findAll()) {
22122                            remove(wikiPage);
22123                    }
22124            }
22125    
22126            /**
22127             * Returns the number of wiki pages.
22128             *
22129             * @return the number of wiki pages
22130             * @throws SystemException if a system exception occurred
22131             */
22132            @Override
22133            public int countAll() throws SystemException {
22134                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
22135                                    FINDER_ARGS_EMPTY, this);
22136    
22137                    if (count == null) {
22138                            Session session = null;
22139    
22140                            try {
22141                                    session = openSession();
22142    
22143                                    Query q = session.createQuery(_SQL_COUNT_WIKIPAGE);
22144    
22145                                    count = (Long)q.uniqueResult();
22146    
22147                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
22148                                            FINDER_ARGS_EMPTY, count);
22149                            }
22150                            catch (Exception e) {
22151                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
22152                                            FINDER_ARGS_EMPTY);
22153    
22154                                    throw processException(e);
22155                            }
22156                            finally {
22157                                    closeSession(session);
22158                            }
22159                    }
22160    
22161                    return count.intValue();
22162            }
22163    
22164            @Override
22165            protected Set<String> getBadColumnNames() {
22166                    return _badColumnNames;
22167            }
22168    
22169            /**
22170             * Initializes the wiki page persistence.
22171             */
22172            public void afterPropertiesSet() {
22173                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
22174                                            com.liferay.portal.util.PropsUtil.get(
22175                                                    "value.object.listener.com.liferay.portlet.wiki.model.WikiPage")));
22176    
22177                    if (listenerClassNames.length > 0) {
22178                            try {
22179                                    List<ModelListener<WikiPage>> listenersList = new ArrayList<ModelListener<WikiPage>>();
22180    
22181                                    for (String listenerClassName : listenerClassNames) {
22182                                            listenersList.add((ModelListener<WikiPage>)InstanceFactory.newInstance(
22183                                                            getClassLoader(), listenerClassName));
22184                                    }
22185    
22186                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
22187                            }
22188                            catch (Exception e) {
22189                                    _log.error(e);
22190                            }
22191                    }
22192            }
22193    
22194            public void destroy() {
22195                    EntityCacheUtil.removeCache(WikiPageImpl.class.getName());
22196                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
22197                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
22198                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
22199            }
22200    
22201            private static final String _SQL_SELECT_WIKIPAGE = "SELECT wikiPage FROM WikiPage wikiPage";
22202            private static final String _SQL_SELECT_WIKIPAGE_WHERE = "SELECT wikiPage FROM WikiPage wikiPage WHERE ";
22203            private static final String _SQL_COUNT_WIKIPAGE = "SELECT COUNT(wikiPage) FROM WikiPage wikiPage";
22204            private static final String _SQL_COUNT_WIKIPAGE_WHERE = "SELECT COUNT(wikiPage) FROM WikiPage wikiPage WHERE ";
22205            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "wikiPage.resourcePrimKey";
22206            private static final String _FILTER_SQL_SELECT_WIKIPAGE_WHERE = "SELECT DISTINCT {wikiPage.*} FROM WikiPage wikiPage WHERE ";
22207            private static final String _FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1 =
22208                    "SELECT {WikiPage.*} FROM (SELECT DISTINCT wikiPage.pageId FROM WikiPage wikiPage WHERE ";
22209            private static final String _FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2 =
22210                    ") TEMP_TABLE INNER JOIN WikiPage ON TEMP_TABLE.pageId = WikiPage.pageId";
22211            private static final String _FILTER_SQL_COUNT_WIKIPAGE_WHERE = "SELECT COUNT(DISTINCT wikiPage.pageId) AS COUNT_VALUE FROM WikiPage wikiPage WHERE ";
22212            private static final String _FILTER_ENTITY_ALIAS = "wikiPage";
22213            private static final String _FILTER_ENTITY_TABLE = "WikiPage";
22214            private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPage.";
22215            private static final String _ORDER_BY_ENTITY_TABLE = "WikiPage.";
22216            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPage exists with the primary key ";
22217            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPage exists with the key {";
22218            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
22219            private static Log _log = LogFactoryUtil.getLog(WikiPagePersistenceImpl.class);
22220            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
22221                                    "uuid"
22222                            });
22223            private static WikiPage _nullWikiPage = new WikiPageImpl() {
22224                            @Override
22225                            public Object clone() {
22226                                    return this;
22227                            }
22228    
22229                            @Override
22230                            public CacheModel<WikiPage> toCacheModel() {
22231                                    return _nullWikiPageCacheModel;
22232                            }
22233                    };
22234    
22235            private static CacheModel<WikiPage> _nullWikiPageCacheModel = new CacheModel<WikiPage>() {
22236                            @Override
22237                            public WikiPage toEntityModel() {
22238                                    return _nullWikiPage;
22239                            }
22240                    };
22241    }