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_G_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13412                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
13413                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_N_S",
13414                            new String[] {
13415                                    Long.class.getName(), Long.class.getName(), Long.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_WITHOUT_PAGINATION_FIND_BY_G_U_N_S =
13422                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13423                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
13424                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_N_S",
13425                            new String[] {
13426                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
13427                                    Integer.class.getName()
13428                            },
13429                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
13430                            WikiPageModelImpl.USERID_COLUMN_BITMASK |
13431                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
13432                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
13433                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
13434                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
13435            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13436                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13437                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_N_S",
13438                            new String[] {
13439                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
13440                                    Integer.class.getName()
13441                            });
13442    
13443            /**
13444             * Returns all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
13445             *
13446             * @param groupId the group ID
13447             * @param userId the user ID
13448             * @param nodeId the node ID
13449             * @param status the status
13450             * @return the matching wiki pages
13451             * @throws SystemException if a system exception occurred
13452             */
13453            @Override
13454            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
13455                    int status) throws SystemException {
13456                    return findByG_U_N_S(groupId, userId, nodeId, status,
13457                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13458            }
13459    
13460            /**
13461             * Returns a range of all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
13462             *
13463             * <p>
13464             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13465             * </p>
13466             *
13467             * @param groupId the group ID
13468             * @param userId the user ID
13469             * @param nodeId the node ID
13470             * @param status the status
13471             * @param start the lower bound of the range of wiki pages
13472             * @param end the upper bound of the range of wiki pages (not inclusive)
13473             * @return the range of matching wiki pages
13474             * @throws SystemException if a system exception occurred
13475             */
13476            @Override
13477            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
13478                    int status, int start, int end) throws SystemException {
13479                    return findByG_U_N_S(groupId, userId, nodeId, status, start, end, null);
13480            }
13481    
13482            /**
13483             * Returns an ordered range of all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
13484             *
13485             * <p>
13486             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13487             * </p>
13488             *
13489             * @param groupId the group ID
13490             * @param userId the user ID
13491             * @param nodeId the node ID
13492             * @param status the status
13493             * @param start the lower bound of the range of wiki pages
13494             * @param end the upper bound of the range of wiki pages (not inclusive)
13495             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13496             * @return the ordered range of matching wiki pages
13497             * @throws SystemException if a system exception occurred
13498             */
13499            @Override
13500            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
13501                    int status, int start, int end, OrderByComparator orderByComparator)
13502                    throws SystemException {
13503                    boolean pagination = true;
13504                    FinderPath finderPath = null;
13505                    Object[] finderArgs = null;
13506    
13507                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13508                                    (orderByComparator == null)) {
13509                            pagination = false;
13510                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S;
13511                            finderArgs = new Object[] { groupId, userId, nodeId, status };
13512                    }
13513                    else {
13514                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_N_S;
13515                            finderArgs = new Object[] {
13516                                            groupId, userId, nodeId, status,
13517                                            
13518                                            start, end, orderByComparator
13519                                    };
13520                    }
13521    
13522                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
13523                                    finderArgs, this);
13524    
13525                    if ((list != null) && !list.isEmpty()) {
13526                            for (WikiPage wikiPage : list) {
13527                                    if ((groupId != wikiPage.getGroupId()) ||
13528                                                    (userId != wikiPage.getUserId()) ||
13529                                                    (nodeId != wikiPage.getNodeId()) ||
13530                                                    (status != wikiPage.getStatus())) {
13531                                            list = null;
13532    
13533                                            break;
13534                                    }
13535                            }
13536                    }
13537    
13538                    if (list == null) {
13539                            StringBundler query = null;
13540    
13541                            if (orderByComparator != null) {
13542                                    query = new StringBundler(6 +
13543                                                    (orderByComparator.getOrderByFields().length * 3));
13544                            }
13545                            else {
13546                                    query = new StringBundler(6);
13547                            }
13548    
13549                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
13550    
13551                            query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
13552    
13553                            query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
13554    
13555                            query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
13556    
13557                            query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
13558    
13559                            if (orderByComparator != null) {
13560                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13561                                            orderByComparator);
13562                            }
13563                            else
13564                             if (pagination) {
13565                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13566                            }
13567    
13568                            String sql = query.toString();
13569    
13570                            Session session = null;
13571    
13572                            try {
13573                                    session = openSession();
13574    
13575                                    Query q = session.createQuery(sql);
13576    
13577                                    QueryPos qPos = QueryPos.getInstance(q);
13578    
13579                                    qPos.add(groupId);
13580    
13581                                    qPos.add(userId);
13582    
13583                                    qPos.add(nodeId);
13584    
13585                                    qPos.add(status);
13586    
13587                                    if (!pagination) {
13588                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13589                                                            start, end, false);
13590    
13591                                            Collections.sort(list);
13592    
13593                                            list = new UnmodifiableList<WikiPage>(list);
13594                                    }
13595                                    else {
13596                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13597                                                            start, end);
13598                                    }
13599    
13600                                    cacheResult(list);
13601    
13602                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13603                            }
13604                            catch (Exception e) {
13605                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13606    
13607                                    throw processException(e);
13608                            }
13609                            finally {
13610                                    closeSession(session);
13611                            }
13612                    }
13613    
13614                    return list;
13615            }
13616    
13617            /**
13618             * Returns the first wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
13619             *
13620             * @param groupId the group ID
13621             * @param userId the user ID
13622             * @param nodeId the node ID
13623             * @param status the status
13624             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13625             * @return the first matching wiki page
13626             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13627             * @throws SystemException if a system exception occurred
13628             */
13629            @Override
13630            public WikiPage findByG_U_N_S_First(long groupId, long userId, long nodeId,
13631                    int status, OrderByComparator orderByComparator)
13632                    throws NoSuchPageException, SystemException {
13633                    WikiPage wikiPage = fetchByG_U_N_S_First(groupId, userId, nodeId,
13634                                    status, orderByComparator);
13635    
13636                    if (wikiPage != null) {
13637                            return wikiPage;
13638                    }
13639    
13640                    StringBundler msg = new StringBundler(10);
13641    
13642                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13643    
13644                    msg.append("groupId=");
13645                    msg.append(groupId);
13646    
13647                    msg.append(", userId=");
13648                    msg.append(userId);
13649    
13650                    msg.append(", nodeId=");
13651                    msg.append(nodeId);
13652    
13653                    msg.append(", status=");
13654                    msg.append(status);
13655    
13656                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13657    
13658                    throw new NoSuchPageException(msg.toString());
13659            }
13660    
13661            /**
13662             * Returns the first wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
13663             *
13664             * @param groupId the group ID
13665             * @param userId the user ID
13666             * @param nodeId the node ID
13667             * @param status the status
13668             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13669             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
13670             * @throws SystemException if a system exception occurred
13671             */
13672            @Override
13673            public WikiPage fetchByG_U_N_S_First(long groupId, long userId,
13674                    long nodeId, int status, OrderByComparator orderByComparator)
13675                    throws SystemException {
13676                    List<WikiPage> list = findByG_U_N_S(groupId, userId, nodeId, status, 0,
13677                                    1, orderByComparator);
13678    
13679                    if (!list.isEmpty()) {
13680                            return list.get(0);
13681                    }
13682    
13683                    return null;
13684            }
13685    
13686            /**
13687             * Returns the last wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
13688             *
13689             * @param groupId the group ID
13690             * @param userId the user ID
13691             * @param nodeId the node ID
13692             * @param status the status
13693             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13694             * @return the last matching wiki page
13695             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13696             * @throws SystemException if a system exception occurred
13697             */
13698            @Override
13699            public WikiPage findByG_U_N_S_Last(long groupId, long userId, long nodeId,
13700                    int status, OrderByComparator orderByComparator)
13701                    throws NoSuchPageException, SystemException {
13702                    WikiPage wikiPage = fetchByG_U_N_S_Last(groupId, userId, nodeId,
13703                                    status, orderByComparator);
13704    
13705                    if (wikiPage != null) {
13706                            return wikiPage;
13707                    }
13708    
13709                    StringBundler msg = new StringBundler(10);
13710    
13711                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13712    
13713                    msg.append("groupId=");
13714                    msg.append(groupId);
13715    
13716                    msg.append(", userId=");
13717                    msg.append(userId);
13718    
13719                    msg.append(", nodeId=");
13720                    msg.append(nodeId);
13721    
13722                    msg.append(", status=");
13723                    msg.append(status);
13724    
13725                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13726    
13727                    throw new NoSuchPageException(msg.toString());
13728            }
13729    
13730            /**
13731             * Returns the last wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
13732             *
13733             * @param groupId the group ID
13734             * @param userId the user ID
13735             * @param nodeId the node ID
13736             * @param status the status
13737             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13738             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
13739             * @throws SystemException if a system exception occurred
13740             */
13741            @Override
13742            public WikiPage fetchByG_U_N_S_Last(long groupId, long userId, long nodeId,
13743                    int status, OrderByComparator orderByComparator)
13744                    throws SystemException {
13745                    int count = countByG_U_N_S(groupId, userId, nodeId, status);
13746    
13747                    if (count == 0) {
13748                            return null;
13749                    }
13750    
13751                    List<WikiPage> list = findByG_U_N_S(groupId, userId, nodeId, status,
13752                                    count - 1, count, orderByComparator);
13753    
13754                    if (!list.isEmpty()) {
13755                            return list.get(0);
13756                    }
13757    
13758                    return null;
13759            }
13760    
13761            /**
13762             * 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;.
13763             *
13764             * @param pageId the primary key of the current wiki page
13765             * @param groupId the group ID
13766             * @param userId the user ID
13767             * @param nodeId the node ID
13768             * @param status the status
13769             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13770             * @return the previous, current, and next wiki page
13771             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
13772             * @throws SystemException if a system exception occurred
13773             */
13774            @Override
13775            public WikiPage[] findByG_U_N_S_PrevAndNext(long pageId, long groupId,
13776                    long userId, long nodeId, int status,
13777                    OrderByComparator orderByComparator)
13778                    throws NoSuchPageException, SystemException {
13779                    WikiPage wikiPage = findByPrimaryKey(pageId);
13780    
13781                    Session session = null;
13782    
13783                    try {
13784                            session = openSession();
13785    
13786                            WikiPage[] array = new WikiPageImpl[3];
13787    
13788                            array[0] = getByG_U_N_S_PrevAndNext(session, wikiPage, groupId,
13789                                            userId, nodeId, status, orderByComparator, true);
13790    
13791                            array[1] = wikiPage;
13792    
13793                            array[2] = getByG_U_N_S_PrevAndNext(session, wikiPage, groupId,
13794                                            userId, nodeId, status, orderByComparator, false);
13795    
13796                            return array;
13797                    }
13798                    catch (Exception e) {
13799                            throw processException(e);
13800                    }
13801                    finally {
13802                            closeSession(session);
13803                    }
13804            }
13805    
13806            protected WikiPage getByG_U_N_S_PrevAndNext(Session session,
13807                    WikiPage wikiPage, long groupId, long userId, long nodeId, int status,
13808                    OrderByComparator orderByComparator, boolean previous) {
13809                    StringBundler query = null;
13810    
13811                    if (orderByComparator != null) {
13812                            query = new StringBundler(6 +
13813                                            (orderByComparator.getOrderByFields().length * 6));
13814                    }
13815                    else {
13816                            query = new StringBundler(3);
13817                    }
13818    
13819                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
13820    
13821                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
13822    
13823                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
13824    
13825                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
13826    
13827                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
13828    
13829                    if (orderByComparator != null) {
13830                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13831    
13832                            if (orderByConditionFields.length > 0) {
13833                                    query.append(WHERE_AND);
13834                            }
13835    
13836                            for (int i = 0; i < orderByConditionFields.length; i++) {
13837                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13838                                    query.append(orderByConditionFields[i]);
13839    
13840                                    if ((i + 1) < orderByConditionFields.length) {
13841                                            if (orderByComparator.isAscending() ^ previous) {
13842                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13843                                            }
13844                                            else {
13845                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13846                                            }
13847                                    }
13848                                    else {
13849                                            if (orderByComparator.isAscending() ^ previous) {
13850                                                    query.append(WHERE_GREATER_THAN);
13851                                            }
13852                                            else {
13853                                                    query.append(WHERE_LESSER_THAN);
13854                                            }
13855                                    }
13856                            }
13857    
13858                            query.append(ORDER_BY_CLAUSE);
13859    
13860                            String[] orderByFields = orderByComparator.getOrderByFields();
13861    
13862                            for (int i = 0; i < orderByFields.length; i++) {
13863                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13864                                    query.append(orderByFields[i]);
13865    
13866                                    if ((i + 1) < orderByFields.length) {
13867                                            if (orderByComparator.isAscending() ^ previous) {
13868                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13869                                            }
13870                                            else {
13871                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13872                                            }
13873                                    }
13874                                    else {
13875                                            if (orderByComparator.isAscending() ^ previous) {
13876                                                    query.append(ORDER_BY_ASC);
13877                                            }
13878                                            else {
13879                                                    query.append(ORDER_BY_DESC);
13880                                            }
13881                                    }
13882                            }
13883                    }
13884                    else {
13885                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13886                    }
13887    
13888                    String sql = query.toString();
13889    
13890                    Query q = session.createQuery(sql);
13891    
13892                    q.setFirstResult(0);
13893                    q.setMaxResults(2);
13894    
13895                    QueryPos qPos = QueryPos.getInstance(q);
13896    
13897                    qPos.add(groupId);
13898    
13899                    qPos.add(userId);
13900    
13901                    qPos.add(nodeId);
13902    
13903                    qPos.add(status);
13904    
13905                    if (orderByComparator != null) {
13906                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
13907    
13908                            for (Object value : values) {
13909                                    qPos.add(value);
13910                            }
13911                    }
13912    
13913                    List<WikiPage> list = q.list();
13914    
13915                    if (list.size() == 2) {
13916                            return list.get(1);
13917                    }
13918                    else {
13919                            return null;
13920                    }
13921            }
13922    
13923            /**
13924             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
13925             *
13926             * @param groupId the group ID
13927             * @param userId the user ID
13928             * @param nodeId the node ID
13929             * @param status the status
13930             * @return the matching wiki pages that the user has permission to view
13931             * @throws SystemException if a system exception occurred
13932             */
13933            @Override
13934            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
13935                    long nodeId, int status) throws SystemException {
13936                    return filterFindByG_U_N_S(groupId, userId, nodeId, status,
13937                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13938            }
13939    
13940            /**
13941             * 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;.
13942             *
13943             * <p>
13944             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13945             * </p>
13946             *
13947             * @param groupId the group ID
13948             * @param userId the user ID
13949             * @param nodeId the node ID
13950             * @param status the status
13951             * @param start the lower bound of the range of wiki pages
13952             * @param end the upper bound of the range of wiki pages (not inclusive)
13953             * @return the range of matching wiki pages that the user has permission to view
13954             * @throws SystemException if a system exception occurred
13955             */
13956            @Override
13957            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
13958                    long nodeId, int status, int start, int end) throws SystemException {
13959                    return filterFindByG_U_N_S(groupId, userId, nodeId, status, start, end,
13960                            null);
13961            }
13962    
13963            /**
13964             * 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;.
13965             *
13966             * <p>
13967             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13968             * </p>
13969             *
13970             * @param groupId the group ID
13971             * @param userId the user ID
13972             * @param nodeId the node ID
13973             * @param status the status
13974             * @param start the lower bound of the range of wiki pages
13975             * @param end the upper bound of the range of wiki pages (not inclusive)
13976             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13977             * @return the ordered range of matching wiki pages that the user has permission to view
13978             * @throws SystemException if a system exception occurred
13979             */
13980            @Override
13981            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
13982                    long nodeId, int status, int start, int end,
13983                    OrderByComparator orderByComparator) throws SystemException {
13984                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13985                            return findByG_U_N_S(groupId, userId, nodeId, status, start, end,
13986                                    orderByComparator);
13987                    }
13988    
13989                    StringBundler query = null;
13990    
13991                    if (orderByComparator != null) {
13992                            query = new StringBundler(6 +
13993                                            (orderByComparator.getOrderByFields().length * 3));
13994                    }
13995                    else {
13996                            query = new StringBundler(6);
13997                    }
13998    
13999                    if (getDB().isSupportsInlineDistinct()) {
14000                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
14001                    }
14002                    else {
14003                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
14004                    }
14005    
14006                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
14007    
14008                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
14009    
14010                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
14011    
14012                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
14013    
14014                    if (!getDB().isSupportsInlineDistinct()) {
14015                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
14016                    }
14017    
14018                    if (orderByComparator != null) {
14019                            if (getDB().isSupportsInlineDistinct()) {
14020                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14021                                            orderByComparator, true);
14022                            }
14023                            else {
14024                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
14025                                            orderByComparator, true);
14026                            }
14027                    }
14028                    else {
14029                            if (getDB().isSupportsInlineDistinct()) {
14030                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14031                            }
14032                            else {
14033                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
14034                            }
14035                    }
14036    
14037                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14038                                    WikiPage.class.getName(),
14039                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14040    
14041                    Session session = null;
14042    
14043                    try {
14044                            session = openSession();
14045    
14046                            SQLQuery q = session.createSQLQuery(sql);
14047    
14048                            if (getDB().isSupportsInlineDistinct()) {
14049                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
14050                            }
14051                            else {
14052                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
14053                            }
14054    
14055                            QueryPos qPos = QueryPos.getInstance(q);
14056    
14057                            qPos.add(groupId);
14058    
14059                            qPos.add(userId);
14060    
14061                            qPos.add(nodeId);
14062    
14063                            qPos.add(status);
14064    
14065                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
14066                    }
14067                    catch (Exception e) {
14068                            throw processException(e);
14069                    }
14070                    finally {
14071                            closeSession(session);
14072                    }
14073            }
14074    
14075            /**
14076             * 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;.
14077             *
14078             * @param pageId the primary key of the current wiki page
14079             * @param groupId the group ID
14080             * @param userId the user ID
14081             * @param nodeId the node ID
14082             * @param status the status
14083             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14084             * @return the previous, current, and next wiki page
14085             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
14086             * @throws SystemException if a system exception occurred
14087             */
14088            @Override
14089            public WikiPage[] filterFindByG_U_N_S_PrevAndNext(long pageId,
14090                    long groupId, long userId, long nodeId, int status,
14091                    OrderByComparator orderByComparator)
14092                    throws NoSuchPageException, SystemException {
14093                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14094                            return findByG_U_N_S_PrevAndNext(pageId, groupId, userId, nodeId,
14095                                    status, orderByComparator);
14096                    }
14097    
14098                    WikiPage wikiPage = findByPrimaryKey(pageId);
14099    
14100                    Session session = null;
14101    
14102                    try {
14103                            session = openSession();
14104    
14105                            WikiPage[] array = new WikiPageImpl[3];
14106    
14107                            array[0] = filterGetByG_U_N_S_PrevAndNext(session, wikiPage,
14108                                            groupId, userId, nodeId, status, orderByComparator, true);
14109    
14110                            array[1] = wikiPage;
14111    
14112                            array[2] = filterGetByG_U_N_S_PrevAndNext(session, wikiPage,
14113                                            groupId, userId, nodeId, status, orderByComparator, false);
14114    
14115                            return array;
14116                    }
14117                    catch (Exception e) {
14118                            throw processException(e);
14119                    }
14120                    finally {
14121                            closeSession(session);
14122                    }
14123            }
14124    
14125            protected WikiPage filterGetByG_U_N_S_PrevAndNext(Session session,
14126                    WikiPage wikiPage, long groupId, long userId, long nodeId, int status,
14127                    OrderByComparator orderByComparator, boolean previous) {
14128                    StringBundler query = null;
14129    
14130                    if (orderByComparator != null) {
14131                            query = new StringBundler(6 +
14132                                            (orderByComparator.getOrderByFields().length * 6));
14133                    }
14134                    else {
14135                            query = new StringBundler(3);
14136                    }
14137    
14138                    if (getDB().isSupportsInlineDistinct()) {
14139                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
14140                    }
14141                    else {
14142                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
14143                    }
14144    
14145                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
14146    
14147                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
14148    
14149                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
14150    
14151                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
14152    
14153                    if (!getDB().isSupportsInlineDistinct()) {
14154                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
14155                    }
14156    
14157                    if (orderByComparator != null) {
14158                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14159    
14160                            if (orderByConditionFields.length > 0) {
14161                                    query.append(WHERE_AND);
14162                            }
14163    
14164                            for (int i = 0; i < orderByConditionFields.length; i++) {
14165                                    if (getDB().isSupportsInlineDistinct()) {
14166                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14167                                    }
14168                                    else {
14169                                            query.append(_ORDER_BY_ENTITY_TABLE);
14170                                    }
14171    
14172                                    query.append(orderByConditionFields[i]);
14173    
14174                                    if ((i + 1) < orderByConditionFields.length) {
14175                                            if (orderByComparator.isAscending() ^ previous) {
14176                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14177                                            }
14178                                            else {
14179                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14180                                            }
14181                                    }
14182                                    else {
14183                                            if (orderByComparator.isAscending() ^ previous) {
14184                                                    query.append(WHERE_GREATER_THAN);
14185                                            }
14186                                            else {
14187                                                    query.append(WHERE_LESSER_THAN);
14188                                            }
14189                                    }
14190                            }
14191    
14192                            query.append(ORDER_BY_CLAUSE);
14193    
14194                            String[] orderByFields = orderByComparator.getOrderByFields();
14195    
14196                            for (int i = 0; i < orderByFields.length; i++) {
14197                                    if (getDB().isSupportsInlineDistinct()) {
14198                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14199                                    }
14200                                    else {
14201                                            query.append(_ORDER_BY_ENTITY_TABLE);
14202                                    }
14203    
14204                                    query.append(orderByFields[i]);
14205    
14206                                    if ((i + 1) < orderByFields.length) {
14207                                            if (orderByComparator.isAscending() ^ previous) {
14208                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14209                                            }
14210                                            else {
14211                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14212                                            }
14213                                    }
14214                                    else {
14215                                            if (orderByComparator.isAscending() ^ previous) {
14216                                                    query.append(ORDER_BY_ASC);
14217                                            }
14218                                            else {
14219                                                    query.append(ORDER_BY_DESC);
14220                                            }
14221                                    }
14222                            }
14223                    }
14224                    else {
14225                            if (getDB().isSupportsInlineDistinct()) {
14226                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14227                            }
14228                            else {
14229                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
14230                            }
14231                    }
14232    
14233                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14234                                    WikiPage.class.getName(),
14235                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14236    
14237                    SQLQuery q = session.createSQLQuery(sql);
14238    
14239                    q.setFirstResult(0);
14240                    q.setMaxResults(2);
14241    
14242                    if (getDB().isSupportsInlineDistinct()) {
14243                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
14244                    }
14245                    else {
14246                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
14247                    }
14248    
14249                    QueryPos qPos = QueryPos.getInstance(q);
14250    
14251                    qPos.add(groupId);
14252    
14253                    qPos.add(userId);
14254    
14255                    qPos.add(nodeId);
14256    
14257                    qPos.add(status);
14258    
14259                    if (orderByComparator != null) {
14260                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
14261    
14262                            for (Object value : values) {
14263                                    qPos.add(value);
14264                            }
14265                    }
14266    
14267                    List<WikiPage> list = q.list();
14268    
14269                    if (list.size() == 2) {
14270                            return list.get(1);
14271                    }
14272                    else {
14273                            return null;
14274                    }
14275            }
14276    
14277            /**
14278             * Removes all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63; from the database.
14279             *
14280             * @param groupId the group ID
14281             * @param userId the user ID
14282             * @param nodeId the node ID
14283             * @param status the status
14284             * @throws SystemException if a system exception occurred
14285             */
14286            @Override
14287            public void removeByG_U_N_S(long groupId, long userId, long nodeId,
14288                    int status) throws SystemException {
14289                    for (WikiPage wikiPage : findByG_U_N_S(groupId, userId, nodeId, status,
14290                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14291                            remove(wikiPage);
14292                    }
14293            }
14294    
14295            /**
14296             * Returns the number of wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14297             *
14298             * @param groupId the group ID
14299             * @param userId the user ID
14300             * @param nodeId the node ID
14301             * @param status the status
14302             * @return the number of matching wiki pages
14303             * @throws SystemException if a system exception occurred
14304             */
14305            @Override
14306            public int countByG_U_N_S(long groupId, long userId, long nodeId, int status)
14307                    throws SystemException {
14308                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_N_S;
14309    
14310                    Object[] finderArgs = new Object[] { groupId, userId, nodeId, status };
14311    
14312                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14313                                    this);
14314    
14315                    if (count == null) {
14316                            StringBundler query = new StringBundler(5);
14317    
14318                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
14319    
14320                            query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
14321    
14322                            query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
14323    
14324                            query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
14325    
14326                            query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
14327    
14328                            String sql = query.toString();
14329    
14330                            Session session = null;
14331    
14332                            try {
14333                                    session = openSession();
14334    
14335                                    Query q = session.createQuery(sql);
14336    
14337                                    QueryPos qPos = QueryPos.getInstance(q);
14338    
14339                                    qPos.add(groupId);
14340    
14341                                    qPos.add(userId);
14342    
14343                                    qPos.add(nodeId);
14344    
14345                                    qPos.add(status);
14346    
14347                                    count = (Long)q.uniqueResult();
14348    
14349                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14350                            }
14351                            catch (Exception e) {
14352                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14353    
14354                                    throw processException(e);
14355                            }
14356                            finally {
14357                                    closeSession(session);
14358                            }
14359                    }
14360    
14361                    return count.intValue();
14362            }
14363    
14364            /**
14365             * 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;.
14366             *
14367             * @param groupId the group ID
14368             * @param userId the user ID
14369             * @param nodeId the node ID
14370             * @param status the status
14371             * @return the number of matching wiki pages that the user has permission to view
14372             * @throws SystemException if a system exception occurred
14373             */
14374            @Override
14375            public int filterCountByG_U_N_S(long groupId, long userId, long nodeId,
14376                    int status) throws SystemException {
14377                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14378                            return countByG_U_N_S(groupId, userId, nodeId, status);
14379                    }
14380    
14381                    StringBundler query = new StringBundler(5);
14382    
14383                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
14384    
14385                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
14386    
14387                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
14388    
14389                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
14390    
14391                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
14392    
14393                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14394                                    WikiPage.class.getName(),
14395                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14396    
14397                    Session session = null;
14398    
14399                    try {
14400                            session = openSession();
14401    
14402                            SQLQuery q = session.createSQLQuery(sql);
14403    
14404                            q.addScalar(COUNT_COLUMN_NAME,
14405                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
14406    
14407                            QueryPos qPos = QueryPos.getInstance(q);
14408    
14409                            qPos.add(groupId);
14410    
14411                            qPos.add(userId);
14412    
14413                            qPos.add(nodeId);
14414    
14415                            qPos.add(status);
14416    
14417                            Long count = (Long)q.uniqueResult();
14418    
14419                            return count.intValue();
14420                    }
14421                    catch (Exception e) {
14422                            throw processException(e);
14423                    }
14424                    finally {
14425                            closeSession(session);
14426                    }
14427            }
14428    
14429            private static final String _FINDER_COLUMN_G_U_N_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
14430            private static final String _FINDER_COLUMN_G_U_N_S_USERID_2 = "wikiPage.userId = ? AND ";
14431            private static final String _FINDER_COLUMN_G_U_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
14432            private static final String _FINDER_COLUMN_G_U_N_S_STATUS_2 = "wikiPage.status = ?";
14433            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14434                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
14435                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_T_H",
14436                            new String[] {
14437                                    Long.class.getName(), Long.class.getName(),
14438                                    String.class.getName(), Boolean.class.getName(),
14439                                    
14440                            Integer.class.getName(), Integer.class.getName(),
14441                                    OrderByComparator.class.getName()
14442                            });
14443            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H =
14444                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14445                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
14446                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_T_H",
14447                            new String[] {
14448                                    Long.class.getName(), Long.class.getName(),
14449                                    String.class.getName(), Boolean.class.getName()
14450                            },
14451                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
14452                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
14453                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
14454                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
14455                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
14456            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14457                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14458                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_T_H",
14459                            new String[] {
14460                                    Long.class.getName(), Long.class.getName(),
14461                                    String.class.getName(), Boolean.class.getName()
14462                            });
14463    
14464            /**
14465             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
14466             *
14467             * @param groupId the group ID
14468             * @param nodeId the node ID
14469             * @param title the title
14470             * @param head the head
14471             * @return the matching wiki pages
14472             * @throws SystemException if a system exception occurred
14473             */
14474            @Override
14475            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
14476                    String title, boolean head) throws SystemException {
14477                    return findByG_N_T_H(groupId, nodeId, title, head, QueryUtil.ALL_POS,
14478                            QueryUtil.ALL_POS, null);
14479            }
14480    
14481            /**
14482             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
14483             *
14484             * <p>
14485             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14486             * </p>
14487             *
14488             * @param groupId the group ID
14489             * @param nodeId the node ID
14490             * @param title the title
14491             * @param head the head
14492             * @param start the lower bound of the range of wiki pages
14493             * @param end the upper bound of the range of wiki pages (not inclusive)
14494             * @return the range of matching wiki pages
14495             * @throws SystemException if a system exception occurred
14496             */
14497            @Override
14498            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
14499                    String title, boolean head, int start, int end)
14500                    throws SystemException {
14501                    return findByG_N_T_H(groupId, nodeId, title, head, start, end, null);
14502            }
14503    
14504            /**
14505             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
14506             *
14507             * <p>
14508             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14509             * </p>
14510             *
14511             * @param groupId the group ID
14512             * @param nodeId the node ID
14513             * @param title the title
14514             * @param head the head
14515             * @param start the lower bound of the range of wiki pages
14516             * @param end the upper bound of the range of wiki pages (not inclusive)
14517             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14518             * @return the ordered range of matching wiki pages
14519             * @throws SystemException if a system exception occurred
14520             */
14521            @Override
14522            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
14523                    String title, boolean head, int start, int end,
14524                    OrderByComparator orderByComparator) throws SystemException {
14525                    boolean pagination = true;
14526                    FinderPath finderPath = null;
14527                    Object[] finderArgs = null;
14528    
14529                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14530                                    (orderByComparator == null)) {
14531                            pagination = false;
14532                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H;
14533                            finderArgs = new Object[] { groupId, nodeId, title, head };
14534                    }
14535                    else {
14536                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T_H;
14537                            finderArgs = new Object[] {
14538                                            groupId, nodeId, title, head,
14539                                            
14540                                            start, end, orderByComparator
14541                                    };
14542                    }
14543    
14544                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
14545                                    finderArgs, this);
14546    
14547                    if ((list != null) && !list.isEmpty()) {
14548                            for (WikiPage wikiPage : list) {
14549                                    if ((groupId != wikiPage.getGroupId()) ||
14550                                                    (nodeId != wikiPage.getNodeId()) ||
14551                                                    !Validator.equals(title, wikiPage.getTitle()) ||
14552                                                    (head != wikiPage.getHead())) {
14553                                            list = null;
14554    
14555                                            break;
14556                                    }
14557                            }
14558                    }
14559    
14560                    if (list == null) {
14561                            StringBundler query = null;
14562    
14563                            if (orderByComparator != null) {
14564                                    query = new StringBundler(6 +
14565                                                    (orderByComparator.getOrderByFields().length * 3));
14566                            }
14567                            else {
14568                                    query = new StringBundler(6);
14569                            }
14570    
14571                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
14572    
14573                            query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
14574    
14575                            query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
14576    
14577                            boolean bindTitle = false;
14578    
14579                            if (title == null) {
14580                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
14581                            }
14582                            else if (title.equals(StringPool.BLANK)) {
14583                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
14584                            }
14585                            else {
14586                                    bindTitle = true;
14587    
14588                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
14589                            }
14590    
14591                            query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
14592    
14593                            if (orderByComparator != null) {
14594                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14595                                            orderByComparator);
14596                            }
14597                            else
14598                             if (pagination) {
14599                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14600                            }
14601    
14602                            String sql = query.toString();
14603    
14604                            Session session = null;
14605    
14606                            try {
14607                                    session = openSession();
14608    
14609                                    Query q = session.createQuery(sql);
14610    
14611                                    QueryPos qPos = QueryPos.getInstance(q);
14612    
14613                                    qPos.add(groupId);
14614    
14615                                    qPos.add(nodeId);
14616    
14617                                    if (bindTitle) {
14618                                            qPos.add(title.toLowerCase());
14619                                    }
14620    
14621                                    qPos.add(head);
14622    
14623                                    if (!pagination) {
14624                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
14625                                                            start, end, false);
14626    
14627                                            Collections.sort(list);
14628    
14629                                            list = new UnmodifiableList<WikiPage>(list);
14630                                    }
14631                                    else {
14632                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
14633                                                            start, end);
14634                                    }
14635    
14636                                    cacheResult(list);
14637    
14638                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
14639                            }
14640                            catch (Exception e) {
14641                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14642    
14643                                    throw processException(e);
14644                            }
14645                            finally {
14646                                    closeSession(session);
14647                            }
14648                    }
14649    
14650                    return list;
14651            }
14652    
14653            /**
14654             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
14655             *
14656             * @param groupId the group ID
14657             * @param nodeId the node ID
14658             * @param title the title
14659             * @param head the head
14660             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14661             * @return the first matching wiki page
14662             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
14663             * @throws SystemException if a system exception occurred
14664             */
14665            @Override
14666            public WikiPage findByG_N_T_H_First(long groupId, long nodeId,
14667                    String title, boolean head, OrderByComparator orderByComparator)
14668                    throws NoSuchPageException, SystemException {
14669                    WikiPage wikiPage = fetchByG_N_T_H_First(groupId, nodeId, title, head,
14670                                    orderByComparator);
14671    
14672                    if (wikiPage != null) {
14673                            return wikiPage;
14674                    }
14675    
14676                    StringBundler msg = new StringBundler(10);
14677    
14678                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14679    
14680                    msg.append("groupId=");
14681                    msg.append(groupId);
14682    
14683                    msg.append(", nodeId=");
14684                    msg.append(nodeId);
14685    
14686                    msg.append(", title=");
14687                    msg.append(title);
14688    
14689                    msg.append(", head=");
14690                    msg.append(head);
14691    
14692                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14693    
14694                    throw new NoSuchPageException(msg.toString());
14695            }
14696    
14697            /**
14698             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
14699             *
14700             * @param groupId the group ID
14701             * @param nodeId the node ID
14702             * @param title the title
14703             * @param head the head
14704             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14705             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
14706             * @throws SystemException if a system exception occurred
14707             */
14708            @Override
14709            public WikiPage fetchByG_N_T_H_First(long groupId, long nodeId,
14710                    String title, boolean head, OrderByComparator orderByComparator)
14711                    throws SystemException {
14712                    List<WikiPage> list = findByG_N_T_H(groupId, nodeId, title, head, 0, 1,
14713                                    orderByComparator);
14714    
14715                    if (!list.isEmpty()) {
14716                            return list.get(0);
14717                    }
14718    
14719                    return null;
14720            }
14721    
14722            /**
14723             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
14724             *
14725             * @param groupId the group ID
14726             * @param nodeId the node ID
14727             * @param title the title
14728             * @param head the head
14729             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14730             * @return the last matching wiki page
14731             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
14732             * @throws SystemException if a system exception occurred
14733             */
14734            @Override
14735            public WikiPage findByG_N_T_H_Last(long groupId, long nodeId, String title,
14736                    boolean head, OrderByComparator orderByComparator)
14737                    throws NoSuchPageException, SystemException {
14738                    WikiPage wikiPage = fetchByG_N_T_H_Last(groupId, nodeId, title, head,
14739                                    orderByComparator);
14740    
14741                    if (wikiPage != null) {
14742                            return wikiPage;
14743                    }
14744    
14745                    StringBundler msg = new StringBundler(10);
14746    
14747                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14748    
14749                    msg.append("groupId=");
14750                    msg.append(groupId);
14751    
14752                    msg.append(", nodeId=");
14753                    msg.append(nodeId);
14754    
14755                    msg.append(", title=");
14756                    msg.append(title);
14757    
14758                    msg.append(", head=");
14759                    msg.append(head);
14760    
14761                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14762    
14763                    throw new NoSuchPageException(msg.toString());
14764            }
14765    
14766            /**
14767             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
14768             *
14769             * @param groupId the group ID
14770             * @param nodeId the node ID
14771             * @param title the title
14772             * @param head the head
14773             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14774             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
14775             * @throws SystemException if a system exception occurred
14776             */
14777            @Override
14778            public WikiPage fetchByG_N_T_H_Last(long groupId, long nodeId,
14779                    String title, boolean head, OrderByComparator orderByComparator)
14780                    throws SystemException {
14781                    int count = countByG_N_T_H(groupId, nodeId, title, head);
14782    
14783                    if (count == 0) {
14784                            return null;
14785                    }
14786    
14787                    List<WikiPage> list = findByG_N_T_H(groupId, nodeId, title, head,
14788                                    count - 1, count, orderByComparator);
14789    
14790                    if (!list.isEmpty()) {
14791                            return list.get(0);
14792                    }
14793    
14794                    return null;
14795            }
14796    
14797            /**
14798             * 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;.
14799             *
14800             * @param pageId the primary key of the current wiki page
14801             * @param groupId the group ID
14802             * @param nodeId the node ID
14803             * @param title the title
14804             * @param head the head
14805             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14806             * @return the previous, current, and next wiki page
14807             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
14808             * @throws SystemException if a system exception occurred
14809             */
14810            @Override
14811            public WikiPage[] findByG_N_T_H_PrevAndNext(long pageId, long groupId,
14812                    long nodeId, String title, boolean head,
14813                    OrderByComparator orderByComparator)
14814                    throws NoSuchPageException, SystemException {
14815                    WikiPage wikiPage = findByPrimaryKey(pageId);
14816    
14817                    Session session = null;
14818    
14819                    try {
14820                            session = openSession();
14821    
14822                            WikiPage[] array = new WikiPageImpl[3];
14823    
14824                            array[0] = getByG_N_T_H_PrevAndNext(session, wikiPage, groupId,
14825                                            nodeId, title, head, orderByComparator, true);
14826    
14827                            array[1] = wikiPage;
14828    
14829                            array[2] = getByG_N_T_H_PrevAndNext(session, wikiPage, groupId,
14830                                            nodeId, title, head, orderByComparator, false);
14831    
14832                            return array;
14833                    }
14834                    catch (Exception e) {
14835                            throw processException(e);
14836                    }
14837                    finally {
14838                            closeSession(session);
14839                    }
14840            }
14841    
14842            protected WikiPage getByG_N_T_H_PrevAndNext(Session session,
14843                    WikiPage wikiPage, long groupId, long nodeId, String title,
14844                    boolean head, OrderByComparator orderByComparator, boolean previous) {
14845                    StringBundler query = null;
14846    
14847                    if (orderByComparator != null) {
14848                            query = new StringBundler(6 +
14849                                            (orderByComparator.getOrderByFields().length * 6));
14850                    }
14851                    else {
14852                            query = new StringBundler(3);
14853                    }
14854    
14855                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
14856    
14857                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
14858    
14859                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
14860    
14861                    boolean bindTitle = false;
14862    
14863                    if (title == null) {
14864                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
14865                    }
14866                    else if (title.equals(StringPool.BLANK)) {
14867                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
14868                    }
14869                    else {
14870                            bindTitle = true;
14871    
14872                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
14873                    }
14874    
14875                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
14876    
14877                    if (orderByComparator != null) {
14878                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14879    
14880                            if (orderByConditionFields.length > 0) {
14881                                    query.append(WHERE_AND);
14882                            }
14883    
14884                            for (int i = 0; i < orderByConditionFields.length; i++) {
14885                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14886                                    query.append(orderByConditionFields[i]);
14887    
14888                                    if ((i + 1) < orderByConditionFields.length) {
14889                                            if (orderByComparator.isAscending() ^ previous) {
14890                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14891                                            }
14892                                            else {
14893                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14894                                            }
14895                                    }
14896                                    else {
14897                                            if (orderByComparator.isAscending() ^ previous) {
14898                                                    query.append(WHERE_GREATER_THAN);
14899                                            }
14900                                            else {
14901                                                    query.append(WHERE_LESSER_THAN);
14902                                            }
14903                                    }
14904                            }
14905    
14906                            query.append(ORDER_BY_CLAUSE);
14907    
14908                            String[] orderByFields = orderByComparator.getOrderByFields();
14909    
14910                            for (int i = 0; i < orderByFields.length; i++) {
14911                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14912                                    query.append(orderByFields[i]);
14913    
14914                                    if ((i + 1) < orderByFields.length) {
14915                                            if (orderByComparator.isAscending() ^ previous) {
14916                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14917                                            }
14918                                            else {
14919                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14920                                            }
14921                                    }
14922                                    else {
14923                                            if (orderByComparator.isAscending() ^ previous) {
14924                                                    query.append(ORDER_BY_ASC);
14925                                            }
14926                                            else {
14927                                                    query.append(ORDER_BY_DESC);
14928                                            }
14929                                    }
14930                            }
14931                    }
14932                    else {
14933                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14934                    }
14935    
14936                    String sql = query.toString();
14937    
14938                    Query q = session.createQuery(sql);
14939    
14940                    q.setFirstResult(0);
14941                    q.setMaxResults(2);
14942    
14943                    QueryPos qPos = QueryPos.getInstance(q);
14944    
14945                    qPos.add(groupId);
14946    
14947                    qPos.add(nodeId);
14948    
14949                    if (bindTitle) {
14950                            qPos.add(title.toLowerCase());
14951                    }
14952    
14953                    qPos.add(head);
14954    
14955                    if (orderByComparator != null) {
14956                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
14957    
14958                            for (Object value : values) {
14959                                    qPos.add(value);
14960                            }
14961                    }
14962    
14963                    List<WikiPage> list = q.list();
14964    
14965                    if (list.size() == 2) {
14966                            return list.get(1);
14967                    }
14968                    else {
14969                            return null;
14970                    }
14971            }
14972    
14973            /**
14974             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
14975             *
14976             * @param groupId the group ID
14977             * @param nodeId the node ID
14978             * @param title the title
14979             * @param head the head
14980             * @return the matching wiki pages that the user has permission to view
14981             * @throws SystemException if a system exception occurred
14982             */
14983            @Override
14984            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
14985                    String title, boolean head) throws SystemException {
14986                    return filterFindByG_N_T_H(groupId, nodeId, title, head,
14987                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14988            }
14989    
14990            /**
14991             * 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;.
14992             *
14993             * <p>
14994             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14995             * </p>
14996             *
14997             * @param groupId the group ID
14998             * @param nodeId the node ID
14999             * @param title the title
15000             * @param head the head
15001             * @param start the lower bound of the range of wiki pages
15002             * @param end the upper bound of the range of wiki pages (not inclusive)
15003             * @return the range of matching wiki pages that the user has permission to view
15004             * @throws SystemException if a system exception occurred
15005             */
15006            @Override
15007            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
15008                    String title, boolean head, int start, int end)
15009                    throws SystemException {
15010                    return filterFindByG_N_T_H(groupId, nodeId, title, head, start, end,
15011                            null);
15012            }
15013    
15014            /**
15015             * 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;.
15016             *
15017             * <p>
15018             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15019             * </p>
15020             *
15021             * @param groupId the group ID
15022             * @param nodeId the node ID
15023             * @param title the title
15024             * @param head the head
15025             * @param start the lower bound of the range of wiki pages
15026             * @param end the upper bound of the range of wiki pages (not inclusive)
15027             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15028             * @return the ordered range of matching wiki pages that the user has permission to view
15029             * @throws SystemException if a system exception occurred
15030             */
15031            @Override
15032            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
15033                    String title, boolean head, int start, int end,
15034                    OrderByComparator orderByComparator) throws SystemException {
15035                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15036                            return findByG_N_T_H(groupId, nodeId, title, head, start, end,
15037                                    orderByComparator);
15038                    }
15039    
15040                    StringBundler query = null;
15041    
15042                    if (orderByComparator != null) {
15043                            query = new StringBundler(6 +
15044                                            (orderByComparator.getOrderByFields().length * 3));
15045                    }
15046                    else {
15047                            query = new StringBundler(6);
15048                    }
15049    
15050                    if (getDB().isSupportsInlineDistinct()) {
15051                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
15052                    }
15053                    else {
15054                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
15055                    }
15056    
15057                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
15058    
15059                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
15060    
15061                    boolean bindTitle = false;
15062    
15063                    if (title == null) {
15064                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
15065                    }
15066                    else if (title.equals(StringPool.BLANK)) {
15067                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
15068                    }
15069                    else {
15070                            bindTitle = true;
15071    
15072                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
15073                    }
15074    
15075                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
15076    
15077                    if (!getDB().isSupportsInlineDistinct()) {
15078                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
15079                    }
15080    
15081                    if (orderByComparator != null) {
15082                            if (getDB().isSupportsInlineDistinct()) {
15083                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15084                                            orderByComparator, true);
15085                            }
15086                            else {
15087                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
15088                                            orderByComparator, true);
15089                            }
15090                    }
15091                    else {
15092                            if (getDB().isSupportsInlineDistinct()) {
15093                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15094                            }
15095                            else {
15096                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
15097                            }
15098                    }
15099    
15100                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15101                                    WikiPage.class.getName(),
15102                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15103    
15104                    Session session = null;
15105    
15106                    try {
15107                            session = openSession();
15108    
15109                            SQLQuery q = session.createSQLQuery(sql);
15110    
15111                            if (getDB().isSupportsInlineDistinct()) {
15112                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
15113                            }
15114                            else {
15115                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
15116                            }
15117    
15118                            QueryPos qPos = QueryPos.getInstance(q);
15119    
15120                            qPos.add(groupId);
15121    
15122                            qPos.add(nodeId);
15123    
15124                            if (bindTitle) {
15125                                    qPos.add(title.toLowerCase());
15126                            }
15127    
15128                            qPos.add(head);
15129    
15130                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
15131                    }
15132                    catch (Exception e) {
15133                            throw processException(e);
15134                    }
15135                    finally {
15136                            closeSession(session);
15137                    }
15138            }
15139    
15140            /**
15141             * 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;.
15142             *
15143             * @param pageId the primary key of the current wiki page
15144             * @param groupId the group ID
15145             * @param nodeId the node ID
15146             * @param title the title
15147             * @param head the head
15148             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15149             * @return the previous, current, and next wiki page
15150             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
15151             * @throws SystemException if a system exception occurred
15152             */
15153            @Override
15154            public WikiPage[] filterFindByG_N_T_H_PrevAndNext(long pageId,
15155                    long groupId, long nodeId, String title, boolean head,
15156                    OrderByComparator orderByComparator)
15157                    throws NoSuchPageException, SystemException {
15158                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15159                            return findByG_N_T_H_PrevAndNext(pageId, groupId, nodeId, title,
15160                                    head, orderByComparator);
15161                    }
15162    
15163                    WikiPage wikiPage = findByPrimaryKey(pageId);
15164    
15165                    Session session = null;
15166    
15167                    try {
15168                            session = openSession();
15169    
15170                            WikiPage[] array = new WikiPageImpl[3];
15171    
15172                            array[0] = filterGetByG_N_T_H_PrevAndNext(session, wikiPage,
15173                                            groupId, nodeId, title, head, orderByComparator, true);
15174    
15175                            array[1] = wikiPage;
15176    
15177                            array[2] = filterGetByG_N_T_H_PrevAndNext(session, wikiPage,
15178                                            groupId, nodeId, title, head, orderByComparator, false);
15179    
15180                            return array;
15181                    }
15182                    catch (Exception e) {
15183                            throw processException(e);
15184                    }
15185                    finally {
15186                            closeSession(session);
15187                    }
15188            }
15189    
15190            protected WikiPage filterGetByG_N_T_H_PrevAndNext(Session session,
15191                    WikiPage wikiPage, long groupId, long nodeId, String title,
15192                    boolean head, OrderByComparator orderByComparator, boolean previous) {
15193                    StringBundler query = null;
15194    
15195                    if (orderByComparator != null) {
15196                            query = new StringBundler(6 +
15197                                            (orderByComparator.getOrderByFields().length * 6));
15198                    }
15199                    else {
15200                            query = new StringBundler(3);
15201                    }
15202    
15203                    if (getDB().isSupportsInlineDistinct()) {
15204                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
15205                    }
15206                    else {
15207                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
15208                    }
15209    
15210                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
15211    
15212                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
15213    
15214                    boolean bindTitle = false;
15215    
15216                    if (title == null) {
15217                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
15218                    }
15219                    else if (title.equals(StringPool.BLANK)) {
15220                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
15221                    }
15222                    else {
15223                            bindTitle = true;
15224    
15225                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
15226                    }
15227    
15228                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
15229    
15230                    if (!getDB().isSupportsInlineDistinct()) {
15231                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
15232                    }
15233    
15234                    if (orderByComparator != null) {
15235                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15236    
15237                            if (orderByConditionFields.length > 0) {
15238                                    query.append(WHERE_AND);
15239                            }
15240    
15241                            for (int i = 0; i < orderByConditionFields.length; i++) {
15242                                    if (getDB().isSupportsInlineDistinct()) {
15243                                            query.append(_ORDER_BY_ENTITY_ALIAS);
15244                                    }
15245                                    else {
15246                                            query.append(_ORDER_BY_ENTITY_TABLE);
15247                                    }
15248    
15249                                    query.append(orderByConditionFields[i]);
15250    
15251                                    if ((i + 1) < orderByConditionFields.length) {
15252                                            if (orderByComparator.isAscending() ^ previous) {
15253                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15254                                            }
15255                                            else {
15256                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15257                                            }
15258                                    }
15259                                    else {
15260                                            if (orderByComparator.isAscending() ^ previous) {
15261                                                    query.append(WHERE_GREATER_THAN);
15262                                            }
15263                                            else {
15264                                                    query.append(WHERE_LESSER_THAN);
15265                                            }
15266                                    }
15267                            }
15268    
15269                            query.append(ORDER_BY_CLAUSE);
15270    
15271                            String[] orderByFields = orderByComparator.getOrderByFields();
15272    
15273                            for (int i = 0; i < orderByFields.length; i++) {
15274                                    if (getDB().isSupportsInlineDistinct()) {
15275                                            query.append(_ORDER_BY_ENTITY_ALIAS);
15276                                    }
15277                                    else {
15278                                            query.append(_ORDER_BY_ENTITY_TABLE);
15279                                    }
15280    
15281                                    query.append(orderByFields[i]);
15282    
15283                                    if ((i + 1) < orderByFields.length) {
15284                                            if (orderByComparator.isAscending() ^ previous) {
15285                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15286                                            }
15287                                            else {
15288                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15289                                            }
15290                                    }
15291                                    else {
15292                                            if (orderByComparator.isAscending() ^ previous) {
15293                                                    query.append(ORDER_BY_ASC);
15294                                            }
15295                                            else {
15296                                                    query.append(ORDER_BY_DESC);
15297                                            }
15298                                    }
15299                            }
15300                    }
15301                    else {
15302                            if (getDB().isSupportsInlineDistinct()) {
15303                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15304                            }
15305                            else {
15306                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
15307                            }
15308                    }
15309    
15310                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15311                                    WikiPage.class.getName(),
15312                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15313    
15314                    SQLQuery q = session.createSQLQuery(sql);
15315    
15316                    q.setFirstResult(0);
15317                    q.setMaxResults(2);
15318    
15319                    if (getDB().isSupportsInlineDistinct()) {
15320                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
15321                    }
15322                    else {
15323                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
15324                    }
15325    
15326                    QueryPos qPos = QueryPos.getInstance(q);
15327    
15328                    qPos.add(groupId);
15329    
15330                    qPos.add(nodeId);
15331    
15332                    if (bindTitle) {
15333                            qPos.add(title.toLowerCase());
15334                    }
15335    
15336                    qPos.add(head);
15337    
15338                    if (orderByComparator != null) {
15339                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
15340    
15341                            for (Object value : values) {
15342                                    qPos.add(value);
15343                            }
15344                    }
15345    
15346                    List<WikiPage> list = q.list();
15347    
15348                    if (list.size() == 2) {
15349                            return list.get(1);
15350                    }
15351                    else {
15352                            return null;
15353                    }
15354            }
15355    
15356            /**
15357             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63; from the database.
15358             *
15359             * @param groupId the group ID
15360             * @param nodeId the node ID
15361             * @param title the title
15362             * @param head the head
15363             * @throws SystemException if a system exception occurred
15364             */
15365            @Override
15366            public void removeByG_N_T_H(long groupId, long nodeId, String title,
15367                    boolean head) throws SystemException {
15368                    for (WikiPage wikiPage : findByG_N_T_H(groupId, nodeId, title, head,
15369                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15370                            remove(wikiPage);
15371                    }
15372            }
15373    
15374            /**
15375             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15376             *
15377             * @param groupId the group ID
15378             * @param nodeId the node ID
15379             * @param title the title
15380             * @param head the head
15381             * @return the number of matching wiki pages
15382             * @throws SystemException if a system exception occurred
15383             */
15384            @Override
15385            public int countByG_N_T_H(long groupId, long nodeId, String title,
15386                    boolean head) throws SystemException {
15387                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_T_H;
15388    
15389                    Object[] finderArgs = new Object[] { groupId, nodeId, title, head };
15390    
15391                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15392                                    this);
15393    
15394                    if (count == null) {
15395                            StringBundler query = new StringBundler(5);
15396    
15397                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
15398    
15399                            query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
15400    
15401                            query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
15402    
15403                            boolean bindTitle = false;
15404    
15405                            if (title == null) {
15406                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
15407                            }
15408                            else if (title.equals(StringPool.BLANK)) {
15409                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
15410                            }
15411                            else {
15412                                    bindTitle = true;
15413    
15414                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
15415                            }
15416    
15417                            query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
15418    
15419                            String sql = query.toString();
15420    
15421                            Session session = null;
15422    
15423                            try {
15424                                    session = openSession();
15425    
15426                                    Query q = session.createQuery(sql);
15427    
15428                                    QueryPos qPos = QueryPos.getInstance(q);
15429    
15430                                    qPos.add(groupId);
15431    
15432                                    qPos.add(nodeId);
15433    
15434                                    if (bindTitle) {
15435                                            qPos.add(title.toLowerCase());
15436                                    }
15437    
15438                                    qPos.add(head);
15439    
15440                                    count = (Long)q.uniqueResult();
15441    
15442                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15443                            }
15444                            catch (Exception e) {
15445                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15446    
15447                                    throw processException(e);
15448                            }
15449                            finally {
15450                                    closeSession(session);
15451                            }
15452                    }
15453    
15454                    return count.intValue();
15455            }
15456    
15457            /**
15458             * 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;.
15459             *
15460             * @param groupId the group ID
15461             * @param nodeId the node ID
15462             * @param title the title
15463             * @param head the head
15464             * @return the number of matching wiki pages that the user has permission to view
15465             * @throws SystemException if a system exception occurred
15466             */
15467            @Override
15468            public int filterCountByG_N_T_H(long groupId, long nodeId, String title,
15469                    boolean head) throws SystemException {
15470                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15471                            return countByG_N_T_H(groupId, nodeId, title, head);
15472                    }
15473    
15474                    StringBundler query = new StringBundler(5);
15475    
15476                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
15477    
15478                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
15479    
15480                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
15481    
15482                    boolean bindTitle = false;
15483    
15484                    if (title == null) {
15485                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
15486                    }
15487                    else if (title.equals(StringPool.BLANK)) {
15488                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
15489                    }
15490                    else {
15491                            bindTitle = true;
15492    
15493                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
15494                    }
15495    
15496                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
15497    
15498                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15499                                    WikiPage.class.getName(),
15500                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15501    
15502                    Session session = null;
15503    
15504                    try {
15505                            session = openSession();
15506    
15507                            SQLQuery q = session.createSQLQuery(sql);
15508    
15509                            q.addScalar(COUNT_COLUMN_NAME,
15510                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
15511    
15512                            QueryPos qPos = QueryPos.getInstance(q);
15513    
15514                            qPos.add(groupId);
15515    
15516                            qPos.add(nodeId);
15517    
15518                            if (bindTitle) {
15519                                    qPos.add(title.toLowerCase());
15520                            }
15521    
15522                            qPos.add(head);
15523    
15524                            Long count = (Long)q.uniqueResult();
15525    
15526                            return count.intValue();
15527                    }
15528                    catch (Exception e) {
15529                            throw processException(e);
15530                    }
15531                    finally {
15532                            closeSession(session);
15533                    }
15534            }
15535    
15536            private static final String _FINDER_COLUMN_G_N_T_H_GROUPID_2 = "wikiPage.groupId = ? AND ";
15537            private static final String _FINDER_COLUMN_G_N_T_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
15538            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_1 = "wikiPage.title IS NULL AND ";
15539            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_2 = "lower(wikiPage.title) = ? AND ";
15540            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '') AND ";
15541            private static final String _FINDER_COLUMN_G_N_T_H_HEAD_2 = "wikiPage.head = ?";
15542            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15543                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
15544                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H_S",
15545                            new String[] {
15546                                    Long.class.getName(), Long.class.getName(),
15547                                    Boolean.class.getName(), Integer.class.getName(),
15548                                    
15549                            Integer.class.getName(), Integer.class.getName(),
15550                                    OrderByComparator.class.getName()
15551                            });
15552            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S =
15553                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15554                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
15555                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H_S",
15556                            new String[] {
15557                                    Long.class.getName(), Long.class.getName(),
15558                                    Boolean.class.getName(), Integer.class.getName()
15559                            },
15560                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
15561                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
15562                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
15563                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
15564                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
15565                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
15566            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15567                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15568                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H_S",
15569                            new String[] {
15570                                    Long.class.getName(), Long.class.getName(),
15571                                    Boolean.class.getName(), Integer.class.getName()
15572                            });
15573    
15574            /**
15575             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
15576             *
15577             * @param groupId the group ID
15578             * @param nodeId the node ID
15579             * @param head the head
15580             * @param status the status
15581             * @return the matching wiki pages
15582             * @throws SystemException if a system exception occurred
15583             */
15584            @Override
15585            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
15586                    boolean head, int status) throws SystemException {
15587                    return findByG_N_H_S(groupId, nodeId, head, status, QueryUtil.ALL_POS,
15588                            QueryUtil.ALL_POS, null);
15589            }
15590    
15591            /**
15592             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
15593             *
15594             * <p>
15595             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15596             * </p>
15597             *
15598             * @param groupId the group ID
15599             * @param nodeId the node ID
15600             * @param head the head
15601             * @param status the status
15602             * @param start the lower bound of the range of wiki pages
15603             * @param end the upper bound of the range of wiki pages (not inclusive)
15604             * @return the range of matching wiki pages
15605             * @throws SystemException if a system exception occurred
15606             */
15607            @Override
15608            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
15609                    boolean head, int status, int start, int end) throws SystemException {
15610                    return findByG_N_H_S(groupId, nodeId, head, status, start, end, null);
15611            }
15612    
15613            /**
15614             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
15615             *
15616             * <p>
15617             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15618             * </p>
15619             *
15620             * @param groupId the group ID
15621             * @param nodeId the node ID
15622             * @param head the head
15623             * @param status the status
15624             * @param start the lower bound of the range of wiki pages
15625             * @param end the upper bound of the range of wiki pages (not inclusive)
15626             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15627             * @return the ordered range of matching wiki pages
15628             * @throws SystemException if a system exception occurred
15629             */
15630            @Override
15631            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
15632                    boolean head, int status, int start, int end,
15633                    OrderByComparator orderByComparator) throws SystemException {
15634                    boolean pagination = true;
15635                    FinderPath finderPath = null;
15636                    Object[] finderArgs = null;
15637    
15638                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15639                                    (orderByComparator == null)) {
15640                            pagination = false;
15641                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S;
15642                            finderArgs = new Object[] { groupId, nodeId, head, status };
15643                    }
15644                    else {
15645                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_S;
15646                            finderArgs = new Object[] {
15647                                            groupId, nodeId, head, status,
15648                                            
15649                                            start, end, orderByComparator
15650                                    };
15651                    }
15652    
15653                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
15654                                    finderArgs, this);
15655    
15656                    if ((list != null) && !list.isEmpty()) {
15657                            for (WikiPage wikiPage : list) {
15658                                    if ((groupId != wikiPage.getGroupId()) ||
15659                                                    (nodeId != wikiPage.getNodeId()) ||
15660                                                    (head != wikiPage.getHead()) ||
15661                                                    (status != wikiPage.getStatus())) {
15662                                            list = null;
15663    
15664                                            break;
15665                                    }
15666                            }
15667                    }
15668    
15669                    if (list == null) {
15670                            StringBundler query = null;
15671    
15672                            if (orderByComparator != null) {
15673                                    query = new StringBundler(6 +
15674                                                    (orderByComparator.getOrderByFields().length * 3));
15675                            }
15676                            else {
15677                                    query = new StringBundler(6);
15678                            }
15679    
15680                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
15681    
15682                            query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
15683    
15684                            query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
15685    
15686                            query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
15687    
15688                            query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
15689    
15690                            if (orderByComparator != null) {
15691                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15692                                            orderByComparator);
15693                            }
15694                            else
15695                             if (pagination) {
15696                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15697                            }
15698    
15699                            String sql = query.toString();
15700    
15701                            Session session = null;
15702    
15703                            try {
15704                                    session = openSession();
15705    
15706                                    Query q = session.createQuery(sql);
15707    
15708                                    QueryPos qPos = QueryPos.getInstance(q);
15709    
15710                                    qPos.add(groupId);
15711    
15712                                    qPos.add(nodeId);
15713    
15714                                    qPos.add(head);
15715    
15716                                    qPos.add(status);
15717    
15718                                    if (!pagination) {
15719                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
15720                                                            start, end, false);
15721    
15722                                            Collections.sort(list);
15723    
15724                                            list = new UnmodifiableList<WikiPage>(list);
15725                                    }
15726                                    else {
15727                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
15728                                                            start, end);
15729                                    }
15730    
15731                                    cacheResult(list);
15732    
15733                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15734                            }
15735                            catch (Exception e) {
15736                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15737    
15738                                    throw processException(e);
15739                            }
15740                            finally {
15741                                    closeSession(session);
15742                            }
15743                    }
15744    
15745                    return list;
15746            }
15747    
15748            /**
15749             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
15750             *
15751             * @param groupId the group ID
15752             * @param nodeId the node ID
15753             * @param head the head
15754             * @param status the status
15755             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15756             * @return the first matching wiki page
15757             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
15758             * @throws SystemException if a system exception occurred
15759             */
15760            @Override
15761            public WikiPage findByG_N_H_S_First(long groupId, long nodeId,
15762                    boolean head, int status, OrderByComparator orderByComparator)
15763                    throws NoSuchPageException, SystemException {
15764                    WikiPage wikiPage = fetchByG_N_H_S_First(groupId, nodeId, head, status,
15765                                    orderByComparator);
15766    
15767                    if (wikiPage != null) {
15768                            return wikiPage;
15769                    }
15770    
15771                    StringBundler msg = new StringBundler(10);
15772    
15773                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15774    
15775                    msg.append("groupId=");
15776                    msg.append(groupId);
15777    
15778                    msg.append(", nodeId=");
15779                    msg.append(nodeId);
15780    
15781                    msg.append(", head=");
15782                    msg.append(head);
15783    
15784                    msg.append(", status=");
15785                    msg.append(status);
15786    
15787                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15788    
15789                    throw new NoSuchPageException(msg.toString());
15790            }
15791    
15792            /**
15793             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
15794             *
15795             * @param groupId the group ID
15796             * @param nodeId the node ID
15797             * @param head the head
15798             * @param status the status
15799             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15800             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
15801             * @throws SystemException if a system exception occurred
15802             */
15803            @Override
15804            public WikiPage fetchByG_N_H_S_First(long groupId, long nodeId,
15805                    boolean head, int status, OrderByComparator orderByComparator)
15806                    throws SystemException {
15807                    List<WikiPage> list = findByG_N_H_S(groupId, nodeId, head, status, 0,
15808                                    1, orderByComparator);
15809    
15810                    if (!list.isEmpty()) {
15811                            return list.get(0);
15812                    }
15813    
15814                    return null;
15815            }
15816    
15817            /**
15818             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
15819             *
15820             * @param groupId the group ID
15821             * @param nodeId the node ID
15822             * @param head the head
15823             * @param status the status
15824             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15825             * @return the last matching wiki page
15826             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
15827             * @throws SystemException if a system exception occurred
15828             */
15829            @Override
15830            public WikiPage findByG_N_H_S_Last(long groupId, long nodeId, boolean head,
15831                    int status, OrderByComparator orderByComparator)
15832                    throws NoSuchPageException, SystemException {
15833                    WikiPage wikiPage = fetchByG_N_H_S_Last(groupId, nodeId, head, status,
15834                                    orderByComparator);
15835    
15836                    if (wikiPage != null) {
15837                            return wikiPage;
15838                    }
15839    
15840                    StringBundler msg = new StringBundler(10);
15841    
15842                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15843    
15844                    msg.append("groupId=");
15845                    msg.append(groupId);
15846    
15847                    msg.append(", nodeId=");
15848                    msg.append(nodeId);
15849    
15850                    msg.append(", head=");
15851                    msg.append(head);
15852    
15853                    msg.append(", status=");
15854                    msg.append(status);
15855    
15856                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15857    
15858                    throw new NoSuchPageException(msg.toString());
15859            }
15860    
15861            /**
15862             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
15863             *
15864             * @param groupId the group ID
15865             * @param nodeId the node ID
15866             * @param head the head
15867             * @param status the status
15868             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15869             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
15870             * @throws SystemException if a system exception occurred
15871             */
15872            @Override
15873            public WikiPage fetchByG_N_H_S_Last(long groupId, long nodeId,
15874                    boolean head, int status, OrderByComparator orderByComparator)
15875                    throws SystemException {
15876                    int count = countByG_N_H_S(groupId, nodeId, head, status);
15877    
15878                    if (count == 0) {
15879                            return null;
15880                    }
15881    
15882                    List<WikiPage> list = findByG_N_H_S(groupId, nodeId, head, status,
15883                                    count - 1, count, orderByComparator);
15884    
15885                    if (!list.isEmpty()) {
15886                            return list.get(0);
15887                    }
15888    
15889                    return null;
15890            }
15891    
15892            /**
15893             * 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;.
15894             *
15895             * @param pageId the primary key of the current wiki page
15896             * @param groupId the group ID
15897             * @param nodeId the node ID
15898             * @param head the head
15899             * @param status the status
15900             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15901             * @return the previous, current, and next wiki page
15902             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
15903             * @throws SystemException if a system exception occurred
15904             */
15905            @Override
15906            public WikiPage[] findByG_N_H_S_PrevAndNext(long pageId, long groupId,
15907                    long nodeId, boolean head, int status,
15908                    OrderByComparator orderByComparator)
15909                    throws NoSuchPageException, SystemException {
15910                    WikiPage wikiPage = findByPrimaryKey(pageId);
15911    
15912                    Session session = null;
15913    
15914                    try {
15915                            session = openSession();
15916    
15917                            WikiPage[] array = new WikiPageImpl[3];
15918    
15919                            array[0] = getByG_N_H_S_PrevAndNext(session, wikiPage, groupId,
15920                                            nodeId, head, status, orderByComparator, true);
15921    
15922                            array[1] = wikiPage;
15923    
15924                            array[2] = getByG_N_H_S_PrevAndNext(session, wikiPage, groupId,
15925                                            nodeId, head, status, orderByComparator, false);
15926    
15927                            return array;
15928                    }
15929                    catch (Exception e) {
15930                            throw processException(e);
15931                    }
15932                    finally {
15933                            closeSession(session);
15934                    }
15935            }
15936    
15937            protected WikiPage getByG_N_H_S_PrevAndNext(Session session,
15938                    WikiPage wikiPage, long groupId, long nodeId, boolean head, int status,
15939                    OrderByComparator orderByComparator, boolean previous) {
15940                    StringBundler query = null;
15941    
15942                    if (orderByComparator != null) {
15943                            query = new StringBundler(6 +
15944                                            (orderByComparator.getOrderByFields().length * 6));
15945                    }
15946                    else {
15947                            query = new StringBundler(3);
15948                    }
15949    
15950                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
15951    
15952                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
15953    
15954                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
15955    
15956                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
15957    
15958                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
15959    
15960                    if (orderByComparator != null) {
15961                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15962    
15963                            if (orderByConditionFields.length > 0) {
15964                                    query.append(WHERE_AND);
15965                            }
15966    
15967                            for (int i = 0; i < orderByConditionFields.length; i++) {
15968                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15969                                    query.append(orderByConditionFields[i]);
15970    
15971                                    if ((i + 1) < orderByConditionFields.length) {
15972                                            if (orderByComparator.isAscending() ^ previous) {
15973                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15974                                            }
15975                                            else {
15976                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15977                                            }
15978                                    }
15979                                    else {
15980                                            if (orderByComparator.isAscending() ^ previous) {
15981                                                    query.append(WHERE_GREATER_THAN);
15982                                            }
15983                                            else {
15984                                                    query.append(WHERE_LESSER_THAN);
15985                                            }
15986                                    }
15987                            }
15988    
15989                            query.append(ORDER_BY_CLAUSE);
15990    
15991                            String[] orderByFields = orderByComparator.getOrderByFields();
15992    
15993                            for (int i = 0; i < orderByFields.length; i++) {
15994                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15995                                    query.append(orderByFields[i]);
15996    
15997                                    if ((i + 1) < orderByFields.length) {
15998                                            if (orderByComparator.isAscending() ^ previous) {
15999                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16000                                            }
16001                                            else {
16002                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16003                                            }
16004                                    }
16005                                    else {
16006                                            if (orderByComparator.isAscending() ^ previous) {
16007                                                    query.append(ORDER_BY_ASC);
16008                                            }
16009                                            else {
16010                                                    query.append(ORDER_BY_DESC);
16011                                            }
16012                                    }
16013                            }
16014                    }
16015                    else {
16016                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16017                    }
16018    
16019                    String sql = query.toString();
16020    
16021                    Query q = session.createQuery(sql);
16022    
16023                    q.setFirstResult(0);
16024                    q.setMaxResults(2);
16025    
16026                    QueryPos qPos = QueryPos.getInstance(q);
16027    
16028                    qPos.add(groupId);
16029    
16030                    qPos.add(nodeId);
16031    
16032                    qPos.add(head);
16033    
16034                    qPos.add(status);
16035    
16036                    if (orderByComparator != null) {
16037                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
16038    
16039                            for (Object value : values) {
16040                                    qPos.add(value);
16041                            }
16042                    }
16043    
16044                    List<WikiPage> list = q.list();
16045    
16046                    if (list.size() == 2) {
16047                            return list.get(1);
16048                    }
16049                    else {
16050                            return null;
16051                    }
16052            }
16053    
16054            /**
16055             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16056             *
16057             * @param groupId the group ID
16058             * @param nodeId the node ID
16059             * @param head the head
16060             * @param status the status
16061             * @return the matching wiki pages that the user has permission to view
16062             * @throws SystemException if a system exception occurred
16063             */
16064            @Override
16065            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
16066                    boolean head, int status) throws SystemException {
16067                    return filterFindByG_N_H_S(groupId, nodeId, head, status,
16068                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16069            }
16070    
16071            /**
16072             * 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;.
16073             *
16074             * <p>
16075             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16076             * </p>
16077             *
16078             * @param groupId the group ID
16079             * @param nodeId the node ID
16080             * @param head the head
16081             * @param status the status
16082             * @param start the lower bound of the range of wiki pages
16083             * @param end the upper bound of the range of wiki pages (not inclusive)
16084             * @return the range of matching wiki pages that the user has permission to view
16085             * @throws SystemException if a system exception occurred
16086             */
16087            @Override
16088            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
16089                    boolean head, int status, int start, int end) throws SystemException {
16090                    return filterFindByG_N_H_S(groupId, nodeId, head, status, start, end,
16091                            null);
16092            }
16093    
16094            /**
16095             * 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;.
16096             *
16097             * <p>
16098             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16099             * </p>
16100             *
16101             * @param groupId the group ID
16102             * @param nodeId the node ID
16103             * @param head the head
16104             * @param status the status
16105             * @param start the lower bound of the range of wiki pages
16106             * @param end the upper bound of the range of wiki pages (not inclusive)
16107             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16108             * @return the ordered range of matching wiki pages that the user has permission to view
16109             * @throws SystemException if a system exception occurred
16110             */
16111            @Override
16112            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
16113                    boolean head, int status, int start, int end,
16114                    OrderByComparator orderByComparator) throws SystemException {
16115                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16116                            return findByG_N_H_S(groupId, nodeId, head, status, start, end,
16117                                    orderByComparator);
16118                    }
16119    
16120                    StringBundler query = null;
16121    
16122                    if (orderByComparator != null) {
16123                            query = new StringBundler(6 +
16124                                            (orderByComparator.getOrderByFields().length * 3));
16125                    }
16126                    else {
16127                            query = new StringBundler(6);
16128                    }
16129    
16130                    if (getDB().isSupportsInlineDistinct()) {
16131                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
16132                    }
16133                    else {
16134                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
16135                    }
16136    
16137                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
16138    
16139                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
16140    
16141                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
16142    
16143                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
16144    
16145                    if (!getDB().isSupportsInlineDistinct()) {
16146                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
16147                    }
16148    
16149                    if (orderByComparator != null) {
16150                            if (getDB().isSupportsInlineDistinct()) {
16151                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16152                                            orderByComparator, true);
16153                            }
16154                            else {
16155                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16156                                            orderByComparator, true);
16157                            }
16158                    }
16159                    else {
16160                            if (getDB().isSupportsInlineDistinct()) {
16161                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16162                            }
16163                            else {
16164                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
16165                            }
16166                    }
16167    
16168                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16169                                    WikiPage.class.getName(),
16170                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16171    
16172                    Session session = null;
16173    
16174                    try {
16175                            session = openSession();
16176    
16177                            SQLQuery q = session.createSQLQuery(sql);
16178    
16179                            if (getDB().isSupportsInlineDistinct()) {
16180                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
16181                            }
16182                            else {
16183                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
16184                            }
16185    
16186                            QueryPos qPos = QueryPos.getInstance(q);
16187    
16188                            qPos.add(groupId);
16189    
16190                            qPos.add(nodeId);
16191    
16192                            qPos.add(head);
16193    
16194                            qPos.add(status);
16195    
16196                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
16197                    }
16198                    catch (Exception e) {
16199                            throw processException(e);
16200                    }
16201                    finally {
16202                            closeSession(session);
16203                    }
16204            }
16205    
16206            /**
16207             * 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;.
16208             *
16209             * @param pageId the primary key of the current wiki page
16210             * @param groupId the group ID
16211             * @param nodeId the node ID
16212             * @param head the head
16213             * @param status the status
16214             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16215             * @return the previous, current, and next wiki page
16216             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
16217             * @throws SystemException if a system exception occurred
16218             */
16219            @Override
16220            public WikiPage[] filterFindByG_N_H_S_PrevAndNext(long pageId,
16221                    long groupId, long nodeId, boolean head, int status,
16222                    OrderByComparator orderByComparator)
16223                    throws NoSuchPageException, SystemException {
16224                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16225                            return findByG_N_H_S_PrevAndNext(pageId, groupId, nodeId, head,
16226                                    status, orderByComparator);
16227                    }
16228    
16229                    WikiPage wikiPage = findByPrimaryKey(pageId);
16230    
16231                    Session session = null;
16232    
16233                    try {
16234                            session = openSession();
16235    
16236                            WikiPage[] array = new WikiPageImpl[3];
16237    
16238                            array[0] = filterGetByG_N_H_S_PrevAndNext(session, wikiPage,
16239                                            groupId, nodeId, head, status, orderByComparator, true);
16240    
16241                            array[1] = wikiPage;
16242    
16243                            array[2] = filterGetByG_N_H_S_PrevAndNext(session, wikiPage,
16244                                            groupId, nodeId, head, status, orderByComparator, false);
16245    
16246                            return array;
16247                    }
16248                    catch (Exception e) {
16249                            throw processException(e);
16250                    }
16251                    finally {
16252                            closeSession(session);
16253                    }
16254            }
16255    
16256            protected WikiPage filterGetByG_N_H_S_PrevAndNext(Session session,
16257                    WikiPage wikiPage, long groupId, long nodeId, boolean head, int status,
16258                    OrderByComparator orderByComparator, boolean previous) {
16259                    StringBundler query = null;
16260    
16261                    if (orderByComparator != null) {
16262                            query = new StringBundler(6 +
16263                                            (orderByComparator.getOrderByFields().length * 6));
16264                    }
16265                    else {
16266                            query = new StringBundler(3);
16267                    }
16268    
16269                    if (getDB().isSupportsInlineDistinct()) {
16270                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
16271                    }
16272                    else {
16273                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
16274                    }
16275    
16276                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
16277    
16278                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
16279    
16280                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
16281    
16282                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
16283    
16284                    if (!getDB().isSupportsInlineDistinct()) {
16285                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
16286                    }
16287    
16288                    if (orderByComparator != null) {
16289                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16290    
16291                            if (orderByConditionFields.length > 0) {
16292                                    query.append(WHERE_AND);
16293                            }
16294    
16295                            for (int i = 0; i < orderByConditionFields.length; i++) {
16296                                    if (getDB().isSupportsInlineDistinct()) {
16297                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16298                                    }
16299                                    else {
16300                                            query.append(_ORDER_BY_ENTITY_TABLE);
16301                                    }
16302    
16303                                    query.append(orderByConditionFields[i]);
16304    
16305                                    if ((i + 1) < orderByConditionFields.length) {
16306                                            if (orderByComparator.isAscending() ^ previous) {
16307                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16308                                            }
16309                                            else {
16310                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16311                                            }
16312                                    }
16313                                    else {
16314                                            if (orderByComparator.isAscending() ^ previous) {
16315                                                    query.append(WHERE_GREATER_THAN);
16316                                            }
16317                                            else {
16318                                                    query.append(WHERE_LESSER_THAN);
16319                                            }
16320                                    }
16321                            }
16322    
16323                            query.append(ORDER_BY_CLAUSE);
16324    
16325                            String[] orderByFields = orderByComparator.getOrderByFields();
16326    
16327                            for (int i = 0; i < orderByFields.length; i++) {
16328                                    if (getDB().isSupportsInlineDistinct()) {
16329                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16330                                    }
16331                                    else {
16332                                            query.append(_ORDER_BY_ENTITY_TABLE);
16333                                    }
16334    
16335                                    query.append(orderByFields[i]);
16336    
16337                                    if ((i + 1) < orderByFields.length) {
16338                                            if (orderByComparator.isAscending() ^ previous) {
16339                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16340                                            }
16341                                            else {
16342                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16343                                            }
16344                                    }
16345                                    else {
16346                                            if (orderByComparator.isAscending() ^ previous) {
16347                                                    query.append(ORDER_BY_ASC);
16348                                            }
16349                                            else {
16350                                                    query.append(ORDER_BY_DESC);
16351                                            }
16352                                    }
16353                            }
16354                    }
16355                    else {
16356                            if (getDB().isSupportsInlineDistinct()) {
16357                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16358                            }
16359                            else {
16360                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
16361                            }
16362                    }
16363    
16364                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16365                                    WikiPage.class.getName(),
16366                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16367    
16368                    SQLQuery q = session.createSQLQuery(sql);
16369    
16370                    q.setFirstResult(0);
16371                    q.setMaxResults(2);
16372    
16373                    if (getDB().isSupportsInlineDistinct()) {
16374                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
16375                    }
16376                    else {
16377                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
16378                    }
16379    
16380                    QueryPos qPos = QueryPos.getInstance(q);
16381    
16382                    qPos.add(groupId);
16383    
16384                    qPos.add(nodeId);
16385    
16386                    qPos.add(head);
16387    
16388                    qPos.add(status);
16389    
16390                    if (orderByComparator != null) {
16391                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
16392    
16393                            for (Object value : values) {
16394                                    qPos.add(value);
16395                            }
16396                    }
16397    
16398                    List<WikiPage> list = q.list();
16399    
16400                    if (list.size() == 2) {
16401                            return list.get(1);
16402                    }
16403                    else {
16404                            return null;
16405                    }
16406            }
16407    
16408            /**
16409             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63; from the database.
16410             *
16411             * @param groupId the group ID
16412             * @param nodeId the node ID
16413             * @param head the head
16414             * @param status the status
16415             * @throws SystemException if a system exception occurred
16416             */
16417            @Override
16418            public void removeByG_N_H_S(long groupId, long nodeId, boolean head,
16419                    int status) throws SystemException {
16420                    for (WikiPage wikiPage : findByG_N_H_S(groupId, nodeId, head, status,
16421                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16422                            remove(wikiPage);
16423                    }
16424            }
16425    
16426            /**
16427             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16428             *
16429             * @param groupId the group ID
16430             * @param nodeId the node ID
16431             * @param head the head
16432             * @param status the status
16433             * @return the number of matching wiki pages
16434             * @throws SystemException if a system exception occurred
16435             */
16436            @Override
16437            public int countByG_N_H_S(long groupId, long nodeId, boolean head,
16438                    int status) throws SystemException {
16439                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H_S;
16440    
16441                    Object[] finderArgs = new Object[] { groupId, nodeId, head, status };
16442    
16443                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
16444                                    this);
16445    
16446                    if (count == null) {
16447                            StringBundler query = new StringBundler(5);
16448    
16449                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
16450    
16451                            query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
16452    
16453                            query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
16454    
16455                            query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
16456    
16457                            query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
16458    
16459                            String sql = query.toString();
16460    
16461                            Session session = null;
16462    
16463                            try {
16464                                    session = openSession();
16465    
16466                                    Query q = session.createQuery(sql);
16467    
16468                                    QueryPos qPos = QueryPos.getInstance(q);
16469    
16470                                    qPos.add(groupId);
16471    
16472                                    qPos.add(nodeId);
16473    
16474                                    qPos.add(head);
16475    
16476                                    qPos.add(status);
16477    
16478                                    count = (Long)q.uniqueResult();
16479    
16480                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
16481                            }
16482                            catch (Exception e) {
16483                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16484    
16485                                    throw processException(e);
16486                            }
16487                            finally {
16488                                    closeSession(session);
16489                            }
16490                    }
16491    
16492                    return count.intValue();
16493            }
16494    
16495            /**
16496             * 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;.
16497             *
16498             * @param groupId the group ID
16499             * @param nodeId the node ID
16500             * @param head the head
16501             * @param status the status
16502             * @return the number of matching wiki pages that the user has permission to view
16503             * @throws SystemException if a system exception occurred
16504             */
16505            @Override
16506            public int filterCountByG_N_H_S(long groupId, long nodeId, boolean head,
16507                    int status) throws SystemException {
16508                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16509                            return countByG_N_H_S(groupId, nodeId, head, status);
16510                    }
16511    
16512                    StringBundler query = new StringBundler(5);
16513    
16514                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
16515    
16516                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
16517    
16518                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
16519    
16520                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
16521    
16522                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
16523    
16524                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16525                                    WikiPage.class.getName(),
16526                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16527    
16528                    Session session = null;
16529    
16530                    try {
16531                            session = openSession();
16532    
16533                            SQLQuery q = session.createSQLQuery(sql);
16534    
16535                            q.addScalar(COUNT_COLUMN_NAME,
16536                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16537    
16538                            QueryPos qPos = QueryPos.getInstance(q);
16539    
16540                            qPos.add(groupId);
16541    
16542                            qPos.add(nodeId);
16543    
16544                            qPos.add(head);
16545    
16546                            qPos.add(status);
16547    
16548                            Long count = (Long)q.uniqueResult();
16549    
16550                            return count.intValue();
16551                    }
16552                    catch (Exception e) {
16553                            throw processException(e);
16554                    }
16555                    finally {
16556                            closeSession(session);
16557                    }
16558            }
16559    
16560            private static final String _FINDER_COLUMN_G_N_H_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
16561            private static final String _FINDER_COLUMN_G_N_H_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
16562            private static final String _FINDER_COLUMN_G_N_H_S_HEAD_2 = "wikiPage.head = ? AND ";
16563            private static final String _FINDER_COLUMN_G_N_H_S_STATUS_2 = "wikiPage.status = ?";
16564            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16565                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
16566                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_P_S",
16567                            new String[] {
16568                                    Long.class.getName(), Boolean.class.getName(),
16569                                    String.class.getName(), Integer.class.getName(),
16570                                    
16571                            Integer.class.getName(), Integer.class.getName(),
16572                                    OrderByComparator.class.getName()
16573                            });
16574            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S =
16575                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16576                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
16577                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_P_S",
16578                            new String[] {
16579                                    Long.class.getName(), Boolean.class.getName(),
16580                                    String.class.getName(), Integer.class.getName()
16581                            },
16582                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
16583                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
16584                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
16585                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
16586                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
16587                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
16588            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16589                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16590                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_P_S",
16591                            new String[] {
16592                                    Long.class.getName(), Boolean.class.getName(),
16593                                    String.class.getName(), Integer.class.getName()
16594                            });
16595    
16596            /**
16597             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16598             *
16599             * @param nodeId the node ID
16600             * @param head the head
16601             * @param parentTitle the parent title
16602             * @param status the status
16603             * @return the matching wiki pages
16604             * @throws SystemException if a system exception occurred
16605             */
16606            @Override
16607            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
16608                    String parentTitle, int status) throws SystemException {
16609                    return findByN_H_P_S(nodeId, head, parentTitle, status,
16610                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16611            }
16612    
16613            /**
16614             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16615             *
16616             * <p>
16617             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16618             * </p>
16619             *
16620             * @param nodeId the node ID
16621             * @param head the head
16622             * @param parentTitle the parent title
16623             * @param status the status
16624             * @param start the lower bound of the range of wiki pages
16625             * @param end the upper bound of the range of wiki pages (not inclusive)
16626             * @return the range of matching wiki pages
16627             * @throws SystemException if a system exception occurred
16628             */
16629            @Override
16630            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
16631                    String parentTitle, int status, int start, int end)
16632                    throws SystemException {
16633                    return findByN_H_P_S(nodeId, head, parentTitle, status, start, end, null);
16634            }
16635    
16636            /**
16637             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16638             *
16639             * <p>
16640             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16641             * </p>
16642             *
16643             * @param nodeId the node ID
16644             * @param head the head
16645             * @param parentTitle the parent title
16646             * @param status the status
16647             * @param start the lower bound of the range of wiki pages
16648             * @param end the upper bound of the range of wiki pages (not inclusive)
16649             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16650             * @return the ordered range of matching wiki pages
16651             * @throws SystemException if a system exception occurred
16652             */
16653            @Override
16654            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
16655                    String parentTitle, int status, int start, int end,
16656                    OrderByComparator orderByComparator) throws SystemException {
16657                    boolean pagination = true;
16658                    FinderPath finderPath = null;
16659                    Object[] finderArgs = null;
16660    
16661                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16662                                    (orderByComparator == null)) {
16663                            pagination = false;
16664                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S;
16665                            finderArgs = new Object[] { nodeId, head, parentTitle, status };
16666                    }
16667                    else {
16668                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_S;
16669                            finderArgs = new Object[] {
16670                                            nodeId, head, parentTitle, status,
16671                                            
16672                                            start, end, orderByComparator
16673                                    };
16674                    }
16675    
16676                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
16677                                    finderArgs, this);
16678    
16679                    if ((list != null) && !list.isEmpty()) {
16680                            for (WikiPage wikiPage : list) {
16681                                    if ((nodeId != wikiPage.getNodeId()) ||
16682                                                    (head != wikiPage.getHead()) ||
16683                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle()) ||
16684                                                    (status != wikiPage.getStatus())) {
16685                                            list = null;
16686    
16687                                            break;
16688                                    }
16689                            }
16690                    }
16691    
16692                    if (list == null) {
16693                            StringBundler query = null;
16694    
16695                            if (orderByComparator != null) {
16696                                    query = new StringBundler(6 +
16697                                                    (orderByComparator.getOrderByFields().length * 3));
16698                            }
16699                            else {
16700                                    query = new StringBundler(6);
16701                            }
16702    
16703                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
16704    
16705                            query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
16706    
16707                            query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
16708    
16709                            boolean bindParentTitle = false;
16710    
16711                            if (parentTitle == null) {
16712                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
16713                            }
16714                            else if (parentTitle.equals(StringPool.BLANK)) {
16715                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
16716                            }
16717                            else {
16718                                    bindParentTitle = true;
16719    
16720                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
16721                            }
16722    
16723                            query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
16724    
16725                            if (orderByComparator != null) {
16726                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16727                                            orderByComparator);
16728                            }
16729                            else
16730                             if (pagination) {
16731                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16732                            }
16733    
16734                            String sql = query.toString();
16735    
16736                            Session session = null;
16737    
16738                            try {
16739                                    session = openSession();
16740    
16741                                    Query q = session.createQuery(sql);
16742    
16743                                    QueryPos qPos = QueryPos.getInstance(q);
16744    
16745                                    qPos.add(nodeId);
16746    
16747                                    qPos.add(head);
16748    
16749                                    if (bindParentTitle) {
16750                                            qPos.add(parentTitle.toLowerCase());
16751                                    }
16752    
16753                                    qPos.add(status);
16754    
16755                                    if (!pagination) {
16756                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
16757                                                            start, end, false);
16758    
16759                                            Collections.sort(list);
16760    
16761                                            list = new UnmodifiableList<WikiPage>(list);
16762                                    }
16763                                    else {
16764                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
16765                                                            start, end);
16766                                    }
16767    
16768                                    cacheResult(list);
16769    
16770                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
16771                            }
16772                            catch (Exception e) {
16773                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16774    
16775                                    throw processException(e);
16776                            }
16777                            finally {
16778                                    closeSession(session);
16779                            }
16780                    }
16781    
16782                    return list;
16783            }
16784    
16785            /**
16786             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16787             *
16788             * @param nodeId the node ID
16789             * @param head the head
16790             * @param parentTitle the parent title
16791             * @param status the status
16792             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16793             * @return the first matching wiki page
16794             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
16795             * @throws SystemException if a system exception occurred
16796             */
16797            @Override
16798            public WikiPage findByN_H_P_S_First(long nodeId, boolean head,
16799                    String parentTitle, int status, OrderByComparator orderByComparator)
16800                    throws NoSuchPageException, SystemException {
16801                    WikiPage wikiPage = fetchByN_H_P_S_First(nodeId, head, parentTitle,
16802                                    status, orderByComparator);
16803    
16804                    if (wikiPage != null) {
16805                            return wikiPage;
16806                    }
16807    
16808                    StringBundler msg = new StringBundler(10);
16809    
16810                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16811    
16812                    msg.append("nodeId=");
16813                    msg.append(nodeId);
16814    
16815                    msg.append(", head=");
16816                    msg.append(head);
16817    
16818                    msg.append(", parentTitle=");
16819                    msg.append(parentTitle);
16820    
16821                    msg.append(", status=");
16822                    msg.append(status);
16823    
16824                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16825    
16826                    throw new NoSuchPageException(msg.toString());
16827            }
16828    
16829            /**
16830             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16831             *
16832             * @param nodeId the node ID
16833             * @param head the head
16834             * @param parentTitle the parent title
16835             * @param status the status
16836             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16837             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
16838             * @throws SystemException if a system exception occurred
16839             */
16840            @Override
16841            public WikiPage fetchByN_H_P_S_First(long nodeId, boolean head,
16842                    String parentTitle, int status, OrderByComparator orderByComparator)
16843                    throws SystemException {
16844                    List<WikiPage> list = findByN_H_P_S(nodeId, head, parentTitle, status,
16845                                    0, 1, orderByComparator);
16846    
16847                    if (!list.isEmpty()) {
16848                            return list.get(0);
16849                    }
16850    
16851                    return null;
16852            }
16853    
16854            /**
16855             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16856             *
16857             * @param nodeId the node ID
16858             * @param head the head
16859             * @param parentTitle the parent title
16860             * @param status the status
16861             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16862             * @return the last matching wiki page
16863             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
16864             * @throws SystemException if a system exception occurred
16865             */
16866            @Override
16867            public WikiPage findByN_H_P_S_Last(long nodeId, boolean head,
16868                    String parentTitle, int status, OrderByComparator orderByComparator)
16869                    throws NoSuchPageException, SystemException {
16870                    WikiPage wikiPage = fetchByN_H_P_S_Last(nodeId, head, parentTitle,
16871                                    status, orderByComparator);
16872    
16873                    if (wikiPage != null) {
16874                            return wikiPage;
16875                    }
16876    
16877                    StringBundler msg = new StringBundler(10);
16878    
16879                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16880    
16881                    msg.append("nodeId=");
16882                    msg.append(nodeId);
16883    
16884                    msg.append(", head=");
16885                    msg.append(head);
16886    
16887                    msg.append(", parentTitle=");
16888                    msg.append(parentTitle);
16889    
16890                    msg.append(", status=");
16891                    msg.append(status);
16892    
16893                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16894    
16895                    throw new NoSuchPageException(msg.toString());
16896            }
16897    
16898            /**
16899             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16900             *
16901             * @param nodeId the node ID
16902             * @param head the head
16903             * @param parentTitle the parent title
16904             * @param status the status
16905             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16906             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
16907             * @throws SystemException if a system exception occurred
16908             */
16909            @Override
16910            public WikiPage fetchByN_H_P_S_Last(long nodeId, boolean head,
16911                    String parentTitle, int status, OrderByComparator orderByComparator)
16912                    throws SystemException {
16913                    int count = countByN_H_P_S(nodeId, head, parentTitle, status);
16914    
16915                    if (count == 0) {
16916                            return null;
16917                    }
16918    
16919                    List<WikiPage> list = findByN_H_P_S(nodeId, head, parentTitle, status,
16920                                    count - 1, count, orderByComparator);
16921    
16922                    if (!list.isEmpty()) {
16923                            return list.get(0);
16924                    }
16925    
16926                    return null;
16927            }
16928    
16929            /**
16930             * 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;.
16931             *
16932             * @param pageId the primary key of the current wiki page
16933             * @param nodeId the node ID
16934             * @param head the head
16935             * @param parentTitle the parent title
16936             * @param status the status
16937             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16938             * @return the previous, current, and next wiki page
16939             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
16940             * @throws SystemException if a system exception occurred
16941             */
16942            @Override
16943            public WikiPage[] findByN_H_P_S_PrevAndNext(long pageId, long nodeId,
16944                    boolean head, String parentTitle, int status,
16945                    OrderByComparator orderByComparator)
16946                    throws NoSuchPageException, SystemException {
16947                    WikiPage wikiPage = findByPrimaryKey(pageId);
16948    
16949                    Session session = null;
16950    
16951                    try {
16952                            session = openSession();
16953    
16954                            WikiPage[] array = new WikiPageImpl[3];
16955    
16956                            array[0] = getByN_H_P_S_PrevAndNext(session, wikiPage, nodeId,
16957                                            head, parentTitle, status, orderByComparator, true);
16958    
16959                            array[1] = wikiPage;
16960    
16961                            array[2] = getByN_H_P_S_PrevAndNext(session, wikiPage, nodeId,
16962                                            head, parentTitle, status, orderByComparator, false);
16963    
16964                            return array;
16965                    }
16966                    catch (Exception e) {
16967                            throw processException(e);
16968                    }
16969                    finally {
16970                            closeSession(session);
16971                    }
16972            }
16973    
16974            protected WikiPage getByN_H_P_S_PrevAndNext(Session session,
16975                    WikiPage wikiPage, long nodeId, boolean head, String parentTitle,
16976                    int status, OrderByComparator orderByComparator, boolean previous) {
16977                    StringBundler query = null;
16978    
16979                    if (orderByComparator != null) {
16980                            query = new StringBundler(6 +
16981                                            (orderByComparator.getOrderByFields().length * 6));
16982                    }
16983                    else {
16984                            query = new StringBundler(3);
16985                    }
16986    
16987                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
16988    
16989                    query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
16990    
16991                    query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
16992    
16993                    boolean bindParentTitle = false;
16994    
16995                    if (parentTitle == null) {
16996                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
16997                    }
16998                    else if (parentTitle.equals(StringPool.BLANK)) {
16999                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
17000                    }
17001                    else {
17002                            bindParentTitle = true;
17003    
17004                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
17005                    }
17006    
17007                    query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
17008    
17009                    if (orderByComparator != null) {
17010                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17011    
17012                            if (orderByConditionFields.length > 0) {
17013                                    query.append(WHERE_AND);
17014                            }
17015    
17016                            for (int i = 0; i < orderByConditionFields.length; i++) {
17017                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17018                                    query.append(orderByConditionFields[i]);
17019    
17020                                    if ((i + 1) < orderByConditionFields.length) {
17021                                            if (orderByComparator.isAscending() ^ previous) {
17022                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17023                                            }
17024                                            else {
17025                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17026                                            }
17027                                    }
17028                                    else {
17029                                            if (orderByComparator.isAscending() ^ previous) {
17030                                                    query.append(WHERE_GREATER_THAN);
17031                                            }
17032                                            else {
17033                                                    query.append(WHERE_LESSER_THAN);
17034                                            }
17035                                    }
17036                            }
17037    
17038                            query.append(ORDER_BY_CLAUSE);
17039    
17040                            String[] orderByFields = orderByComparator.getOrderByFields();
17041    
17042                            for (int i = 0; i < orderByFields.length; i++) {
17043                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17044                                    query.append(orderByFields[i]);
17045    
17046                                    if ((i + 1) < orderByFields.length) {
17047                                            if (orderByComparator.isAscending() ^ previous) {
17048                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17049                                            }
17050                                            else {
17051                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17052                                            }
17053                                    }
17054                                    else {
17055                                            if (orderByComparator.isAscending() ^ previous) {
17056                                                    query.append(ORDER_BY_ASC);
17057                                            }
17058                                            else {
17059                                                    query.append(ORDER_BY_DESC);
17060                                            }
17061                                    }
17062                            }
17063                    }
17064                    else {
17065                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
17066                    }
17067    
17068                    String sql = query.toString();
17069    
17070                    Query q = session.createQuery(sql);
17071    
17072                    q.setFirstResult(0);
17073                    q.setMaxResults(2);
17074    
17075                    QueryPos qPos = QueryPos.getInstance(q);
17076    
17077                    qPos.add(nodeId);
17078    
17079                    qPos.add(head);
17080    
17081                    if (bindParentTitle) {
17082                            qPos.add(parentTitle.toLowerCase());
17083                    }
17084    
17085                    qPos.add(status);
17086    
17087                    if (orderByComparator != null) {
17088                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
17089    
17090                            for (Object value : values) {
17091                                    qPos.add(value);
17092                            }
17093                    }
17094    
17095                    List<WikiPage> list = q.list();
17096    
17097                    if (list.size() == 2) {
17098                            return list.get(1);
17099                    }
17100                    else {
17101                            return null;
17102                    }
17103            }
17104    
17105            /**
17106             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63; from the database.
17107             *
17108             * @param nodeId the node ID
17109             * @param head the head
17110             * @param parentTitle the parent title
17111             * @param status the status
17112             * @throws SystemException if a system exception occurred
17113             */
17114            @Override
17115            public void removeByN_H_P_S(long nodeId, boolean head, String parentTitle,
17116                    int status) throws SystemException {
17117                    for (WikiPage wikiPage : findByN_H_P_S(nodeId, head, parentTitle,
17118                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17119                            remove(wikiPage);
17120                    }
17121            }
17122    
17123            /**
17124             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17125             *
17126             * @param nodeId the node ID
17127             * @param head the head
17128             * @param parentTitle the parent title
17129             * @param status the status
17130             * @return the number of matching wiki pages
17131             * @throws SystemException if a system exception occurred
17132             */
17133            @Override
17134            public int countByN_H_P_S(long nodeId, boolean head, String parentTitle,
17135                    int status) throws SystemException {
17136                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_P_S;
17137    
17138                    Object[] finderArgs = new Object[] { nodeId, head, parentTitle, status };
17139    
17140                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
17141                                    this);
17142    
17143                    if (count == null) {
17144                            StringBundler query = new StringBundler(5);
17145    
17146                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
17147    
17148                            query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
17149    
17150                            query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
17151    
17152                            boolean bindParentTitle = false;
17153    
17154                            if (parentTitle == null) {
17155                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
17156                            }
17157                            else if (parentTitle.equals(StringPool.BLANK)) {
17158                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
17159                            }
17160                            else {
17161                                    bindParentTitle = true;
17162    
17163                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
17164                            }
17165    
17166                            query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
17167    
17168                            String sql = query.toString();
17169    
17170                            Session session = null;
17171    
17172                            try {
17173                                    session = openSession();
17174    
17175                                    Query q = session.createQuery(sql);
17176    
17177                                    QueryPos qPos = QueryPos.getInstance(q);
17178    
17179                                    qPos.add(nodeId);
17180    
17181                                    qPos.add(head);
17182    
17183                                    if (bindParentTitle) {
17184                                            qPos.add(parentTitle.toLowerCase());
17185                                    }
17186    
17187                                    qPos.add(status);
17188    
17189                                    count = (Long)q.uniqueResult();
17190    
17191                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
17192                            }
17193                            catch (Exception e) {
17194                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17195    
17196                                    throw processException(e);
17197                            }
17198                            finally {
17199                                    closeSession(session);
17200                            }
17201                    }
17202    
17203                    return count.intValue();
17204            }
17205    
17206            private static final String _FINDER_COLUMN_N_H_P_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
17207            private static final String _FINDER_COLUMN_N_H_P_S_HEAD_2 = "wikiPage.head = ? AND ";
17208            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL AND ";
17209            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ? AND ";
17210            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '') AND ";
17211            private static final String _FINDER_COLUMN_N_H_P_S_STATUS_2 = "wikiPage.status = ?";
17212            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_P_S =
17213                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17214                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
17215                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H_P_S",
17216                            new String[] {
17217                                    Long.class.getName(), Long.class.getName(),
17218                                    Boolean.class.getName(), String.class.getName(),
17219                                    Integer.class.getName(),
17220                                    
17221                            Integer.class.getName(), Integer.class.getName(),
17222                                    OrderByComparator.class.getName()
17223                            });
17224            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S =
17225                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17226                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
17227                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H_P_S",
17228                            new String[] {
17229                                    Long.class.getName(), Long.class.getName(),
17230                                    Boolean.class.getName(), String.class.getName(),
17231                                    Integer.class.getName()
17232                            },
17233                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
17234                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
17235                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
17236                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
17237                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
17238                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
17239                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
17240            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17241                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17242                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H_P_S",
17243                            new String[] {
17244                                    Long.class.getName(), Long.class.getName(),
17245                                    Boolean.class.getName(), String.class.getName(),
17246                                    Integer.class.getName()
17247                            });
17248    
17249            /**
17250             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17251             *
17252             * @param groupId the group ID
17253             * @param nodeId the node ID
17254             * @param head the head
17255             * @param parentTitle the parent title
17256             * @param status the status
17257             * @return the matching wiki pages
17258             * @throws SystemException if a system exception occurred
17259             */
17260            @Override
17261            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
17262                    boolean head, String parentTitle, int status) throws SystemException {
17263                    return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
17264                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17265            }
17266    
17267            /**
17268             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17269             *
17270             * <p>
17271             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17272             * </p>
17273             *
17274             * @param groupId the group ID
17275             * @param nodeId the node ID
17276             * @param head the head
17277             * @param parentTitle the parent title
17278             * @param status the status
17279             * @param start the lower bound of the range of wiki pages
17280             * @param end the upper bound of the range of wiki pages (not inclusive)
17281             * @return the range of matching wiki pages
17282             * @throws SystemException if a system exception occurred
17283             */
17284            @Override
17285            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
17286                    boolean head, String parentTitle, int status, int start, int end)
17287                    throws SystemException {
17288                    return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
17289                            start, end, null);
17290            }
17291    
17292            /**
17293             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17294             *
17295             * <p>
17296             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17297             * </p>
17298             *
17299             * @param groupId the group ID
17300             * @param nodeId the node ID
17301             * @param head the head
17302             * @param parentTitle the parent title
17303             * @param status the status
17304             * @param start the lower bound of the range of wiki pages
17305             * @param end the upper bound of the range of wiki pages (not inclusive)
17306             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17307             * @return the ordered range of matching wiki pages
17308             * @throws SystemException if a system exception occurred
17309             */
17310            @Override
17311            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
17312                    boolean head, String parentTitle, int status, int start, int end,
17313                    OrderByComparator orderByComparator) throws SystemException {
17314                    boolean pagination = true;
17315                    FinderPath finderPath = null;
17316                    Object[] finderArgs = null;
17317    
17318                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17319                                    (orderByComparator == null)) {
17320                            pagination = false;
17321                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S;
17322                            finderArgs = new Object[] { groupId, nodeId, head, parentTitle, status };
17323                    }
17324                    else {
17325                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_P_S;
17326                            finderArgs = new Object[] {
17327                                            groupId, nodeId, head, parentTitle, status,
17328                                            
17329                                            start, end, orderByComparator
17330                                    };
17331                    }
17332    
17333                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
17334                                    finderArgs, this);
17335    
17336                    if ((list != null) && !list.isEmpty()) {
17337                            for (WikiPage wikiPage : list) {
17338                                    if ((groupId != wikiPage.getGroupId()) ||
17339                                                    (nodeId != wikiPage.getNodeId()) ||
17340                                                    (head != wikiPage.getHead()) ||
17341                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle()) ||
17342                                                    (status != wikiPage.getStatus())) {
17343                                            list = null;
17344    
17345                                            break;
17346                                    }
17347                            }
17348                    }
17349    
17350                    if (list == null) {
17351                            StringBundler query = null;
17352    
17353                            if (orderByComparator != null) {
17354                                    query = new StringBundler(7 +
17355                                                    (orderByComparator.getOrderByFields().length * 3));
17356                            }
17357                            else {
17358                                    query = new StringBundler(7);
17359                            }
17360    
17361                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
17362    
17363                            query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
17364    
17365                            query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
17366    
17367                            query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
17368    
17369                            boolean bindParentTitle = false;
17370    
17371                            if (parentTitle == null) {
17372                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
17373                            }
17374                            else if (parentTitle.equals(StringPool.BLANK)) {
17375                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
17376                            }
17377                            else {
17378                                    bindParentTitle = true;
17379    
17380                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
17381                            }
17382    
17383                            query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
17384    
17385                            if (orderByComparator != null) {
17386                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17387                                            orderByComparator);
17388                            }
17389                            else
17390                             if (pagination) {
17391                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
17392                            }
17393    
17394                            String sql = query.toString();
17395    
17396                            Session session = null;
17397    
17398                            try {
17399                                    session = openSession();
17400    
17401                                    Query q = session.createQuery(sql);
17402    
17403                                    QueryPos qPos = QueryPos.getInstance(q);
17404    
17405                                    qPos.add(groupId);
17406    
17407                                    qPos.add(nodeId);
17408    
17409                                    qPos.add(head);
17410    
17411                                    if (bindParentTitle) {
17412                                            qPos.add(parentTitle.toLowerCase());
17413                                    }
17414    
17415                                    qPos.add(status);
17416    
17417                                    if (!pagination) {
17418                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
17419                                                            start, end, false);
17420    
17421                                            Collections.sort(list);
17422    
17423                                            list = new UnmodifiableList<WikiPage>(list);
17424                                    }
17425                                    else {
17426                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
17427                                                            start, end);
17428                                    }
17429    
17430                                    cacheResult(list);
17431    
17432                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
17433                            }
17434                            catch (Exception e) {
17435                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17436    
17437                                    throw processException(e);
17438                            }
17439                            finally {
17440                                    closeSession(session);
17441                            }
17442                    }
17443    
17444                    return list;
17445            }
17446    
17447            /**
17448             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17449             *
17450             * @param groupId the group ID
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 first matching wiki page
17457             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
17458             * @throws SystemException if a system exception occurred
17459             */
17460            @Override
17461            public WikiPage findByG_N_H_P_S_First(long groupId, long nodeId,
17462                    boolean head, String parentTitle, int status,
17463                    OrderByComparator orderByComparator)
17464                    throws NoSuchPageException, SystemException {
17465                    WikiPage wikiPage = fetchByG_N_H_P_S_First(groupId, nodeId, head,
17466                                    parentTitle, status, orderByComparator);
17467    
17468                    if (wikiPage != null) {
17469                            return wikiPage;
17470                    }
17471    
17472                    StringBundler msg = new StringBundler(12);
17473    
17474                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17475    
17476                    msg.append("groupId=");
17477                    msg.append(groupId);
17478    
17479                    msg.append(", nodeId=");
17480                    msg.append(nodeId);
17481    
17482                    msg.append(", head=");
17483                    msg.append(head);
17484    
17485                    msg.append(", parentTitle=");
17486                    msg.append(parentTitle);
17487    
17488                    msg.append(", status=");
17489                    msg.append(status);
17490    
17491                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17492    
17493                    throw new NoSuchPageException(msg.toString());
17494            }
17495    
17496            /**
17497             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17498             *
17499             * @param groupId the group ID
17500             * @param nodeId the node ID
17501             * @param head the head
17502             * @param parentTitle the parent title
17503             * @param status the status
17504             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17505             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
17506             * @throws SystemException if a system exception occurred
17507             */
17508            @Override
17509            public WikiPage fetchByG_N_H_P_S_First(long groupId, long nodeId,
17510                    boolean head, String parentTitle, int status,
17511                    OrderByComparator orderByComparator) throws SystemException {
17512                    List<WikiPage> list = findByG_N_H_P_S(groupId, nodeId, head,
17513                                    parentTitle, status, 0, 1, orderByComparator);
17514    
17515                    if (!list.isEmpty()) {
17516                            return list.get(0);
17517                    }
17518    
17519                    return null;
17520            }
17521    
17522            /**
17523             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17524             *
17525             * @param groupId the group ID
17526             * @param nodeId the node ID
17527             * @param head the head
17528             * @param parentTitle the parent title
17529             * @param status the status
17530             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17531             * @return the last matching wiki page
17532             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
17533             * @throws SystemException if a system exception occurred
17534             */
17535            @Override
17536            public WikiPage findByG_N_H_P_S_Last(long groupId, long nodeId,
17537                    boolean head, String parentTitle, int status,
17538                    OrderByComparator orderByComparator)
17539                    throws NoSuchPageException, SystemException {
17540                    WikiPage wikiPage = fetchByG_N_H_P_S_Last(groupId, nodeId, head,
17541                                    parentTitle, status, orderByComparator);
17542    
17543                    if (wikiPage != null) {
17544                            return wikiPage;
17545                    }
17546    
17547                    StringBundler msg = new StringBundler(12);
17548    
17549                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17550    
17551                    msg.append("groupId=");
17552                    msg.append(groupId);
17553    
17554                    msg.append(", nodeId=");
17555                    msg.append(nodeId);
17556    
17557                    msg.append(", head=");
17558                    msg.append(head);
17559    
17560                    msg.append(", parentTitle=");
17561                    msg.append(parentTitle);
17562    
17563                    msg.append(", status=");
17564                    msg.append(status);
17565    
17566                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17567    
17568                    throw new NoSuchPageException(msg.toString());
17569            }
17570    
17571            /**
17572             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17573             *
17574             * @param groupId the group ID
17575             * @param nodeId the node ID
17576             * @param head the head
17577             * @param parentTitle the parent title
17578             * @param status the status
17579             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17580             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
17581             * @throws SystemException if a system exception occurred
17582             */
17583            @Override
17584            public WikiPage fetchByG_N_H_P_S_Last(long groupId, long nodeId,
17585                    boolean head, String parentTitle, int status,
17586                    OrderByComparator orderByComparator) throws SystemException {
17587                    int count = countByG_N_H_P_S(groupId, nodeId, head, parentTitle, status);
17588    
17589                    if (count == 0) {
17590                            return null;
17591                    }
17592    
17593                    List<WikiPage> list = findByG_N_H_P_S(groupId, nodeId, head,
17594                                    parentTitle, status, count - 1, count, orderByComparator);
17595    
17596                    if (!list.isEmpty()) {
17597                            return list.get(0);
17598                    }
17599    
17600                    return null;
17601            }
17602    
17603            /**
17604             * 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;.
17605             *
17606             * @param pageId the primary key of the current wiki page
17607             * @param groupId the group ID
17608             * @param nodeId the node ID
17609             * @param head the head
17610             * @param parentTitle the parent title
17611             * @param status the status
17612             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17613             * @return the previous, current, and next wiki page
17614             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
17615             * @throws SystemException if a system exception occurred
17616             */
17617            @Override
17618            public WikiPage[] findByG_N_H_P_S_PrevAndNext(long pageId, long groupId,
17619                    long nodeId, boolean head, String parentTitle, int status,
17620                    OrderByComparator orderByComparator)
17621                    throws NoSuchPageException, SystemException {
17622                    WikiPage wikiPage = findByPrimaryKey(pageId);
17623    
17624                    Session session = null;
17625    
17626                    try {
17627                            session = openSession();
17628    
17629                            WikiPage[] array = new WikiPageImpl[3];
17630    
17631                            array[0] = getByG_N_H_P_S_PrevAndNext(session, wikiPage, groupId,
17632                                            nodeId, head, parentTitle, status, orderByComparator, true);
17633    
17634                            array[1] = wikiPage;
17635    
17636                            array[2] = getByG_N_H_P_S_PrevAndNext(session, wikiPage, groupId,
17637                                            nodeId, head, parentTitle, status, orderByComparator, false);
17638    
17639                            return array;
17640                    }
17641                    catch (Exception e) {
17642                            throw processException(e);
17643                    }
17644                    finally {
17645                            closeSession(session);
17646                    }
17647            }
17648    
17649            protected WikiPage getByG_N_H_P_S_PrevAndNext(Session session,
17650                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
17651                    String parentTitle, int status, OrderByComparator orderByComparator,
17652                    boolean previous) {
17653                    StringBundler query = null;
17654    
17655                    if (orderByComparator != null) {
17656                            query = new StringBundler(6 +
17657                                            (orderByComparator.getOrderByFields().length * 6));
17658                    }
17659                    else {
17660                            query = new StringBundler(3);
17661                    }
17662    
17663                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
17664    
17665                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
17666    
17667                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
17668    
17669                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
17670    
17671                    boolean bindParentTitle = false;
17672    
17673                    if (parentTitle == null) {
17674                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
17675                    }
17676                    else if (parentTitle.equals(StringPool.BLANK)) {
17677                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
17678                    }
17679                    else {
17680                            bindParentTitle = true;
17681    
17682                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
17683                    }
17684    
17685                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
17686    
17687                    if (orderByComparator != null) {
17688                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17689    
17690                            if (orderByConditionFields.length > 0) {
17691                                    query.append(WHERE_AND);
17692                            }
17693    
17694                            for (int i = 0; i < orderByConditionFields.length; i++) {
17695                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17696                                    query.append(orderByConditionFields[i]);
17697    
17698                                    if ((i + 1) < orderByConditionFields.length) {
17699                                            if (orderByComparator.isAscending() ^ previous) {
17700                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17701                                            }
17702                                            else {
17703                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17704                                            }
17705                                    }
17706                                    else {
17707                                            if (orderByComparator.isAscending() ^ previous) {
17708                                                    query.append(WHERE_GREATER_THAN);
17709                                            }
17710                                            else {
17711                                                    query.append(WHERE_LESSER_THAN);
17712                                            }
17713                                    }
17714                            }
17715    
17716                            query.append(ORDER_BY_CLAUSE);
17717    
17718                            String[] orderByFields = orderByComparator.getOrderByFields();
17719    
17720                            for (int i = 0; i < orderByFields.length; i++) {
17721                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17722                                    query.append(orderByFields[i]);
17723    
17724                                    if ((i + 1) < orderByFields.length) {
17725                                            if (orderByComparator.isAscending() ^ previous) {
17726                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17727                                            }
17728                                            else {
17729                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17730                                            }
17731                                    }
17732                                    else {
17733                                            if (orderByComparator.isAscending() ^ previous) {
17734                                                    query.append(ORDER_BY_ASC);
17735                                            }
17736                                            else {
17737                                                    query.append(ORDER_BY_DESC);
17738                                            }
17739                                    }
17740                            }
17741                    }
17742                    else {
17743                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
17744                    }
17745    
17746                    String sql = query.toString();
17747    
17748                    Query q = session.createQuery(sql);
17749    
17750                    q.setFirstResult(0);
17751                    q.setMaxResults(2);
17752    
17753                    QueryPos qPos = QueryPos.getInstance(q);
17754    
17755                    qPos.add(groupId);
17756    
17757                    qPos.add(nodeId);
17758    
17759                    qPos.add(head);
17760    
17761                    if (bindParentTitle) {
17762                            qPos.add(parentTitle.toLowerCase());
17763                    }
17764    
17765                    qPos.add(status);
17766    
17767                    if (orderByComparator != null) {
17768                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
17769    
17770                            for (Object value : values) {
17771                                    qPos.add(value);
17772                            }
17773                    }
17774    
17775                    List<WikiPage> list = q.list();
17776    
17777                    if (list.size() == 2) {
17778                            return list.get(1);
17779                    }
17780                    else {
17781                            return null;
17782                    }
17783            }
17784    
17785            /**
17786             * 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;.
17787             *
17788             * @param groupId the group ID
17789             * @param nodeId the node ID
17790             * @param head the head
17791             * @param parentTitle the parent title
17792             * @param status the status
17793             * @return the matching wiki pages that the user has permission to view
17794             * @throws SystemException if a system exception occurred
17795             */
17796            @Override
17797            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
17798                    boolean head, String parentTitle, int status) throws SystemException {
17799                    return filterFindByG_N_H_P_S(groupId, nodeId, head, parentTitle,
17800                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17801            }
17802    
17803            /**
17804             * 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;.
17805             *
17806             * <p>
17807             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17808             * </p>
17809             *
17810             * @param groupId the group ID
17811             * @param nodeId the node ID
17812             * @param head the head
17813             * @param parentTitle the parent title
17814             * @param status the status
17815             * @param start the lower bound of the range of wiki pages
17816             * @param end the upper bound of the range of wiki pages (not inclusive)
17817             * @return the range of matching wiki pages that the user has permission to view
17818             * @throws SystemException if a system exception occurred
17819             */
17820            @Override
17821            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
17822                    boolean head, String parentTitle, int status, int start, int end)
17823                    throws SystemException {
17824                    return filterFindByG_N_H_P_S(groupId, nodeId, head, parentTitle,
17825                            status, start, end, null);
17826            }
17827    
17828            /**
17829             * 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;.
17830             *
17831             * <p>
17832             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17833             * </p>
17834             *
17835             * @param groupId the group ID
17836             * @param nodeId the node ID
17837             * @param head the head
17838             * @param parentTitle the parent title
17839             * @param status the status
17840             * @param start the lower bound of the range of wiki pages
17841             * @param end the upper bound of the range of wiki pages (not inclusive)
17842             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17843             * @return the ordered range of matching wiki pages that the user has permission to view
17844             * @throws SystemException if a system exception occurred
17845             */
17846            @Override
17847            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
17848                    boolean head, String parentTitle, int status, int start, int end,
17849                    OrderByComparator orderByComparator) throws SystemException {
17850                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17851                            return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
17852                                    start, end, orderByComparator);
17853                    }
17854    
17855                    StringBundler query = null;
17856    
17857                    if (orderByComparator != null) {
17858                            query = new StringBundler(7 +
17859                                            (orderByComparator.getOrderByFields().length * 3));
17860                    }
17861                    else {
17862                            query = new StringBundler(7);
17863                    }
17864    
17865                    if (getDB().isSupportsInlineDistinct()) {
17866                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
17867                    }
17868                    else {
17869                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
17870                    }
17871    
17872                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
17873    
17874                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
17875    
17876                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
17877    
17878                    boolean bindParentTitle = false;
17879    
17880                    if (parentTitle == null) {
17881                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
17882                    }
17883                    else if (parentTitle.equals(StringPool.BLANK)) {
17884                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
17885                    }
17886                    else {
17887                            bindParentTitle = true;
17888    
17889                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
17890                    }
17891    
17892                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
17893    
17894                    if (!getDB().isSupportsInlineDistinct()) {
17895                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
17896                    }
17897    
17898                    if (orderByComparator != null) {
17899                            if (getDB().isSupportsInlineDistinct()) {
17900                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17901                                            orderByComparator, true);
17902                            }
17903                            else {
17904                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
17905                                            orderByComparator, true);
17906                            }
17907                    }
17908                    else {
17909                            if (getDB().isSupportsInlineDistinct()) {
17910                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
17911                            }
17912                            else {
17913                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
17914                            }
17915                    }
17916    
17917                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17918                                    WikiPage.class.getName(),
17919                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17920    
17921                    Session session = null;
17922    
17923                    try {
17924                            session = openSession();
17925    
17926                            SQLQuery q = session.createSQLQuery(sql);
17927    
17928                            if (getDB().isSupportsInlineDistinct()) {
17929                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
17930                            }
17931                            else {
17932                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
17933                            }
17934    
17935                            QueryPos qPos = QueryPos.getInstance(q);
17936    
17937                            qPos.add(groupId);
17938    
17939                            qPos.add(nodeId);
17940    
17941                            qPos.add(head);
17942    
17943                            if (bindParentTitle) {
17944                                    qPos.add(parentTitle.toLowerCase());
17945                            }
17946    
17947                            qPos.add(status);
17948    
17949                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
17950                    }
17951                    catch (Exception e) {
17952                            throw processException(e);
17953                    }
17954                    finally {
17955                            closeSession(session);
17956                    }
17957            }
17958    
17959            /**
17960             * 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;.
17961             *
17962             * @param pageId the primary key of the current wiki page
17963             * @param groupId the group ID
17964             * @param nodeId the node ID
17965             * @param head the head
17966             * @param parentTitle the parent title
17967             * @param status the status
17968             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17969             * @return the previous, current, and next wiki page
17970             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
17971             * @throws SystemException if a system exception occurred
17972             */
17973            @Override
17974            public WikiPage[] filterFindByG_N_H_P_S_PrevAndNext(long pageId,
17975                    long groupId, long nodeId, boolean head, String parentTitle,
17976                    int status, OrderByComparator orderByComparator)
17977                    throws NoSuchPageException, SystemException {
17978                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17979                            return findByG_N_H_P_S_PrevAndNext(pageId, groupId, nodeId, head,
17980                                    parentTitle, status, orderByComparator);
17981                    }
17982    
17983                    WikiPage wikiPage = findByPrimaryKey(pageId);
17984    
17985                    Session session = null;
17986    
17987                    try {
17988                            session = openSession();
17989    
17990                            WikiPage[] array = new WikiPageImpl[3];
17991    
17992                            array[0] = filterGetByG_N_H_P_S_PrevAndNext(session, wikiPage,
17993                                            groupId, nodeId, head, parentTitle, status,
17994                                            orderByComparator, true);
17995    
17996                            array[1] = wikiPage;
17997    
17998                            array[2] = filterGetByG_N_H_P_S_PrevAndNext(session, wikiPage,
17999                                            groupId, nodeId, head, parentTitle, status,
18000                                            orderByComparator, false);
18001    
18002                            return array;
18003                    }
18004                    catch (Exception e) {
18005                            throw processException(e);
18006                    }
18007                    finally {
18008                            closeSession(session);
18009                    }
18010            }
18011    
18012            protected WikiPage filterGetByG_N_H_P_S_PrevAndNext(Session session,
18013                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
18014                    String parentTitle, int status, OrderByComparator orderByComparator,
18015                    boolean previous) {
18016                    StringBundler query = null;
18017    
18018                    if (orderByComparator != null) {
18019                            query = new StringBundler(6 +
18020                                            (orderByComparator.getOrderByFields().length * 6));
18021                    }
18022                    else {
18023                            query = new StringBundler(3);
18024                    }
18025    
18026                    if (getDB().isSupportsInlineDistinct()) {
18027                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
18028                    }
18029                    else {
18030                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
18031                    }
18032    
18033                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
18034    
18035                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
18036    
18037                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
18038    
18039                    boolean bindParentTitle = false;
18040    
18041                    if (parentTitle == null) {
18042                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
18043                    }
18044                    else if (parentTitle.equals(StringPool.BLANK)) {
18045                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
18046                    }
18047                    else {
18048                            bindParentTitle = true;
18049    
18050                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
18051                    }
18052    
18053                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
18054    
18055                    if (!getDB().isSupportsInlineDistinct()) {
18056                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
18057                    }
18058    
18059                    if (orderByComparator != null) {
18060                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18061    
18062                            if (orderByConditionFields.length > 0) {
18063                                    query.append(WHERE_AND);
18064                            }
18065    
18066                            for (int i = 0; i < orderByConditionFields.length; i++) {
18067                                    if (getDB().isSupportsInlineDistinct()) {
18068                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18069                                    }
18070                                    else {
18071                                            query.append(_ORDER_BY_ENTITY_TABLE);
18072                                    }
18073    
18074                                    query.append(orderByConditionFields[i]);
18075    
18076                                    if ((i + 1) < orderByConditionFields.length) {
18077                                            if (orderByComparator.isAscending() ^ previous) {
18078                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18079                                            }
18080                                            else {
18081                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18082                                            }
18083                                    }
18084                                    else {
18085                                            if (orderByComparator.isAscending() ^ previous) {
18086                                                    query.append(WHERE_GREATER_THAN);
18087                                            }
18088                                            else {
18089                                                    query.append(WHERE_LESSER_THAN);
18090                                            }
18091                                    }
18092                            }
18093    
18094                            query.append(ORDER_BY_CLAUSE);
18095    
18096                            String[] orderByFields = orderByComparator.getOrderByFields();
18097    
18098                            for (int i = 0; i < orderByFields.length; i++) {
18099                                    if (getDB().isSupportsInlineDistinct()) {
18100                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18101                                    }
18102                                    else {
18103                                            query.append(_ORDER_BY_ENTITY_TABLE);
18104                                    }
18105    
18106                                    query.append(orderByFields[i]);
18107    
18108                                    if ((i + 1) < orderByFields.length) {
18109                                            if (orderByComparator.isAscending() ^ previous) {
18110                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18111                                            }
18112                                            else {
18113                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18114                                            }
18115                                    }
18116                                    else {
18117                                            if (orderByComparator.isAscending() ^ previous) {
18118                                                    query.append(ORDER_BY_ASC);
18119                                            }
18120                                            else {
18121                                                    query.append(ORDER_BY_DESC);
18122                                            }
18123                                    }
18124                            }
18125                    }
18126                    else {
18127                            if (getDB().isSupportsInlineDistinct()) {
18128                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
18129                            }
18130                            else {
18131                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
18132                            }
18133                    }
18134    
18135                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18136                                    WikiPage.class.getName(),
18137                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18138    
18139                    SQLQuery q = session.createSQLQuery(sql);
18140    
18141                    q.setFirstResult(0);
18142                    q.setMaxResults(2);
18143    
18144                    if (getDB().isSupportsInlineDistinct()) {
18145                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
18146                    }
18147                    else {
18148                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
18149                    }
18150    
18151                    QueryPos qPos = QueryPos.getInstance(q);
18152    
18153                    qPos.add(groupId);
18154    
18155                    qPos.add(nodeId);
18156    
18157                    qPos.add(head);
18158    
18159                    if (bindParentTitle) {
18160                            qPos.add(parentTitle.toLowerCase());
18161                    }
18162    
18163                    qPos.add(status);
18164    
18165                    if (orderByComparator != null) {
18166                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
18167    
18168                            for (Object value : values) {
18169                                    qPos.add(value);
18170                            }
18171                    }
18172    
18173                    List<WikiPage> list = q.list();
18174    
18175                    if (list.size() == 2) {
18176                            return list.get(1);
18177                    }
18178                    else {
18179                            return null;
18180                    }
18181            }
18182    
18183            /**
18184             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63; from the database.
18185             *
18186             * @param groupId the group ID
18187             * @param nodeId the node ID
18188             * @param head the head
18189             * @param parentTitle the parent title
18190             * @param status the status
18191             * @throws SystemException if a system exception occurred
18192             */
18193            @Override
18194            public void removeByG_N_H_P_S(long groupId, long nodeId, boolean head,
18195                    String parentTitle, int status) throws SystemException {
18196                    for (WikiPage wikiPage : findByG_N_H_P_S(groupId, nodeId, head,
18197                                    parentTitle, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18198                            remove(wikiPage);
18199                    }
18200            }
18201    
18202            /**
18203             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
18204             *
18205             * @param groupId the group ID
18206             * @param nodeId the node ID
18207             * @param head the head
18208             * @param parentTitle the parent title
18209             * @param status the status
18210             * @return the number of matching wiki pages
18211             * @throws SystemException if a system exception occurred
18212             */
18213            @Override
18214            public int countByG_N_H_P_S(long groupId, long nodeId, boolean head,
18215                    String parentTitle, int status) throws SystemException {
18216                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H_P_S;
18217    
18218                    Object[] finderArgs = new Object[] {
18219                                    groupId, nodeId, head, parentTitle, status
18220                            };
18221    
18222                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
18223                                    this);
18224    
18225                    if (count == null) {
18226                            StringBundler query = new StringBundler(6);
18227    
18228                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
18229    
18230                            query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
18231    
18232                            query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
18233    
18234                            query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
18235    
18236                            boolean bindParentTitle = false;
18237    
18238                            if (parentTitle == null) {
18239                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
18240                            }
18241                            else if (parentTitle.equals(StringPool.BLANK)) {
18242                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
18243                            }
18244                            else {
18245                                    bindParentTitle = true;
18246    
18247                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
18248                            }
18249    
18250                            query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
18251    
18252                            String sql = query.toString();
18253    
18254                            Session session = null;
18255    
18256                            try {
18257                                    session = openSession();
18258    
18259                                    Query q = session.createQuery(sql);
18260    
18261                                    QueryPos qPos = QueryPos.getInstance(q);
18262    
18263                                    qPos.add(groupId);
18264    
18265                                    qPos.add(nodeId);
18266    
18267                                    qPos.add(head);
18268    
18269                                    if (bindParentTitle) {
18270                                            qPos.add(parentTitle.toLowerCase());
18271                                    }
18272    
18273                                    qPos.add(status);
18274    
18275                                    count = (Long)q.uniqueResult();
18276    
18277                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
18278                            }
18279                            catch (Exception e) {
18280                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18281    
18282                                    throw processException(e);
18283                            }
18284                            finally {
18285                                    closeSession(session);
18286                            }
18287                    }
18288    
18289                    return count.intValue();
18290            }
18291    
18292            /**
18293             * 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;.
18294             *
18295             * @param groupId the group ID
18296             * @param nodeId the node ID
18297             * @param head the head
18298             * @param parentTitle the parent title
18299             * @param status the status
18300             * @return the number of matching wiki pages that the user has permission to view
18301             * @throws SystemException if a system exception occurred
18302             */
18303            @Override
18304            public int filterCountByG_N_H_P_S(long groupId, long nodeId, boolean head,
18305                    String parentTitle, int status) throws SystemException {
18306                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18307                            return countByG_N_H_P_S(groupId, nodeId, head, parentTitle, status);
18308                    }
18309    
18310                    StringBundler query = new StringBundler(6);
18311    
18312                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
18313    
18314                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
18315    
18316                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
18317    
18318                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
18319    
18320                    boolean bindParentTitle = false;
18321    
18322                    if (parentTitle == null) {
18323                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
18324                    }
18325                    else if (parentTitle.equals(StringPool.BLANK)) {
18326                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
18327                    }
18328                    else {
18329                            bindParentTitle = true;
18330    
18331                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
18332                    }
18333    
18334                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
18335    
18336                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18337                                    WikiPage.class.getName(),
18338                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18339    
18340                    Session session = null;
18341    
18342                    try {
18343                            session = openSession();
18344    
18345                            SQLQuery q = session.createSQLQuery(sql);
18346    
18347                            q.addScalar(COUNT_COLUMN_NAME,
18348                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18349    
18350                            QueryPos qPos = QueryPos.getInstance(q);
18351    
18352                            qPos.add(groupId);
18353    
18354                            qPos.add(nodeId);
18355    
18356                            qPos.add(head);
18357    
18358                            if (bindParentTitle) {
18359                                    qPos.add(parentTitle.toLowerCase());
18360                            }
18361    
18362                            qPos.add(status);
18363    
18364                            Long count = (Long)q.uniqueResult();
18365    
18366                            return count.intValue();
18367                    }
18368                    catch (Exception e) {
18369                            throw processException(e);
18370                    }
18371                    finally {
18372                            closeSession(session);
18373                    }
18374            }
18375    
18376            private static final String _FINDER_COLUMN_G_N_H_P_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
18377            private static final String _FINDER_COLUMN_G_N_H_P_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
18378            private static final String _FINDER_COLUMN_G_N_H_P_S_HEAD_2 = "wikiPage.head = ? AND ";
18379            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL AND ";
18380            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ? AND ";
18381            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '') AND ";
18382            private static final String _FINDER_COLUMN_G_N_H_P_S_STATUS_2 = "wikiPage.status = ?";
18383    
18384            public WikiPagePersistenceImpl() {
18385                    setModelClass(WikiPage.class);
18386            }
18387    
18388            /**
18389             * Caches the wiki page in the entity cache if it is enabled.
18390             *
18391             * @param wikiPage the wiki page
18392             */
18393            @Override
18394            public void cacheResult(WikiPage wikiPage) {
18395                    EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
18396                            WikiPageImpl.class, wikiPage.getPrimaryKey(), wikiPage);
18397    
18398                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
18399                            new Object[] { wikiPage.getUuid(), wikiPage.getGroupId() }, wikiPage);
18400    
18401                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
18402                            new Object[] {
18403                                    wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
18404                                    wikiPage.getVersion()
18405                            }, wikiPage);
18406    
18407                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
18408                            new Object[] {
18409                                    wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion()
18410                            }, wikiPage);
18411    
18412                    wikiPage.resetOriginalValues();
18413            }
18414    
18415            /**
18416             * Caches the wiki pages in the entity cache if it is enabled.
18417             *
18418             * @param wikiPages the wiki pages
18419             */
18420            @Override
18421            public void cacheResult(List<WikiPage> wikiPages) {
18422                    for (WikiPage wikiPage : wikiPages) {
18423                            if (EntityCacheUtil.getResult(
18424                                                    WikiPageModelImpl.ENTITY_CACHE_ENABLED,
18425                                                    WikiPageImpl.class, wikiPage.getPrimaryKey()) == null) {
18426                                    cacheResult(wikiPage);
18427                            }
18428                            else {
18429                                    wikiPage.resetOriginalValues();
18430                            }
18431                    }
18432            }
18433    
18434            /**
18435             * Clears the cache for all wiki pages.
18436             *
18437             * <p>
18438             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
18439             * </p>
18440             */
18441            @Override
18442            public void clearCache() {
18443                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
18444                            CacheRegistryUtil.clear(WikiPageImpl.class.getName());
18445                    }
18446    
18447                    EntityCacheUtil.clearCache(WikiPageImpl.class.getName());
18448    
18449                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
18450                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18451                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18452            }
18453    
18454            /**
18455             * Clears the cache for the wiki page.
18456             *
18457             * <p>
18458             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
18459             * </p>
18460             */
18461            @Override
18462            public void clearCache(WikiPage wikiPage) {
18463                    EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
18464                            WikiPageImpl.class, wikiPage.getPrimaryKey());
18465    
18466                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18467                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18468    
18469                    clearUniqueFindersCache(wikiPage);
18470            }
18471    
18472            @Override
18473            public void clearCache(List<WikiPage> wikiPages) {
18474                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18475                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18476    
18477                    for (WikiPage wikiPage : wikiPages) {
18478                            EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
18479                                    WikiPageImpl.class, wikiPage.getPrimaryKey());
18480    
18481                            clearUniqueFindersCache(wikiPage);
18482                    }
18483            }
18484    
18485            protected void cacheUniqueFindersCache(WikiPage wikiPage) {
18486                    if (wikiPage.isNew()) {
18487                            Object[] args = new Object[] {
18488                                            wikiPage.getUuid(), wikiPage.getGroupId()
18489                                    };
18490    
18491                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18492                                    Long.valueOf(1));
18493                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18494                                    wikiPage);
18495    
18496                            args = new Object[] {
18497                                            wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
18498                                            wikiPage.getVersion()
18499                                    };
18500    
18501                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_N_V, args,
18502                                    Long.valueOf(1));
18503                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V, args, wikiPage);
18504    
18505                            args = new Object[] {
18506                                            wikiPage.getNodeId(), wikiPage.getTitle(),
18507                                            wikiPage.getVersion()
18508                                    };
18509    
18510                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T_V, args,
18511                                    Long.valueOf(1));
18512                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V, args, wikiPage);
18513                    }
18514                    else {
18515                            WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
18516    
18517                            if ((wikiPageModelImpl.getColumnBitmask() &
18518                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18519                                    Object[] args = new Object[] {
18520                                                    wikiPage.getUuid(), wikiPage.getGroupId()
18521                                            };
18522    
18523                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18524                                            Long.valueOf(1));
18525                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18526                                            wikiPage);
18527                            }
18528    
18529                            if ((wikiPageModelImpl.getColumnBitmask() &
18530                                            FINDER_PATH_FETCH_BY_R_N_V.getColumnBitmask()) != 0) {
18531                                    Object[] args = new Object[] {
18532                                                    wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
18533                                                    wikiPage.getVersion()
18534                                            };
18535    
18536                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_N_V, args,
18537                                            Long.valueOf(1));
18538                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V, args,
18539                                            wikiPage);
18540                            }
18541    
18542                            if ((wikiPageModelImpl.getColumnBitmask() &
18543                                            FINDER_PATH_FETCH_BY_N_T_V.getColumnBitmask()) != 0) {
18544                                    Object[] args = new Object[] {
18545                                                    wikiPage.getNodeId(), wikiPage.getTitle(),
18546                                                    wikiPage.getVersion()
18547                                            };
18548    
18549                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T_V, args,
18550                                            Long.valueOf(1));
18551                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V, args,
18552                                            wikiPage);
18553                            }
18554                    }
18555            }
18556    
18557            protected void clearUniqueFindersCache(WikiPage wikiPage) {
18558                    WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
18559    
18560                    Object[] args = new Object[] { wikiPage.getUuid(), wikiPage.getGroupId() };
18561    
18562                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18563                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18564    
18565                    if ((wikiPageModelImpl.getColumnBitmask() &
18566                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18567                            args = new Object[] {
18568                                            wikiPageModelImpl.getOriginalUuid(),
18569                                            wikiPageModelImpl.getOriginalGroupId()
18570                                    };
18571    
18572                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18573                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18574                    }
18575    
18576                    args = new Object[] {
18577                                    wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
18578                                    wikiPage.getVersion()
18579                            };
18580    
18581                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_V, args);
18582                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V, args);
18583    
18584                    if ((wikiPageModelImpl.getColumnBitmask() &
18585                                    FINDER_PATH_FETCH_BY_R_N_V.getColumnBitmask()) != 0) {
18586                            args = new Object[] {
18587                                            wikiPageModelImpl.getOriginalResourcePrimKey(),
18588                                            wikiPageModelImpl.getOriginalNodeId(),
18589                                            wikiPageModelImpl.getOriginalVersion()
18590                                    };
18591    
18592                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_V, args);
18593                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V, args);
18594                    }
18595    
18596                    args = new Object[] {
18597                                    wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion()
18598                            };
18599    
18600                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_V, args);
18601                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V, args);
18602    
18603                    if ((wikiPageModelImpl.getColumnBitmask() &
18604                                    FINDER_PATH_FETCH_BY_N_T_V.getColumnBitmask()) != 0) {
18605                            args = new Object[] {
18606                                            wikiPageModelImpl.getOriginalNodeId(),
18607                                            wikiPageModelImpl.getOriginalTitle(),
18608                                            wikiPageModelImpl.getOriginalVersion()
18609                                    };
18610    
18611                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_V, args);
18612                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V, args);
18613                    }
18614            }
18615    
18616            /**
18617             * Creates a new wiki page with the primary key. Does not add the wiki page to the database.
18618             *
18619             * @param pageId the primary key for the new wiki page
18620             * @return the new wiki page
18621             */
18622            @Override
18623            public WikiPage create(long pageId) {
18624                    WikiPage wikiPage = new WikiPageImpl();
18625    
18626                    wikiPage.setNew(true);
18627                    wikiPage.setPrimaryKey(pageId);
18628    
18629                    String uuid = PortalUUIDUtil.generate();
18630    
18631                    wikiPage.setUuid(uuid);
18632    
18633                    return wikiPage;
18634            }
18635    
18636            /**
18637             * Removes the wiki page with the primary key from the database. Also notifies the appropriate model listeners.
18638             *
18639             * @param pageId the primary key of the wiki page
18640             * @return the wiki page that was removed
18641             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
18642             * @throws SystemException if a system exception occurred
18643             */
18644            @Override
18645            public WikiPage remove(long pageId)
18646                    throws NoSuchPageException, SystemException {
18647                    return remove((Serializable)pageId);
18648            }
18649    
18650            /**
18651             * Removes the wiki page with the primary key from the database. Also notifies the appropriate model listeners.
18652             *
18653             * @param primaryKey the primary key of the wiki page
18654             * @return the wiki page that was removed
18655             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
18656             * @throws SystemException if a system exception occurred
18657             */
18658            @Override
18659            public WikiPage remove(Serializable primaryKey)
18660                    throws NoSuchPageException, SystemException {
18661                    Session session = null;
18662    
18663                    try {
18664                            session = openSession();
18665    
18666                            WikiPage wikiPage = (WikiPage)session.get(WikiPageImpl.class,
18667                                            primaryKey);
18668    
18669                            if (wikiPage == null) {
18670                                    if (_log.isWarnEnabled()) {
18671                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
18672                                    }
18673    
18674                                    throw new NoSuchPageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
18675                                            primaryKey);
18676                            }
18677    
18678                            return remove(wikiPage);
18679                    }
18680                    catch (NoSuchPageException nsee) {
18681                            throw nsee;
18682                    }
18683                    catch (Exception e) {
18684                            throw processException(e);
18685                    }
18686                    finally {
18687                            closeSession(session);
18688                    }
18689            }
18690    
18691            @Override
18692            protected WikiPage removeImpl(WikiPage wikiPage) throws SystemException {
18693                    wikiPage = toUnwrappedModel(wikiPage);
18694    
18695                    Session session = null;
18696    
18697                    try {
18698                            session = openSession();
18699    
18700                            if (!session.contains(wikiPage)) {
18701                                    wikiPage = (WikiPage)session.get(WikiPageImpl.class,
18702                                                    wikiPage.getPrimaryKeyObj());
18703                            }
18704    
18705                            if (wikiPage != null) {
18706                                    session.delete(wikiPage);
18707                            }
18708                    }
18709                    catch (Exception e) {
18710                            throw processException(e);
18711                    }
18712                    finally {
18713                            closeSession(session);
18714                    }
18715    
18716                    if (wikiPage != null) {
18717                            clearCache(wikiPage);
18718                    }
18719    
18720                    return wikiPage;
18721            }
18722    
18723            @Override
18724            public WikiPage updateImpl(com.liferay.portlet.wiki.model.WikiPage wikiPage)
18725                    throws SystemException {
18726                    wikiPage = toUnwrappedModel(wikiPage);
18727    
18728                    boolean isNew = wikiPage.isNew();
18729    
18730                    WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
18731    
18732                    if (Validator.isNull(wikiPage.getUuid())) {
18733                            String uuid = PortalUUIDUtil.generate();
18734    
18735                            wikiPage.setUuid(uuid);
18736                    }
18737    
18738                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
18739    
18740                    if (userId > 0) {
18741                            long companyId = wikiPage.getCompanyId();
18742    
18743                            long groupId = wikiPage.getGroupId();
18744    
18745                            long pageId = 0;
18746    
18747                            if (!isNew) {
18748                                    pageId = wikiPage.getPrimaryKey();
18749                            }
18750    
18751                            try {
18752                                    wikiPage.setTitle(SanitizerUtil.sanitize(companyId, groupId,
18753                                                    userId,
18754                                                    com.liferay.portlet.wiki.model.WikiPage.class.getName(),
18755                                                    pageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
18756                                                    wikiPage.getTitle(), null));
18757                            }
18758                            catch (SanitizerException se) {
18759                                    throw new SystemException(se);
18760                            }
18761                    }
18762    
18763                    Session session = null;
18764    
18765                    try {
18766                            session = openSession();
18767    
18768                            if (wikiPage.isNew()) {
18769                                    session.save(wikiPage);
18770    
18771                                    wikiPage.setNew(false);
18772                            }
18773                            else {
18774                                    session.merge(wikiPage);
18775                            }
18776                    }
18777                    catch (Exception e) {
18778                            throw processException(e);
18779                    }
18780                    finally {
18781                            closeSession(session);
18782                    }
18783    
18784                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18785    
18786                    if (isNew || !WikiPageModelImpl.COLUMN_BITMASK_ENABLED) {
18787                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18788                    }
18789    
18790                    else {
18791                            if ((wikiPageModelImpl.getColumnBitmask() &
18792                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
18793                                    Object[] args = new Object[] { wikiPageModelImpl.getOriginalUuid() };
18794    
18795                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
18796                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
18797                                            args);
18798    
18799                                    args = new Object[] { wikiPageModelImpl.getUuid() };
18800    
18801                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
18802                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
18803                                            args);
18804                            }
18805    
18806                            if ((wikiPageModelImpl.getColumnBitmask() &
18807                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
18808                                    Object[] args = new Object[] {
18809                                                    wikiPageModelImpl.getOriginalUuid(),
18810                                                    wikiPageModelImpl.getOriginalCompanyId()
18811                                            };
18812    
18813                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
18814                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
18815                                            args);
18816    
18817                                    args = new Object[] {
18818                                                    wikiPageModelImpl.getUuid(),
18819                                                    wikiPageModelImpl.getCompanyId()
18820                                            };
18821    
18822                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
18823                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
18824                                            args);
18825                            }
18826    
18827                            if ((wikiPageModelImpl.getColumnBitmask() &
18828                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY.getColumnBitmask()) != 0) {
18829                                    Object[] args = new Object[] {
18830                                                    wikiPageModelImpl.getOriginalResourcePrimKey()
18831                                            };
18832    
18833                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEPRIMKEY,
18834                                            args);
18835                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY,
18836                                            args);
18837    
18838                                    args = new Object[] { wikiPageModelImpl.getResourcePrimKey() };
18839    
18840                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEPRIMKEY,
18841                                            args);
18842                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY,
18843                                            args);
18844                            }
18845    
18846                            if ((wikiPageModelImpl.getColumnBitmask() &
18847                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID.getColumnBitmask()) != 0) {
18848                                    Object[] args = new Object[] {
18849                                                    wikiPageModelImpl.getOriginalNodeId()
18850                                            };
18851    
18852                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NODEID, args);
18853                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID,
18854                                            args);
18855    
18856                                    args = new Object[] { wikiPageModelImpl.getNodeId() };
18857    
18858                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NODEID, args);
18859                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID,
18860                                            args);
18861                            }
18862    
18863                            if ((wikiPageModelImpl.getColumnBitmask() &
18864                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT.getColumnBitmask()) != 0) {
18865                                    Object[] args = new Object[] {
18866                                                    wikiPageModelImpl.getOriginalFormat()
18867                                            };
18868    
18869                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FORMAT, args);
18870                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT,
18871                                            args);
18872    
18873                                    args = new Object[] { wikiPageModelImpl.getFormat() };
18874    
18875                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FORMAT, args);
18876                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT,
18877                                            args);
18878                            }
18879    
18880                            if ((wikiPageModelImpl.getColumnBitmask() &
18881                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N.getColumnBitmask()) != 0) {
18882                                    Object[] args = new Object[] {
18883                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
18884                                                    wikiPageModelImpl.getOriginalNodeId()
18885                                            };
18886    
18887                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N, args);
18888                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N,
18889                                            args);
18890    
18891                                    args = new Object[] {
18892                                                    wikiPageModelImpl.getResourcePrimKey(),
18893                                                    wikiPageModelImpl.getNodeId()
18894                                            };
18895    
18896                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N, args);
18897                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N,
18898                                            args);
18899                            }
18900    
18901                            if ((wikiPageModelImpl.getColumnBitmask() &
18902                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S.getColumnBitmask()) != 0) {
18903                                    Object[] args = new Object[] {
18904                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
18905                                                    wikiPageModelImpl.getOriginalStatus()
18906                                            };
18907    
18908                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
18909                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
18910                                            args);
18911    
18912                                    args = new Object[] {
18913                                                    wikiPageModelImpl.getResourcePrimKey(),
18914                                                    wikiPageModelImpl.getStatus()
18915                                            };
18916    
18917                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
18918                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
18919                                            args);
18920                            }
18921    
18922                            if ((wikiPageModelImpl.getColumnBitmask() &
18923                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T.getColumnBitmask()) != 0) {
18924                                    Object[] args = new Object[] {
18925                                                    wikiPageModelImpl.getOriginalNodeId(),
18926                                                    wikiPageModelImpl.getOriginalTitle()
18927                                            };
18928    
18929                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
18930                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T,
18931                                            args);
18932    
18933                                    args = new Object[] {
18934                                                    wikiPageModelImpl.getNodeId(),
18935                                                    wikiPageModelImpl.getTitle()
18936                                            };
18937    
18938                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
18939                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T,
18940                                            args);
18941                            }
18942    
18943                            if ((wikiPageModelImpl.getColumnBitmask() &
18944                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H.getColumnBitmask()) != 0) {
18945                                    Object[] args = new Object[] {
18946                                                    wikiPageModelImpl.getOriginalNodeId(),
18947                                                    wikiPageModelImpl.getOriginalHead()
18948                                            };
18949    
18950                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H, args);
18951                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H,
18952                                            args);
18953    
18954                                    args = new Object[] {
18955                                                    wikiPageModelImpl.getNodeId(),
18956                                                    wikiPageModelImpl.getHead()
18957                                            };
18958    
18959                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H, args);
18960                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H,
18961                                            args);
18962                            }
18963    
18964                            if ((wikiPageModelImpl.getColumnBitmask() &
18965                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P.getColumnBitmask()) != 0) {
18966                                    Object[] args = new Object[] {
18967                                                    wikiPageModelImpl.getOriginalNodeId(),
18968                                                    wikiPageModelImpl.getOriginalParentTitle()
18969                                            };
18970    
18971                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_P, args);
18972                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P,
18973                                            args);
18974    
18975                                    args = new Object[] {
18976                                                    wikiPageModelImpl.getNodeId(),
18977                                                    wikiPageModelImpl.getParentTitle()
18978                                            };
18979    
18980                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_P, args);
18981                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P,
18982                                            args);
18983                            }
18984    
18985                            if ((wikiPageModelImpl.getColumnBitmask() &
18986                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R.getColumnBitmask()) != 0) {
18987                                    Object[] args = new Object[] {
18988                                                    wikiPageModelImpl.getOriginalNodeId(),
18989                                                    wikiPageModelImpl.getOriginalRedirectTitle()
18990                                            };
18991    
18992                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_R, args);
18993                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R,
18994                                            args);
18995    
18996                                    args = new Object[] {
18997                                                    wikiPageModelImpl.getNodeId(),
18998                                                    wikiPageModelImpl.getRedirectTitle()
18999                                            };
19000    
19001                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_R, args);
19002                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R,
19003                                            args);
19004                            }
19005    
19006                            if ((wikiPageModelImpl.getColumnBitmask() &
19007                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S.getColumnBitmask()) != 0) {
19008                                    Object[] args = new Object[] {
19009                                                    wikiPageModelImpl.getOriginalNodeId(),
19010                                                    wikiPageModelImpl.getOriginalStatus()
19011                                            };
19012    
19013                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_S, args);
19014                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S,
19015                                            args);
19016    
19017                                    args = new Object[] {
19018                                                    wikiPageModelImpl.getNodeId(),
19019                                                    wikiPageModelImpl.getStatus()
19020                                            };
19021    
19022                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_S, args);
19023                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S,
19024                                            args);
19025                            }
19026    
19027                            if ((wikiPageModelImpl.getColumnBitmask() &
19028                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H.getColumnBitmask()) != 0) {
19029                                    Object[] args = new Object[] {
19030                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
19031                                                    wikiPageModelImpl.getOriginalNodeId(),
19032                                                    wikiPageModelImpl.getOriginalHead()
19033                                            };
19034    
19035                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_H, args);
19036                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H,
19037                                            args);
19038    
19039                                    args = new Object[] {
19040                                                    wikiPageModelImpl.getResourcePrimKey(),
19041                                                    wikiPageModelImpl.getNodeId(),
19042                                                    wikiPageModelImpl.getHead()
19043                                            };
19044    
19045                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_H, args);
19046                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H,
19047                                            args);
19048                            }
19049    
19050                            if ((wikiPageModelImpl.getColumnBitmask() &
19051                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S.getColumnBitmask()) != 0) {
19052                                    Object[] args = new Object[] {
19053                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
19054                                                    wikiPageModelImpl.getOriginalNodeId(),
19055                                                    wikiPageModelImpl.getOriginalStatus()
19056                                            };
19057    
19058                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_S, args);
19059                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S,
19060                                            args);
19061    
19062                                    args = new Object[] {
19063                                                    wikiPageModelImpl.getResourcePrimKey(),
19064                                                    wikiPageModelImpl.getNodeId(),
19065                                                    wikiPageModelImpl.getStatus()
19066                                            };
19067    
19068                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_S, args);
19069                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S,
19070                                            args);
19071                            }
19072    
19073                            if ((wikiPageModelImpl.getColumnBitmask() &
19074                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H.getColumnBitmask()) != 0) {
19075                                    Object[] args = new Object[] {
19076                                                    wikiPageModelImpl.getOriginalGroupId(),
19077                                                    wikiPageModelImpl.getOriginalNodeId(),
19078                                                    wikiPageModelImpl.getOriginalHead()
19079                                            };
19080    
19081                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H, args);
19082                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H,
19083                                            args);
19084    
19085                                    args = new Object[] {
19086                                                    wikiPageModelImpl.getGroupId(),
19087                                                    wikiPageModelImpl.getNodeId(),
19088                                                    wikiPageModelImpl.getHead()
19089                                            };
19090    
19091                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H, args);
19092                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H,
19093                                            args);
19094                            }
19095    
19096                            if ((wikiPageModelImpl.getColumnBitmask() &
19097                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S.getColumnBitmask()) != 0) {
19098                                    Object[] args = new Object[] {
19099                                                    wikiPageModelImpl.getOriginalGroupId(),
19100                                                    wikiPageModelImpl.getOriginalNodeId(),
19101                                                    wikiPageModelImpl.getOriginalStatus()
19102                                            };
19103    
19104                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_S, args);
19105                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S,
19106                                            args);
19107    
19108                                    args = new Object[] {
19109                                                    wikiPageModelImpl.getGroupId(),
19110                                                    wikiPageModelImpl.getNodeId(),
19111                                                    wikiPageModelImpl.getStatus()
19112                                            };
19113    
19114                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_S, args);
19115                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S,
19116                                            args);
19117                            }
19118    
19119                            if ((wikiPageModelImpl.getColumnBitmask() &
19120                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S.getColumnBitmask()) != 0) {
19121                                    Object[] args = new Object[] {
19122                                                    wikiPageModelImpl.getOriginalUserId(),
19123                                                    wikiPageModelImpl.getOriginalNodeId(),
19124                                                    wikiPageModelImpl.getOriginalStatus()
19125                                            };
19126    
19127                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_N_S, args);
19128                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S,
19129                                            args);
19130    
19131                                    args = new Object[] {
19132                                                    wikiPageModelImpl.getUserId(),
19133                                                    wikiPageModelImpl.getNodeId(),
19134                                                    wikiPageModelImpl.getStatus()
19135                                            };
19136    
19137                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_N_S, args);
19138                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S,
19139                                            args);
19140                            }
19141    
19142                            if ((wikiPageModelImpl.getColumnBitmask() &
19143                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H.getColumnBitmask()) != 0) {
19144                                    Object[] args = new Object[] {
19145                                                    wikiPageModelImpl.getOriginalNodeId(),
19146                                                    wikiPageModelImpl.getOriginalTitle(),
19147                                                    wikiPageModelImpl.getOriginalHead()
19148                                            };
19149    
19150                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_H, args);
19151                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H,
19152                                            args);
19153    
19154                                    args = new Object[] {
19155                                                    wikiPageModelImpl.getNodeId(),
19156                                                    wikiPageModelImpl.getTitle(),
19157                                                    wikiPageModelImpl.getHead()
19158                                            };
19159    
19160                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_H, args);
19161                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H,
19162                                            args);
19163                            }
19164    
19165                            if ((wikiPageModelImpl.getColumnBitmask() &
19166                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S.getColumnBitmask()) != 0) {
19167                                    Object[] args = new Object[] {
19168                                                    wikiPageModelImpl.getOriginalNodeId(),
19169                                                    wikiPageModelImpl.getOriginalTitle(),
19170                                                    wikiPageModelImpl.getOriginalStatus()
19171                                            };
19172    
19173                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_S, args);
19174                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S,
19175                                            args);
19176    
19177                                    args = new Object[] {
19178                                                    wikiPageModelImpl.getNodeId(),
19179                                                    wikiPageModelImpl.getTitle(),
19180                                                    wikiPageModelImpl.getStatus()
19181                                            };
19182    
19183                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_S, args);
19184                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S,
19185                                            args);
19186                            }
19187    
19188                            if ((wikiPageModelImpl.getColumnBitmask() &
19189                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P.getColumnBitmask()) != 0) {
19190                                    Object[] args = new Object[] {
19191                                                    wikiPageModelImpl.getOriginalNodeId(),
19192                                                    wikiPageModelImpl.getOriginalHead(),
19193                                                    wikiPageModelImpl.getOriginalParentTitle()
19194                                            };
19195    
19196                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P, args);
19197                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P,
19198                                            args);
19199    
19200                                    args = new Object[] {
19201                                                    wikiPageModelImpl.getNodeId(),
19202                                                    wikiPageModelImpl.getHead(),
19203                                                    wikiPageModelImpl.getParentTitle()
19204                                            };
19205    
19206                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P, args);
19207                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P,
19208                                            args);
19209                            }
19210    
19211                            if ((wikiPageModelImpl.getColumnBitmask() &
19212                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S.getColumnBitmask()) != 0) {
19213                                    Object[] args = new Object[] {
19214                                                    wikiPageModelImpl.getOriginalNodeId(),
19215                                                    wikiPageModelImpl.getOriginalHead(),
19216                                                    wikiPageModelImpl.getOriginalStatus()
19217                                            };
19218    
19219                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_S, args);
19220                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S,
19221                                            args);
19222    
19223                                    args = new Object[] {
19224                                                    wikiPageModelImpl.getNodeId(),
19225                                                    wikiPageModelImpl.getHead(),
19226                                                    wikiPageModelImpl.getStatus()
19227                                            };
19228    
19229                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_S, args);
19230                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S,
19231                                            args);
19232                            }
19233    
19234                            if ((wikiPageModelImpl.getColumnBitmask() &
19235                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S.getColumnBitmask()) != 0) {
19236                                    Object[] args = new Object[] {
19237                                                    wikiPageModelImpl.getOriginalGroupId(),
19238                                                    wikiPageModelImpl.getOriginalUserId(),
19239                                                    wikiPageModelImpl.getOriginalNodeId(),
19240                                                    wikiPageModelImpl.getOriginalStatus()
19241                                            };
19242    
19243                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_N_S, args);
19244                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S,
19245                                            args);
19246    
19247                                    args = new Object[] {
19248                                                    wikiPageModelImpl.getGroupId(),
19249                                                    wikiPageModelImpl.getUserId(),
19250                                                    wikiPageModelImpl.getNodeId(),
19251                                                    wikiPageModelImpl.getStatus()
19252                                            };
19253    
19254                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_N_S, args);
19255                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S,
19256                                            args);
19257                            }
19258    
19259                            if ((wikiPageModelImpl.getColumnBitmask() &
19260                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H.getColumnBitmask()) != 0) {
19261                                    Object[] args = new Object[] {
19262                                                    wikiPageModelImpl.getOriginalGroupId(),
19263                                                    wikiPageModelImpl.getOriginalNodeId(),
19264                                                    wikiPageModelImpl.getOriginalTitle(),
19265                                                    wikiPageModelImpl.getOriginalHead()
19266                                            };
19267    
19268                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T_H, args);
19269                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H,
19270                                            args);
19271    
19272                                    args = new Object[] {
19273                                                    wikiPageModelImpl.getGroupId(),
19274                                                    wikiPageModelImpl.getNodeId(),
19275                                                    wikiPageModelImpl.getTitle(),
19276                                                    wikiPageModelImpl.getHead()
19277                                            };
19278    
19279                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T_H, args);
19280                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H,
19281                                            args);
19282                            }
19283    
19284                            if ((wikiPageModelImpl.getColumnBitmask() &
19285                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S.getColumnBitmask()) != 0) {
19286                                    Object[] args = new Object[] {
19287                                                    wikiPageModelImpl.getOriginalGroupId(),
19288                                                    wikiPageModelImpl.getOriginalNodeId(),
19289                                                    wikiPageModelImpl.getOriginalHead(),
19290                                                    wikiPageModelImpl.getOriginalStatus()
19291                                            };
19292    
19293                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_S, args);
19294                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S,
19295                                            args);
19296    
19297                                    args = new Object[] {
19298                                                    wikiPageModelImpl.getGroupId(),
19299                                                    wikiPageModelImpl.getNodeId(),
19300                                                    wikiPageModelImpl.getHead(),
19301                                                    wikiPageModelImpl.getStatus()
19302                                            };
19303    
19304                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_S, args);
19305                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S,
19306                                            args);
19307                            }
19308    
19309                            if ((wikiPageModelImpl.getColumnBitmask() &
19310                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S.getColumnBitmask()) != 0) {
19311                                    Object[] args = new Object[] {
19312                                                    wikiPageModelImpl.getOriginalNodeId(),
19313                                                    wikiPageModelImpl.getOriginalHead(),
19314                                                    wikiPageModelImpl.getOriginalParentTitle(),
19315                                                    wikiPageModelImpl.getOriginalStatus()
19316                                            };
19317    
19318                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P_S, args);
19319                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S,
19320                                            args);
19321    
19322                                    args = new Object[] {
19323                                                    wikiPageModelImpl.getNodeId(),
19324                                                    wikiPageModelImpl.getHead(),
19325                                                    wikiPageModelImpl.getParentTitle(),
19326                                                    wikiPageModelImpl.getStatus()
19327                                            };
19328    
19329                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P_S, args);
19330                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S,
19331                                            args);
19332                            }
19333    
19334                            if ((wikiPageModelImpl.getColumnBitmask() &
19335                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S.getColumnBitmask()) != 0) {
19336                                    Object[] args = new Object[] {
19337                                                    wikiPageModelImpl.getOriginalGroupId(),
19338                                                    wikiPageModelImpl.getOriginalNodeId(),
19339                                                    wikiPageModelImpl.getOriginalHead(),
19340                                                    wikiPageModelImpl.getOriginalParentTitle(),
19341                                                    wikiPageModelImpl.getOriginalStatus()
19342                                            };
19343    
19344                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_P_S,
19345                                            args);
19346                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S,
19347                                            args);
19348    
19349                                    args = new Object[] {
19350                                                    wikiPageModelImpl.getGroupId(),
19351                                                    wikiPageModelImpl.getNodeId(),
19352                                                    wikiPageModelImpl.getHead(),
19353                                                    wikiPageModelImpl.getParentTitle(),
19354                                                    wikiPageModelImpl.getStatus()
19355                                            };
19356    
19357                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_P_S,
19358                                            args);
19359                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S,
19360                                            args);
19361                            }
19362                    }
19363    
19364                    EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
19365                            WikiPageImpl.class, wikiPage.getPrimaryKey(), wikiPage);
19366    
19367                    clearUniqueFindersCache(wikiPage);
19368                    cacheUniqueFindersCache(wikiPage);
19369    
19370                    return wikiPage;
19371            }
19372    
19373            protected WikiPage toUnwrappedModel(WikiPage wikiPage) {
19374                    if (wikiPage instanceof WikiPageImpl) {
19375                            return wikiPage;
19376                    }
19377    
19378                    WikiPageImpl wikiPageImpl = new WikiPageImpl();
19379    
19380                    wikiPageImpl.setNew(wikiPage.isNew());
19381                    wikiPageImpl.setPrimaryKey(wikiPage.getPrimaryKey());
19382    
19383                    wikiPageImpl.setUuid(wikiPage.getUuid());
19384                    wikiPageImpl.setPageId(wikiPage.getPageId());
19385                    wikiPageImpl.setResourcePrimKey(wikiPage.getResourcePrimKey());
19386                    wikiPageImpl.setGroupId(wikiPage.getGroupId());
19387                    wikiPageImpl.setCompanyId(wikiPage.getCompanyId());
19388                    wikiPageImpl.setUserId(wikiPage.getUserId());
19389                    wikiPageImpl.setUserName(wikiPage.getUserName());
19390                    wikiPageImpl.setCreateDate(wikiPage.getCreateDate());
19391                    wikiPageImpl.setModifiedDate(wikiPage.getModifiedDate());
19392                    wikiPageImpl.setNodeId(wikiPage.getNodeId());
19393                    wikiPageImpl.setTitle(wikiPage.getTitle());
19394                    wikiPageImpl.setVersion(wikiPage.getVersion());
19395                    wikiPageImpl.setMinorEdit(wikiPage.isMinorEdit());
19396                    wikiPageImpl.setContent(wikiPage.getContent());
19397                    wikiPageImpl.setSummary(wikiPage.getSummary());
19398                    wikiPageImpl.setFormat(wikiPage.getFormat());
19399                    wikiPageImpl.setHead(wikiPage.isHead());
19400                    wikiPageImpl.setParentTitle(wikiPage.getParentTitle());
19401                    wikiPageImpl.setRedirectTitle(wikiPage.getRedirectTitle());
19402                    wikiPageImpl.setStatus(wikiPage.getStatus());
19403                    wikiPageImpl.setStatusByUserId(wikiPage.getStatusByUserId());
19404                    wikiPageImpl.setStatusByUserName(wikiPage.getStatusByUserName());
19405                    wikiPageImpl.setStatusDate(wikiPage.getStatusDate());
19406    
19407                    return wikiPageImpl;
19408            }
19409    
19410            /**
19411             * Returns the wiki page with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
19412             *
19413             * @param primaryKey the primary key of the wiki page
19414             * @return the wiki page
19415             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
19416             * @throws SystemException if a system exception occurred
19417             */
19418            @Override
19419            public WikiPage findByPrimaryKey(Serializable primaryKey)
19420                    throws NoSuchPageException, SystemException {
19421                    WikiPage wikiPage = fetchByPrimaryKey(primaryKey);
19422    
19423                    if (wikiPage == null) {
19424                            if (_log.isWarnEnabled()) {
19425                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19426                            }
19427    
19428                            throw new NoSuchPageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19429                                    primaryKey);
19430                    }
19431    
19432                    return wikiPage;
19433            }
19434    
19435            /**
19436             * Returns the wiki page with the primary key or throws a {@link com.liferay.portlet.wiki.NoSuchPageException} if it could not be found.
19437             *
19438             * @param pageId the primary key of the wiki page
19439             * @return the wiki page
19440             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
19441             * @throws SystemException if a system exception occurred
19442             */
19443            @Override
19444            public WikiPage findByPrimaryKey(long pageId)
19445                    throws NoSuchPageException, SystemException {
19446                    return findByPrimaryKey((Serializable)pageId);
19447            }
19448    
19449            /**
19450             * Returns the wiki page with the primary key or returns <code>null</code> if it could not be found.
19451             *
19452             * @param primaryKey the primary key of the wiki page
19453             * @return the wiki page, or <code>null</code> if a wiki page with the primary key could not be found
19454             * @throws SystemException if a system exception occurred
19455             */
19456            @Override
19457            public WikiPage fetchByPrimaryKey(Serializable primaryKey)
19458                    throws SystemException {
19459                    WikiPage wikiPage = (WikiPage)EntityCacheUtil.getResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
19460                                    WikiPageImpl.class, primaryKey);
19461    
19462                    if (wikiPage == _nullWikiPage) {
19463                            return null;
19464                    }
19465    
19466                    if (wikiPage == null) {
19467                            Session session = null;
19468    
19469                            try {
19470                                    session = openSession();
19471    
19472                                    wikiPage = (WikiPage)session.get(WikiPageImpl.class, primaryKey);
19473    
19474                                    if (wikiPage != null) {
19475                                            cacheResult(wikiPage);
19476                                    }
19477                                    else {
19478                                            EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
19479                                                    WikiPageImpl.class, primaryKey, _nullWikiPage);
19480                                    }
19481                            }
19482                            catch (Exception e) {
19483                                    EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
19484                                            WikiPageImpl.class, primaryKey);
19485    
19486                                    throw processException(e);
19487                            }
19488                            finally {
19489                                    closeSession(session);
19490                            }
19491                    }
19492    
19493                    return wikiPage;
19494            }
19495    
19496            /**
19497             * Returns the wiki page with the primary key or returns <code>null</code> if it could not be found.
19498             *
19499             * @param pageId the primary key of the wiki page
19500             * @return the wiki page, or <code>null</code> if a wiki page with the primary key could not be found
19501             * @throws SystemException if a system exception occurred
19502             */
19503            @Override
19504            public WikiPage fetchByPrimaryKey(long pageId) throws SystemException {
19505                    return fetchByPrimaryKey((Serializable)pageId);
19506            }
19507    
19508            /**
19509             * Returns all the wiki pages.
19510             *
19511             * @return the wiki pages
19512             * @throws SystemException if a system exception occurred
19513             */
19514            @Override
19515            public List<WikiPage> findAll() throws SystemException {
19516                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19517            }
19518    
19519            /**
19520             * Returns a range of all the wiki pages.
19521             *
19522             * <p>
19523             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
19524             * </p>
19525             *
19526             * @param start the lower bound of the range of wiki pages
19527             * @param end the upper bound of the range of wiki pages (not inclusive)
19528             * @return the range of wiki pages
19529             * @throws SystemException if a system exception occurred
19530             */
19531            @Override
19532            public List<WikiPage> findAll(int start, int end) throws SystemException {
19533                    return findAll(start, end, null);
19534            }
19535    
19536            /**
19537             * Returns an ordered range of all the wiki pages.
19538             *
19539             * <p>
19540             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
19541             * </p>
19542             *
19543             * @param start the lower bound of the range of wiki pages
19544             * @param end the upper bound of the range of wiki pages (not inclusive)
19545             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19546             * @return the ordered range of wiki pages
19547             * @throws SystemException if a system exception occurred
19548             */
19549            @Override
19550            public List<WikiPage> findAll(int start, int end,
19551                    OrderByComparator orderByComparator) throws SystemException {
19552                    boolean pagination = true;
19553                    FinderPath finderPath = null;
19554                    Object[] finderArgs = null;
19555    
19556                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
19557                                    (orderByComparator == null)) {
19558                            pagination = false;
19559                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
19560                            finderArgs = FINDER_ARGS_EMPTY;
19561                    }
19562                    else {
19563                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
19564                            finderArgs = new Object[] { start, end, orderByComparator };
19565                    }
19566    
19567                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
19568                                    finderArgs, this);
19569    
19570                    if (list == null) {
19571                            StringBundler query = null;
19572                            String sql = null;
19573    
19574                            if (orderByComparator != null) {
19575                                    query = new StringBundler(2 +
19576                                                    (orderByComparator.getOrderByFields().length * 3));
19577    
19578                                    query.append(_SQL_SELECT_WIKIPAGE);
19579    
19580                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19581                                            orderByComparator);
19582    
19583                                    sql = query.toString();
19584                            }
19585                            else {
19586                                    sql = _SQL_SELECT_WIKIPAGE;
19587    
19588                                    if (pagination) {
19589                                            sql = sql.concat(WikiPageModelImpl.ORDER_BY_JPQL);
19590                                    }
19591                            }
19592    
19593                            Session session = null;
19594    
19595                            try {
19596                                    session = openSession();
19597    
19598                                    Query q = session.createQuery(sql);
19599    
19600                                    if (!pagination) {
19601                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
19602                                                            start, end, false);
19603    
19604                                            Collections.sort(list);
19605    
19606                                            list = new UnmodifiableList<WikiPage>(list);
19607                                    }
19608                                    else {
19609                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
19610                                                            start, end);
19611                                    }
19612    
19613                                    cacheResult(list);
19614    
19615                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
19616                            }
19617                            catch (Exception e) {
19618                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19619    
19620                                    throw processException(e);
19621                            }
19622                            finally {
19623                                    closeSession(session);
19624                            }
19625                    }
19626    
19627                    return list;
19628            }
19629    
19630            /**
19631             * Removes all the wiki pages from the database.
19632             *
19633             * @throws SystemException if a system exception occurred
19634             */
19635            @Override
19636            public void removeAll() throws SystemException {
19637                    for (WikiPage wikiPage : findAll()) {
19638                            remove(wikiPage);
19639                    }
19640            }
19641    
19642            /**
19643             * Returns the number of wiki pages.
19644             *
19645             * @return the number of wiki pages
19646             * @throws SystemException if a system exception occurred
19647             */
19648            @Override
19649            public int countAll() throws SystemException {
19650                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
19651                                    FINDER_ARGS_EMPTY, this);
19652    
19653                    if (count == null) {
19654                            Session session = null;
19655    
19656                            try {
19657                                    session = openSession();
19658    
19659                                    Query q = session.createQuery(_SQL_COUNT_WIKIPAGE);
19660    
19661                                    count = (Long)q.uniqueResult();
19662    
19663                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
19664                                            FINDER_ARGS_EMPTY, count);
19665                            }
19666                            catch (Exception e) {
19667                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
19668                                            FINDER_ARGS_EMPTY);
19669    
19670                                    throw processException(e);
19671                            }
19672                            finally {
19673                                    closeSession(session);
19674                            }
19675                    }
19676    
19677                    return count.intValue();
19678            }
19679    
19680            @Override
19681            protected Set<String> getBadColumnNames() {
19682                    return _badColumnNames;
19683            }
19684    
19685            /**
19686             * Initializes the wiki page persistence.
19687             */
19688            public void afterPropertiesSet() {
19689                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
19690                                            com.liferay.portal.util.PropsUtil.get(
19691                                                    "value.object.listener.com.liferay.portlet.wiki.model.WikiPage")));
19692    
19693                    if (listenerClassNames.length > 0) {
19694                            try {
19695                                    List<ModelListener<WikiPage>> listenersList = new ArrayList<ModelListener<WikiPage>>();
19696    
19697                                    for (String listenerClassName : listenerClassNames) {
19698                                            listenersList.add((ModelListener<WikiPage>)InstanceFactory.newInstance(
19699                                                            getClassLoader(), listenerClassName));
19700                                    }
19701    
19702                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
19703                            }
19704                            catch (Exception e) {
19705                                    _log.error(e);
19706                            }
19707                    }
19708            }
19709    
19710            public void destroy() {
19711                    EntityCacheUtil.removeCache(WikiPageImpl.class.getName());
19712                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
19713                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19714                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19715            }
19716    
19717            private static final String _SQL_SELECT_WIKIPAGE = "SELECT wikiPage FROM WikiPage wikiPage";
19718            private static final String _SQL_SELECT_WIKIPAGE_WHERE = "SELECT wikiPage FROM WikiPage wikiPage WHERE ";
19719            private static final String _SQL_COUNT_WIKIPAGE = "SELECT COUNT(wikiPage) FROM WikiPage wikiPage";
19720            private static final String _SQL_COUNT_WIKIPAGE_WHERE = "SELECT COUNT(wikiPage) FROM WikiPage wikiPage WHERE ";
19721            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "wikiPage.resourcePrimKey";
19722            private static final String _FILTER_SQL_SELECT_WIKIPAGE_WHERE = "SELECT DISTINCT {wikiPage.*} FROM WikiPage wikiPage WHERE ";
19723            private static final String _FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1 =
19724                    "SELECT {WikiPage.*} FROM (SELECT DISTINCT wikiPage.pageId FROM WikiPage wikiPage WHERE ";
19725            private static final String _FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2 =
19726                    ") TEMP_TABLE INNER JOIN WikiPage ON TEMP_TABLE.pageId = WikiPage.pageId";
19727            private static final String _FILTER_SQL_COUNT_WIKIPAGE_WHERE = "SELECT COUNT(DISTINCT wikiPage.pageId) AS COUNT_VALUE FROM WikiPage wikiPage WHERE ";
19728            private static final String _FILTER_ENTITY_ALIAS = "wikiPage";
19729            private static final String _FILTER_ENTITY_TABLE = "WikiPage";
19730            private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPage.";
19731            private static final String _ORDER_BY_ENTITY_TABLE = "WikiPage.";
19732            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPage exists with the primary key ";
19733            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPage exists with the key {";
19734            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
19735            private static Log _log = LogFactoryUtil.getLog(WikiPagePersistenceImpl.class);
19736            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
19737                                    "uuid"
19738                            });
19739            private static WikiPage _nullWikiPage = new WikiPageImpl() {
19740                            @Override
19741                            public Object clone() {
19742                                    return this;
19743                            }
19744    
19745                            @Override
19746                            public CacheModel<WikiPage> toCacheModel() {
19747                                    return _nullWikiPageCacheModel;
19748                            }
19749                    };
19750    
19751            private static CacheModel<WikiPage> _nullWikiPageCacheModel = new CacheModel<WikiPage>() {
19752                            @Override
19753                            public WikiPage toEntityModel() {
19754                                    return _nullWikiPage;
19755                            }
19756                    };
19757    }