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_NODEID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1465                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1466                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByNodeId",
1467                            new String[] {
1468                                    Long.class.getName(),
1469                                    
1470                            Integer.class.getName(), Integer.class.getName(),
1471                                    OrderByComparator.class.getName()
1472                            });
1473            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID =
1474                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1475                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1476                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByNodeId",
1477                            new String[] { Long.class.getName() },
1478                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
1479                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
1480                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
1481            public static final FinderPath FINDER_PATH_COUNT_BY_NODEID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1482                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1483                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByNodeId",
1484                            new String[] { Long.class.getName() });
1485    
1486            /**
1487             * Returns all the wiki pages where nodeId = &#63;.
1488             *
1489             * @param nodeId the node ID
1490             * @return the matching wiki pages
1491             * @throws SystemException if a system exception occurred
1492             */
1493            @Override
1494            public List<WikiPage> findByNodeId(long nodeId) throws SystemException {
1495                    return findByNodeId(nodeId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1496            }
1497    
1498            /**
1499             * Returns a range of all the wiki pages where nodeId = &#63;.
1500             *
1501             * <p>
1502             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1503             * </p>
1504             *
1505             * @param nodeId the node ID
1506             * @param start the lower bound of the range of wiki pages
1507             * @param end the upper bound of the range of wiki pages (not inclusive)
1508             * @return the range of matching wiki pages
1509             * @throws SystemException if a system exception occurred
1510             */
1511            @Override
1512            public List<WikiPage> findByNodeId(long nodeId, int start, int end)
1513                    throws SystemException {
1514                    return findByNodeId(nodeId, start, end, null);
1515            }
1516    
1517            /**
1518             * Returns an ordered range of all the wiki pages where nodeId = &#63;.
1519             *
1520             * <p>
1521             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1522             * </p>
1523             *
1524             * @param nodeId the node ID
1525             * @param start the lower bound of the range of wiki pages
1526             * @param end the upper bound of the range of wiki pages (not inclusive)
1527             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1528             * @return the ordered range of matching wiki pages
1529             * @throws SystemException if a system exception occurred
1530             */
1531            @Override
1532            public List<WikiPage> findByNodeId(long nodeId, int start, int end,
1533                    OrderByComparator orderByComparator) throws SystemException {
1534                    boolean pagination = true;
1535                    FinderPath finderPath = null;
1536                    Object[] finderArgs = null;
1537    
1538                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1539                                    (orderByComparator == null)) {
1540                            pagination = false;
1541                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID;
1542                            finderArgs = new Object[] { nodeId };
1543                    }
1544                    else {
1545                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NODEID;
1546                            finderArgs = new Object[] { nodeId, start, end, orderByComparator };
1547                    }
1548    
1549                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
1550                                    finderArgs, this);
1551    
1552                    if ((list != null) && !list.isEmpty()) {
1553                            for (WikiPage wikiPage : list) {
1554                                    if ((nodeId != wikiPage.getNodeId())) {
1555                                            list = null;
1556    
1557                                            break;
1558                                    }
1559                            }
1560                    }
1561    
1562                    if (list == null) {
1563                            StringBundler query = null;
1564    
1565                            if (orderByComparator != null) {
1566                                    query = new StringBundler(3 +
1567                                                    (orderByComparator.getOrderByFields().length * 3));
1568                            }
1569                            else {
1570                                    query = new StringBundler(3);
1571                            }
1572    
1573                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1574    
1575                            query.append(_FINDER_COLUMN_NODEID_NODEID_2);
1576    
1577                            if (orderByComparator != null) {
1578                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1579                                            orderByComparator);
1580                            }
1581                            else
1582                             if (pagination) {
1583                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1584                            }
1585    
1586                            String sql = query.toString();
1587    
1588                            Session session = null;
1589    
1590                            try {
1591                                    session = openSession();
1592    
1593                                    Query q = session.createQuery(sql);
1594    
1595                                    QueryPos qPos = QueryPos.getInstance(q);
1596    
1597                                    qPos.add(nodeId);
1598    
1599                                    if (!pagination) {
1600                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
1601                                                            start, end, false);
1602    
1603                                            Collections.sort(list);
1604    
1605                                            list = new UnmodifiableList<WikiPage>(list);
1606                                    }
1607                                    else {
1608                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
1609                                                            start, end);
1610                                    }
1611    
1612                                    cacheResult(list);
1613    
1614                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1615                            }
1616                            catch (Exception e) {
1617                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1618    
1619                                    throw processException(e);
1620                            }
1621                            finally {
1622                                    closeSession(session);
1623                            }
1624                    }
1625    
1626                    return list;
1627            }
1628    
1629            /**
1630             * Returns the first wiki page in the ordered set where nodeId = &#63;.
1631             *
1632             * @param nodeId the node ID
1633             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1634             * @return the first matching wiki page
1635             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1636             * @throws SystemException if a system exception occurred
1637             */
1638            @Override
1639            public WikiPage findByNodeId_First(long nodeId,
1640                    OrderByComparator orderByComparator)
1641                    throws NoSuchPageException, SystemException {
1642                    WikiPage wikiPage = fetchByNodeId_First(nodeId, orderByComparator);
1643    
1644                    if (wikiPage != null) {
1645                            return wikiPage;
1646                    }
1647    
1648                    StringBundler msg = new StringBundler(4);
1649    
1650                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1651    
1652                    msg.append("nodeId=");
1653                    msg.append(nodeId);
1654    
1655                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1656    
1657                    throw new NoSuchPageException(msg.toString());
1658            }
1659    
1660            /**
1661             * Returns the first wiki page in the ordered set where nodeId = &#63;.
1662             *
1663             * @param nodeId the node ID
1664             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1665             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
1666             * @throws SystemException if a system exception occurred
1667             */
1668            @Override
1669            public WikiPage fetchByNodeId_First(long nodeId,
1670                    OrderByComparator orderByComparator) throws SystemException {
1671                    List<WikiPage> list = findByNodeId(nodeId, 0, 1, orderByComparator);
1672    
1673                    if (!list.isEmpty()) {
1674                            return list.get(0);
1675                    }
1676    
1677                    return null;
1678            }
1679    
1680            /**
1681             * Returns the last wiki page in the ordered set where nodeId = &#63;.
1682             *
1683             * @param nodeId the node ID
1684             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1685             * @return the last matching wiki page
1686             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1687             * @throws SystemException if a system exception occurred
1688             */
1689            @Override
1690            public WikiPage findByNodeId_Last(long nodeId,
1691                    OrderByComparator orderByComparator)
1692                    throws NoSuchPageException, SystemException {
1693                    WikiPage wikiPage = fetchByNodeId_Last(nodeId, orderByComparator);
1694    
1695                    if (wikiPage != null) {
1696                            return wikiPage;
1697                    }
1698    
1699                    StringBundler msg = new StringBundler(4);
1700    
1701                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1702    
1703                    msg.append("nodeId=");
1704                    msg.append(nodeId);
1705    
1706                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1707    
1708                    throw new NoSuchPageException(msg.toString());
1709            }
1710    
1711            /**
1712             * Returns the last wiki page in the ordered set where nodeId = &#63;.
1713             *
1714             * @param nodeId the node ID
1715             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1716             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
1717             * @throws SystemException if a system exception occurred
1718             */
1719            @Override
1720            public WikiPage fetchByNodeId_Last(long nodeId,
1721                    OrderByComparator orderByComparator) throws SystemException {
1722                    int count = countByNodeId(nodeId);
1723    
1724                    if (count == 0) {
1725                            return null;
1726                    }
1727    
1728                    List<WikiPage> list = findByNodeId(nodeId, count - 1, count,
1729                                    orderByComparator);
1730    
1731                    if (!list.isEmpty()) {
1732                            return list.get(0);
1733                    }
1734    
1735                    return null;
1736            }
1737    
1738            /**
1739             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63;.
1740             *
1741             * @param pageId the primary key of the current wiki page
1742             * @param nodeId the node ID
1743             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1744             * @return the previous, current, and next wiki page
1745             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
1746             * @throws SystemException if a system exception occurred
1747             */
1748            @Override
1749            public WikiPage[] findByNodeId_PrevAndNext(long pageId, long nodeId,
1750                    OrderByComparator orderByComparator)
1751                    throws NoSuchPageException, SystemException {
1752                    WikiPage wikiPage = findByPrimaryKey(pageId);
1753    
1754                    Session session = null;
1755    
1756                    try {
1757                            session = openSession();
1758    
1759                            WikiPage[] array = new WikiPageImpl[3];
1760    
1761                            array[0] = getByNodeId_PrevAndNext(session, wikiPage, nodeId,
1762                                            orderByComparator, true);
1763    
1764                            array[1] = wikiPage;
1765    
1766                            array[2] = getByNodeId_PrevAndNext(session, wikiPage, nodeId,
1767                                            orderByComparator, false);
1768    
1769                            return array;
1770                    }
1771                    catch (Exception e) {
1772                            throw processException(e);
1773                    }
1774                    finally {
1775                            closeSession(session);
1776                    }
1777            }
1778    
1779            protected WikiPage getByNodeId_PrevAndNext(Session session,
1780                    WikiPage wikiPage, long nodeId, OrderByComparator orderByComparator,
1781                    boolean previous) {
1782                    StringBundler query = null;
1783    
1784                    if (orderByComparator != null) {
1785                            query = new StringBundler(6 +
1786                                            (orderByComparator.getOrderByFields().length * 6));
1787                    }
1788                    else {
1789                            query = new StringBundler(3);
1790                    }
1791    
1792                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1793    
1794                    query.append(_FINDER_COLUMN_NODEID_NODEID_2);
1795    
1796                    if (orderByComparator != null) {
1797                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1798    
1799                            if (orderByConditionFields.length > 0) {
1800                                    query.append(WHERE_AND);
1801                            }
1802    
1803                            for (int i = 0; i < orderByConditionFields.length; i++) {
1804                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1805                                    query.append(orderByConditionFields[i]);
1806    
1807                                    if ((i + 1) < orderByConditionFields.length) {
1808                                            if (orderByComparator.isAscending() ^ previous) {
1809                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1810                                            }
1811                                            else {
1812                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1813                                            }
1814                                    }
1815                                    else {
1816                                            if (orderByComparator.isAscending() ^ previous) {
1817                                                    query.append(WHERE_GREATER_THAN);
1818                                            }
1819                                            else {
1820                                                    query.append(WHERE_LESSER_THAN);
1821                                            }
1822                                    }
1823                            }
1824    
1825                            query.append(ORDER_BY_CLAUSE);
1826    
1827                            String[] orderByFields = orderByComparator.getOrderByFields();
1828    
1829                            for (int i = 0; i < orderByFields.length; i++) {
1830                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1831                                    query.append(orderByFields[i]);
1832    
1833                                    if ((i + 1) < orderByFields.length) {
1834                                            if (orderByComparator.isAscending() ^ previous) {
1835                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1836                                            }
1837                                            else {
1838                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1839                                            }
1840                                    }
1841                                    else {
1842                                            if (orderByComparator.isAscending() ^ previous) {
1843                                                    query.append(ORDER_BY_ASC);
1844                                            }
1845                                            else {
1846                                                    query.append(ORDER_BY_DESC);
1847                                            }
1848                                    }
1849                            }
1850                    }
1851                    else {
1852                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1853                    }
1854    
1855                    String sql = query.toString();
1856    
1857                    Query q = session.createQuery(sql);
1858    
1859                    q.setFirstResult(0);
1860                    q.setMaxResults(2);
1861    
1862                    QueryPos qPos = QueryPos.getInstance(q);
1863    
1864                    qPos.add(nodeId);
1865    
1866                    if (orderByComparator != null) {
1867                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
1868    
1869                            for (Object value : values) {
1870                                    qPos.add(value);
1871                            }
1872                    }
1873    
1874                    List<WikiPage> list = q.list();
1875    
1876                    if (list.size() == 2) {
1877                            return list.get(1);
1878                    }
1879                    else {
1880                            return null;
1881                    }
1882            }
1883    
1884            /**
1885             * Removes all the wiki pages where nodeId = &#63; from the database.
1886             *
1887             * @param nodeId the node ID
1888             * @throws SystemException if a system exception occurred
1889             */
1890            @Override
1891            public void removeByNodeId(long nodeId) throws SystemException {
1892                    for (WikiPage wikiPage : findByNodeId(nodeId, QueryUtil.ALL_POS,
1893                                    QueryUtil.ALL_POS, null)) {
1894                            remove(wikiPage);
1895                    }
1896            }
1897    
1898            /**
1899             * Returns the number of wiki pages where nodeId = &#63;.
1900             *
1901             * @param nodeId the node ID
1902             * @return the number of matching wiki pages
1903             * @throws SystemException if a system exception occurred
1904             */
1905            @Override
1906            public int countByNodeId(long nodeId) throws SystemException {
1907                    FinderPath finderPath = FINDER_PATH_COUNT_BY_NODEID;
1908    
1909                    Object[] finderArgs = new Object[] { nodeId };
1910    
1911                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1912                                    this);
1913    
1914                    if (count == null) {
1915                            StringBundler query = new StringBundler(2);
1916    
1917                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
1918    
1919                            query.append(_FINDER_COLUMN_NODEID_NODEID_2);
1920    
1921                            String sql = query.toString();
1922    
1923                            Session session = null;
1924    
1925                            try {
1926                                    session = openSession();
1927    
1928                                    Query q = session.createQuery(sql);
1929    
1930                                    QueryPos qPos = QueryPos.getInstance(q);
1931    
1932                                    qPos.add(nodeId);
1933    
1934                                    count = (Long)q.uniqueResult();
1935    
1936                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1937                            }
1938                            catch (Exception e) {
1939                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1940    
1941                                    throw processException(e);
1942                            }
1943                            finally {
1944                                    closeSession(session);
1945                            }
1946                    }
1947    
1948                    return count.intValue();
1949            }
1950    
1951            private static final String _FINDER_COLUMN_NODEID_NODEID_2 = "wikiPage.nodeId = ?";
1952            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_FORMAT = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1953                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1954                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByFormat",
1955                            new String[] {
1956                                    String.class.getName(),
1957                                    
1958                            Integer.class.getName(), Integer.class.getName(),
1959                                    OrderByComparator.class.getName()
1960                            });
1961            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT =
1962                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1963                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1964                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByFormat",
1965                            new String[] { String.class.getName() },
1966                            WikiPageModelImpl.FORMAT_COLUMN_BITMASK |
1967                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
1968                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
1969                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
1970            public static final FinderPath FINDER_PATH_COUNT_BY_FORMAT = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1971                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1972                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFormat",
1973                            new String[] { String.class.getName() });
1974    
1975            /**
1976             * Returns all the wiki pages where format = &#63;.
1977             *
1978             * @param format the format
1979             * @return the matching wiki pages
1980             * @throws SystemException if a system exception occurred
1981             */
1982            @Override
1983            public List<WikiPage> findByFormat(String format) throws SystemException {
1984                    return findByFormat(format, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1985            }
1986    
1987            /**
1988             * Returns a range of all the wiki pages where format = &#63;.
1989             *
1990             * <p>
1991             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1992             * </p>
1993             *
1994             * @param format the format
1995             * @param start the lower bound of the range of wiki pages
1996             * @param end the upper bound of the range of wiki pages (not inclusive)
1997             * @return the range of matching wiki pages
1998             * @throws SystemException if a system exception occurred
1999             */
2000            @Override
2001            public List<WikiPage> findByFormat(String format, int start, int end)
2002                    throws SystemException {
2003                    return findByFormat(format, start, end, null);
2004            }
2005    
2006            /**
2007             * Returns an ordered range of all the wiki pages where format = &#63;.
2008             *
2009             * <p>
2010             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2011             * </p>
2012             *
2013             * @param format the format
2014             * @param start the lower bound of the range of wiki pages
2015             * @param end the upper bound of the range of wiki pages (not inclusive)
2016             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2017             * @return the ordered range of matching wiki pages
2018             * @throws SystemException if a system exception occurred
2019             */
2020            @Override
2021            public List<WikiPage> findByFormat(String format, int start, int end,
2022                    OrderByComparator orderByComparator) throws SystemException {
2023                    boolean pagination = true;
2024                    FinderPath finderPath = null;
2025                    Object[] finderArgs = null;
2026    
2027                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2028                                    (orderByComparator == null)) {
2029                            pagination = false;
2030                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT;
2031                            finderArgs = new Object[] { format };
2032                    }
2033                    else {
2034                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FORMAT;
2035                            finderArgs = new Object[] { format, start, end, orderByComparator };
2036                    }
2037    
2038                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
2039                                    finderArgs, this);
2040    
2041                    if ((list != null) && !list.isEmpty()) {
2042                            for (WikiPage wikiPage : list) {
2043                                    if (!Validator.equals(format, wikiPage.getFormat())) {
2044                                            list = null;
2045    
2046                                            break;
2047                                    }
2048                            }
2049                    }
2050    
2051                    if (list == null) {
2052                            StringBundler query = null;
2053    
2054                            if (orderByComparator != null) {
2055                                    query = new StringBundler(3 +
2056                                                    (orderByComparator.getOrderByFields().length * 3));
2057                            }
2058                            else {
2059                                    query = new StringBundler(3);
2060                            }
2061    
2062                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2063    
2064                            boolean bindFormat = false;
2065    
2066                            if (format == null) {
2067                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_1);
2068                            }
2069                            else if (format.equals(StringPool.BLANK)) {
2070                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_3);
2071                            }
2072                            else {
2073                                    bindFormat = true;
2074    
2075                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_2);
2076                            }
2077    
2078                            if (orderByComparator != null) {
2079                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2080                                            orderByComparator);
2081                            }
2082                            else
2083                             if (pagination) {
2084                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2085                            }
2086    
2087                            String sql = query.toString();
2088    
2089                            Session session = null;
2090    
2091                            try {
2092                                    session = openSession();
2093    
2094                                    Query q = session.createQuery(sql);
2095    
2096                                    QueryPos qPos = QueryPos.getInstance(q);
2097    
2098                                    if (bindFormat) {
2099                                            qPos.add(format);
2100                                    }
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 format = &#63;.
2134             *
2135             * @param format the format
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 findByFormat_First(String format,
2143                    OrderByComparator orderByComparator)
2144                    throws NoSuchPageException, SystemException {
2145                    WikiPage wikiPage = fetchByFormat_First(format, 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("format=");
2156                    msg.append(format);
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 format = &#63;.
2165             *
2166             * @param format the format
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 fetchByFormat_First(String format,
2173                    OrderByComparator orderByComparator) throws SystemException {
2174                    List<WikiPage> list = findByFormat(format, 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 format = &#63;.
2185             *
2186             * @param format the format
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 findByFormat_Last(String format,
2194                    OrderByComparator orderByComparator)
2195                    throws NoSuchPageException, SystemException {
2196                    WikiPage wikiPage = fetchByFormat_Last(format, 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("format=");
2207                    msg.append(format);
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 format = &#63;.
2216             *
2217             * @param format the format
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 fetchByFormat_Last(String format,
2224                    OrderByComparator orderByComparator) throws SystemException {
2225                    int count = countByFormat(format);
2226    
2227                    if (count == 0) {
2228                            return null;
2229                    }
2230    
2231                    List<WikiPage> list = findByFormat(format, 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 format = &#63;.
2243             *
2244             * @param pageId the primary key of the current wiki page
2245             * @param format the format
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[] findByFormat_PrevAndNext(long pageId, String format,
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] = getByFormat_PrevAndNext(session, wikiPage, format,
2265                                            orderByComparator, true);
2266    
2267                            array[1] = wikiPage;
2268    
2269                            array[2] = getByFormat_PrevAndNext(session, wikiPage, format,
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 getByFormat_PrevAndNext(Session session,
2283                    WikiPage wikiPage, String format, 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                    boolean bindFormat = false;
2298    
2299                    if (format == null) {
2300                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_1);
2301                    }
2302                    else if (format.equals(StringPool.BLANK)) {
2303                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_3);
2304                    }
2305                    else {
2306                            bindFormat = true;
2307    
2308                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_2);
2309                    }
2310    
2311                    if (orderByComparator != null) {
2312                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2313    
2314                            if (orderByConditionFields.length > 0) {
2315                                    query.append(WHERE_AND);
2316                            }
2317    
2318                            for (int i = 0; i < orderByConditionFields.length; i++) {
2319                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2320                                    query.append(orderByConditionFields[i]);
2321    
2322                                    if ((i + 1) < orderByConditionFields.length) {
2323                                            if (orderByComparator.isAscending() ^ previous) {
2324                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2325                                            }
2326                                            else {
2327                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2328                                            }
2329                                    }
2330                                    else {
2331                                            if (orderByComparator.isAscending() ^ previous) {
2332                                                    query.append(WHERE_GREATER_THAN);
2333                                            }
2334                                            else {
2335                                                    query.append(WHERE_LESSER_THAN);
2336                                            }
2337                                    }
2338                            }
2339    
2340                            query.append(ORDER_BY_CLAUSE);
2341    
2342                            String[] orderByFields = orderByComparator.getOrderByFields();
2343    
2344                            for (int i = 0; i < orderByFields.length; i++) {
2345                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2346                                    query.append(orderByFields[i]);
2347    
2348                                    if ((i + 1) < orderByFields.length) {
2349                                            if (orderByComparator.isAscending() ^ previous) {
2350                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2351                                            }
2352                                            else {
2353                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2354                                            }
2355                                    }
2356                                    else {
2357                                            if (orderByComparator.isAscending() ^ previous) {
2358                                                    query.append(ORDER_BY_ASC);
2359                                            }
2360                                            else {
2361                                                    query.append(ORDER_BY_DESC);
2362                                            }
2363                                    }
2364                            }
2365                    }
2366                    else {
2367                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2368                    }
2369    
2370                    String sql = query.toString();
2371    
2372                    Query q = session.createQuery(sql);
2373    
2374                    q.setFirstResult(0);
2375                    q.setMaxResults(2);
2376    
2377                    QueryPos qPos = QueryPos.getInstance(q);
2378    
2379                    if (bindFormat) {
2380                            qPos.add(format);
2381                    }
2382    
2383                    if (orderByComparator != null) {
2384                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
2385    
2386                            for (Object value : values) {
2387                                    qPos.add(value);
2388                            }
2389                    }
2390    
2391                    List<WikiPage> list = q.list();
2392    
2393                    if (list.size() == 2) {
2394                            return list.get(1);
2395                    }
2396                    else {
2397                            return null;
2398                    }
2399            }
2400    
2401            /**
2402             * Removes all the wiki pages where format = &#63; from the database.
2403             *
2404             * @param format the format
2405             * @throws SystemException if a system exception occurred
2406             */
2407            @Override
2408            public void removeByFormat(String format) throws SystemException {
2409                    for (WikiPage wikiPage : findByFormat(format, QueryUtil.ALL_POS,
2410                                    QueryUtil.ALL_POS, null)) {
2411                            remove(wikiPage);
2412                    }
2413            }
2414    
2415            /**
2416             * Returns the number of wiki pages where format = &#63;.
2417             *
2418             * @param format the format
2419             * @return the number of matching wiki pages
2420             * @throws SystemException if a system exception occurred
2421             */
2422            @Override
2423            public int countByFormat(String format) throws SystemException {
2424                    FinderPath finderPath = FINDER_PATH_COUNT_BY_FORMAT;
2425    
2426                    Object[] finderArgs = new Object[] { format };
2427    
2428                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2429                                    this);
2430    
2431                    if (count == null) {
2432                            StringBundler query = new StringBundler(2);
2433    
2434                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
2435    
2436                            boolean bindFormat = false;
2437    
2438                            if (format == null) {
2439                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_1);
2440                            }
2441                            else if (format.equals(StringPool.BLANK)) {
2442                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_3);
2443                            }
2444                            else {
2445                                    bindFormat = true;
2446    
2447                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_2);
2448                            }
2449    
2450                            String sql = query.toString();
2451    
2452                            Session session = null;
2453    
2454                            try {
2455                                    session = openSession();
2456    
2457                                    Query q = session.createQuery(sql);
2458    
2459                                    QueryPos qPos = QueryPos.getInstance(q);
2460    
2461                                    if (bindFormat) {
2462                                            qPos.add(format);
2463                                    }
2464    
2465                                    count = (Long)q.uniqueResult();
2466    
2467                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2468                            }
2469                            catch (Exception e) {
2470                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2471    
2472                                    throw processException(e);
2473                            }
2474                            finally {
2475                                    closeSession(session);
2476                            }
2477                    }
2478    
2479                    return count.intValue();
2480            }
2481    
2482            private static final String _FINDER_COLUMN_FORMAT_FORMAT_1 = "wikiPage.format IS NULL";
2483            private static final String _FINDER_COLUMN_FORMAT_FORMAT_2 = "wikiPage.format = ?";
2484            private static final String _FINDER_COLUMN_FORMAT_FORMAT_3 = "(wikiPage.format IS NULL OR wikiPage.format = '')";
2485            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2486                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
2487                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_N",
2488                            new String[] {
2489                                    Long.class.getName(), Long.class.getName(),
2490                                    
2491                            Integer.class.getName(), Integer.class.getName(),
2492                                    OrderByComparator.class.getName()
2493                            });
2494            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2495                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
2496                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_N",
2497                            new String[] { Long.class.getName(), Long.class.getName() },
2498                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
2499                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
2500                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
2501                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
2502            public static final FinderPath FINDER_PATH_COUNT_BY_R_N = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2503                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2504                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N",
2505                            new String[] { Long.class.getName(), Long.class.getName() });
2506    
2507            /**
2508             * Returns all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
2509             *
2510             * @param resourcePrimKey the resource prim key
2511             * @param nodeId the node ID
2512             * @return the matching wiki pages
2513             * @throws SystemException if a system exception occurred
2514             */
2515            @Override
2516            public List<WikiPage> findByR_N(long resourcePrimKey, long nodeId)
2517                    throws SystemException {
2518                    return findByR_N(resourcePrimKey, nodeId, QueryUtil.ALL_POS,
2519                            QueryUtil.ALL_POS, null);
2520            }
2521    
2522            /**
2523             * Returns a range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
2524             *
2525             * <p>
2526             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2527             * </p>
2528             *
2529             * @param resourcePrimKey the resource prim key
2530             * @param nodeId the node ID
2531             * @param start the lower bound of the range of wiki pages
2532             * @param end the upper bound of the range of wiki pages (not inclusive)
2533             * @return the range of matching wiki pages
2534             * @throws SystemException if a system exception occurred
2535             */
2536            @Override
2537            public List<WikiPage> findByR_N(long resourcePrimKey, long nodeId,
2538                    int start, int end) throws SystemException {
2539                    return findByR_N(resourcePrimKey, nodeId, start, end, null);
2540            }
2541    
2542            /**
2543             * Returns an ordered range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
2544             *
2545             * <p>
2546             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2547             * </p>
2548             *
2549             * @param resourcePrimKey the resource prim key
2550             * @param nodeId the node ID
2551             * @param start the lower bound of the range of wiki pages
2552             * @param end the upper bound of the range of wiki pages (not inclusive)
2553             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2554             * @return the ordered range of matching wiki pages
2555             * @throws SystemException if a system exception occurred
2556             */
2557            @Override
2558            public List<WikiPage> findByR_N(long resourcePrimKey, long nodeId,
2559                    int start, int end, OrderByComparator orderByComparator)
2560                    throws SystemException {
2561                    boolean pagination = true;
2562                    FinderPath finderPath = null;
2563                    Object[] finderArgs = null;
2564    
2565                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2566                                    (orderByComparator == null)) {
2567                            pagination = false;
2568                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N;
2569                            finderArgs = new Object[] { resourcePrimKey, nodeId };
2570                    }
2571                    else {
2572                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N;
2573                            finderArgs = new Object[] {
2574                                            resourcePrimKey, nodeId,
2575                                            
2576                                            start, end, orderByComparator
2577                                    };
2578                    }
2579    
2580                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
2581                                    finderArgs, this);
2582    
2583                    if ((list != null) && !list.isEmpty()) {
2584                            for (WikiPage wikiPage : list) {
2585                                    if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
2586                                                    (nodeId != wikiPage.getNodeId())) {
2587                                            list = null;
2588    
2589                                            break;
2590                                    }
2591                            }
2592                    }
2593    
2594                    if (list == null) {
2595                            StringBundler query = null;
2596    
2597                            if (orderByComparator != null) {
2598                                    query = new StringBundler(4 +
2599                                                    (orderByComparator.getOrderByFields().length * 3));
2600                            }
2601                            else {
2602                                    query = new StringBundler(4);
2603                            }
2604    
2605                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2606    
2607                            query.append(_FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2);
2608    
2609                            query.append(_FINDER_COLUMN_R_N_NODEID_2);
2610    
2611                            if (orderByComparator != null) {
2612                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2613                                            orderByComparator);
2614                            }
2615                            else
2616                             if (pagination) {
2617                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2618                            }
2619    
2620                            String sql = query.toString();
2621    
2622                            Session session = null;
2623    
2624                            try {
2625                                    session = openSession();
2626    
2627                                    Query q = session.createQuery(sql);
2628    
2629                                    QueryPos qPos = QueryPos.getInstance(q);
2630    
2631                                    qPos.add(resourcePrimKey);
2632    
2633                                    qPos.add(nodeId);
2634    
2635                                    if (!pagination) {
2636                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
2637                                                            start, end, false);
2638    
2639                                            Collections.sort(list);
2640    
2641                                            list = new UnmodifiableList<WikiPage>(list);
2642                                    }
2643                                    else {
2644                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
2645                                                            start, end);
2646                                    }
2647    
2648                                    cacheResult(list);
2649    
2650                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2651                            }
2652                            catch (Exception e) {
2653                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2654    
2655                                    throw processException(e);
2656                            }
2657                            finally {
2658                                    closeSession(session);
2659                            }
2660                    }
2661    
2662                    return list;
2663            }
2664    
2665            /**
2666             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2667             *
2668             * @param resourcePrimKey the resource prim key
2669             * @param nodeId the node ID
2670             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2671             * @return the first matching wiki page
2672             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2673             * @throws SystemException if a system exception occurred
2674             */
2675            @Override
2676            public WikiPage findByR_N_First(long resourcePrimKey, long nodeId,
2677                    OrderByComparator orderByComparator)
2678                    throws NoSuchPageException, SystemException {
2679                    WikiPage wikiPage = fetchByR_N_First(resourcePrimKey, nodeId,
2680                                    orderByComparator);
2681    
2682                    if (wikiPage != null) {
2683                            return wikiPage;
2684                    }
2685    
2686                    StringBundler msg = new StringBundler(6);
2687    
2688                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2689    
2690                    msg.append("resourcePrimKey=");
2691                    msg.append(resourcePrimKey);
2692    
2693                    msg.append(", nodeId=");
2694                    msg.append(nodeId);
2695    
2696                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2697    
2698                    throw new NoSuchPageException(msg.toString());
2699            }
2700    
2701            /**
2702             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2703             *
2704             * @param resourcePrimKey the resource prim key
2705             * @param nodeId the node ID
2706             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2707             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
2708             * @throws SystemException if a system exception occurred
2709             */
2710            @Override
2711            public WikiPage fetchByR_N_First(long resourcePrimKey, long nodeId,
2712                    OrderByComparator orderByComparator) throws SystemException {
2713                    List<WikiPage> list = findByR_N(resourcePrimKey, nodeId, 0, 1,
2714                                    orderByComparator);
2715    
2716                    if (!list.isEmpty()) {
2717                            return list.get(0);
2718                    }
2719    
2720                    return null;
2721            }
2722    
2723            /**
2724             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2725             *
2726             * @param resourcePrimKey the resource prim key
2727             * @param nodeId the node ID
2728             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2729             * @return the last matching wiki page
2730             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2731             * @throws SystemException if a system exception occurred
2732             */
2733            @Override
2734            public WikiPage findByR_N_Last(long resourcePrimKey, long nodeId,
2735                    OrderByComparator orderByComparator)
2736                    throws NoSuchPageException, SystemException {
2737                    WikiPage wikiPage = fetchByR_N_Last(resourcePrimKey, nodeId,
2738                                    orderByComparator);
2739    
2740                    if (wikiPage != null) {
2741                            return wikiPage;
2742                    }
2743    
2744                    StringBundler msg = new StringBundler(6);
2745    
2746                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2747    
2748                    msg.append("resourcePrimKey=");
2749                    msg.append(resourcePrimKey);
2750    
2751                    msg.append(", nodeId=");
2752                    msg.append(nodeId);
2753    
2754                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2755    
2756                    throw new NoSuchPageException(msg.toString());
2757            }
2758    
2759            /**
2760             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2761             *
2762             * @param resourcePrimKey the resource prim key
2763             * @param nodeId the node ID
2764             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2765             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
2766             * @throws SystemException if a system exception occurred
2767             */
2768            @Override
2769            public WikiPage fetchByR_N_Last(long resourcePrimKey, long nodeId,
2770                    OrderByComparator orderByComparator) throws SystemException {
2771                    int count = countByR_N(resourcePrimKey, nodeId);
2772    
2773                    if (count == 0) {
2774                            return null;
2775                    }
2776    
2777                    List<WikiPage> list = findByR_N(resourcePrimKey, nodeId, count - 1,
2778                                    count, orderByComparator);
2779    
2780                    if (!list.isEmpty()) {
2781                            return list.get(0);
2782                    }
2783    
2784                    return null;
2785            }
2786    
2787            /**
2788             * Returns the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2789             *
2790             * @param pageId the primary key of the current wiki page
2791             * @param resourcePrimKey the resource prim key
2792             * @param nodeId the node ID
2793             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2794             * @return the previous, current, and next wiki page
2795             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
2796             * @throws SystemException if a system exception occurred
2797             */
2798            @Override
2799            public WikiPage[] findByR_N_PrevAndNext(long pageId, long resourcePrimKey,
2800                    long nodeId, OrderByComparator orderByComparator)
2801                    throws NoSuchPageException, SystemException {
2802                    WikiPage wikiPage = findByPrimaryKey(pageId);
2803    
2804                    Session session = null;
2805    
2806                    try {
2807                            session = openSession();
2808    
2809                            WikiPage[] array = new WikiPageImpl[3];
2810    
2811                            array[0] = getByR_N_PrevAndNext(session, wikiPage, resourcePrimKey,
2812                                            nodeId, orderByComparator, true);
2813    
2814                            array[1] = wikiPage;
2815    
2816                            array[2] = getByR_N_PrevAndNext(session, wikiPage, resourcePrimKey,
2817                                            nodeId, orderByComparator, false);
2818    
2819                            return array;
2820                    }
2821                    catch (Exception e) {
2822                            throw processException(e);
2823                    }
2824                    finally {
2825                            closeSession(session);
2826                    }
2827            }
2828    
2829            protected WikiPage getByR_N_PrevAndNext(Session session, WikiPage wikiPage,
2830                    long resourcePrimKey, long nodeId, OrderByComparator orderByComparator,
2831                    boolean previous) {
2832                    StringBundler query = null;
2833    
2834                    if (orderByComparator != null) {
2835                            query = new StringBundler(6 +
2836                                            (orderByComparator.getOrderByFields().length * 6));
2837                    }
2838                    else {
2839                            query = new StringBundler(3);
2840                    }
2841    
2842                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2843    
2844                    query.append(_FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2);
2845    
2846                    query.append(_FINDER_COLUMN_R_N_NODEID_2);
2847    
2848                    if (orderByComparator != null) {
2849                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2850    
2851                            if (orderByConditionFields.length > 0) {
2852                                    query.append(WHERE_AND);
2853                            }
2854    
2855                            for (int i = 0; i < orderByConditionFields.length; i++) {
2856                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2857                                    query.append(orderByConditionFields[i]);
2858    
2859                                    if ((i + 1) < orderByConditionFields.length) {
2860                                            if (orderByComparator.isAscending() ^ previous) {
2861                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2862                                            }
2863                                            else {
2864                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2865                                            }
2866                                    }
2867                                    else {
2868                                            if (orderByComparator.isAscending() ^ previous) {
2869                                                    query.append(WHERE_GREATER_THAN);
2870                                            }
2871                                            else {
2872                                                    query.append(WHERE_LESSER_THAN);
2873                                            }
2874                                    }
2875                            }
2876    
2877                            query.append(ORDER_BY_CLAUSE);
2878    
2879                            String[] orderByFields = orderByComparator.getOrderByFields();
2880    
2881                            for (int i = 0; i < orderByFields.length; i++) {
2882                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2883                                    query.append(orderByFields[i]);
2884    
2885                                    if ((i + 1) < orderByFields.length) {
2886                                            if (orderByComparator.isAscending() ^ previous) {
2887                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2888                                            }
2889                                            else {
2890                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2891                                            }
2892                                    }
2893                                    else {
2894                                            if (orderByComparator.isAscending() ^ previous) {
2895                                                    query.append(ORDER_BY_ASC);
2896                                            }
2897                                            else {
2898                                                    query.append(ORDER_BY_DESC);
2899                                            }
2900                                    }
2901                            }
2902                    }
2903                    else {
2904                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2905                    }
2906    
2907                    String sql = query.toString();
2908    
2909                    Query q = session.createQuery(sql);
2910    
2911                    q.setFirstResult(0);
2912                    q.setMaxResults(2);
2913    
2914                    QueryPos qPos = QueryPos.getInstance(q);
2915    
2916                    qPos.add(resourcePrimKey);
2917    
2918                    qPos.add(nodeId);
2919    
2920                    if (orderByComparator != null) {
2921                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
2922    
2923                            for (Object value : values) {
2924                                    qPos.add(value);
2925                            }
2926                    }
2927    
2928                    List<WikiPage> list = q.list();
2929    
2930                    if (list.size() == 2) {
2931                            return list.get(1);
2932                    }
2933                    else {
2934                            return null;
2935                    }
2936            }
2937    
2938            /**
2939             * Removes all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; from the database.
2940             *
2941             * @param resourcePrimKey the resource prim key
2942             * @param nodeId the node ID
2943             * @throws SystemException if a system exception occurred
2944             */
2945            @Override
2946            public void removeByR_N(long resourcePrimKey, long nodeId)
2947                    throws SystemException {
2948                    for (WikiPage wikiPage : findByR_N(resourcePrimKey, nodeId,
2949                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2950                            remove(wikiPage);
2951                    }
2952            }
2953    
2954            /**
2955             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
2956             *
2957             * @param resourcePrimKey the resource prim key
2958             * @param nodeId the node ID
2959             * @return the number of matching wiki pages
2960             * @throws SystemException if a system exception occurred
2961             */
2962            @Override
2963            public int countByR_N(long resourcePrimKey, long nodeId)
2964                    throws SystemException {
2965                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N;
2966    
2967                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId };
2968    
2969                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2970                                    this);
2971    
2972                    if (count == null) {
2973                            StringBundler query = new StringBundler(3);
2974    
2975                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
2976    
2977                            query.append(_FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2);
2978    
2979                            query.append(_FINDER_COLUMN_R_N_NODEID_2);
2980    
2981                            String sql = query.toString();
2982    
2983                            Session session = null;
2984    
2985                            try {
2986                                    session = openSession();
2987    
2988                                    Query q = session.createQuery(sql);
2989    
2990                                    QueryPos qPos = QueryPos.getInstance(q);
2991    
2992                                    qPos.add(resourcePrimKey);
2993    
2994                                    qPos.add(nodeId);
2995    
2996                                    count = (Long)q.uniqueResult();
2997    
2998                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2999                            }
3000                            catch (Exception e) {
3001                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3002    
3003                                    throw processException(e);
3004                            }
3005                            finally {
3006                                    closeSession(session);
3007                            }
3008                    }
3009    
3010                    return count.intValue();
3011            }
3012    
3013            private static final String _FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
3014            private static final String _FINDER_COLUMN_R_N_NODEID_2 = "wikiPage.nodeId = ?";
3015            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3016                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
3017                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_T",
3018                            new String[] {
3019                                    Long.class.getName(), String.class.getName(),
3020                                    
3021                            Integer.class.getName(), Integer.class.getName(),
3022                                    OrderByComparator.class.getName()
3023                            });
3024            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3025                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
3026                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_T",
3027                            new String[] { Long.class.getName(), String.class.getName() },
3028                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
3029                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
3030                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
3031            public static final FinderPath FINDER_PATH_COUNT_BY_N_T = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3032                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3033                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T",
3034                            new String[] { Long.class.getName(), String.class.getName() });
3035    
3036            /**
3037             * Returns all the wiki pages where nodeId = &#63; and title = &#63;.
3038             *
3039             * @param nodeId the node ID
3040             * @param title the title
3041             * @return the matching wiki pages
3042             * @throws SystemException if a system exception occurred
3043             */
3044            @Override
3045            public List<WikiPage> findByN_T(long nodeId, String title)
3046                    throws SystemException {
3047                    return findByN_T(nodeId, title, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3048                            null);
3049            }
3050    
3051            /**
3052             * Returns a range of all the wiki pages where nodeId = &#63; and title = &#63;.
3053             *
3054             * <p>
3055             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3056             * </p>
3057             *
3058             * @param nodeId the node ID
3059             * @param title the title
3060             * @param start the lower bound of the range of wiki pages
3061             * @param end the upper bound of the range of wiki pages (not inclusive)
3062             * @return the range of matching wiki pages
3063             * @throws SystemException if a system exception occurred
3064             */
3065            @Override
3066            public List<WikiPage> findByN_T(long nodeId, String title, int start,
3067                    int end) throws SystemException {
3068                    return findByN_T(nodeId, title, start, end, null);
3069            }
3070    
3071            /**
3072             * Returns an ordered range of all the wiki pages where nodeId = &#63; and title = &#63;.
3073             *
3074             * <p>
3075             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3076             * </p>
3077             *
3078             * @param nodeId the node ID
3079             * @param title the title
3080             * @param start the lower bound of the range of wiki pages
3081             * @param end the upper bound of the range of wiki pages (not inclusive)
3082             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3083             * @return the ordered range of matching wiki pages
3084             * @throws SystemException if a system exception occurred
3085             */
3086            @Override
3087            public List<WikiPage> findByN_T(long nodeId, String title, int start,
3088                    int end, OrderByComparator orderByComparator) throws SystemException {
3089                    boolean pagination = true;
3090                    FinderPath finderPath = null;
3091                    Object[] finderArgs = null;
3092    
3093                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3094                                    (orderByComparator == null)) {
3095                            pagination = false;
3096                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T;
3097                            finderArgs = new Object[] { nodeId, title };
3098                    }
3099                    else {
3100                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T;
3101                            finderArgs = new Object[] {
3102                                            nodeId, title,
3103                                            
3104                                            start, end, orderByComparator
3105                                    };
3106                    }
3107    
3108                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
3109                                    finderArgs, this);
3110    
3111                    if ((list != null) && !list.isEmpty()) {
3112                            for (WikiPage wikiPage : list) {
3113                                    if ((nodeId != wikiPage.getNodeId()) ||
3114                                                    !Validator.equals(title, wikiPage.getTitle())) {
3115                                            list = null;
3116    
3117                                            break;
3118                                    }
3119                            }
3120                    }
3121    
3122                    if (list == null) {
3123                            StringBundler query = null;
3124    
3125                            if (orderByComparator != null) {
3126                                    query = new StringBundler(4 +
3127                                                    (orderByComparator.getOrderByFields().length * 3));
3128                            }
3129                            else {
3130                                    query = new StringBundler(4);
3131                            }
3132    
3133                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3134    
3135                            query.append(_FINDER_COLUMN_N_T_NODEID_2);
3136    
3137                            boolean bindTitle = false;
3138    
3139                            if (title == null) {
3140                                    query.append(_FINDER_COLUMN_N_T_TITLE_1);
3141                            }
3142                            else if (title.equals(StringPool.BLANK)) {
3143                                    query.append(_FINDER_COLUMN_N_T_TITLE_3);
3144                            }
3145                            else {
3146                                    bindTitle = true;
3147    
3148                                    query.append(_FINDER_COLUMN_N_T_TITLE_2);
3149                            }
3150    
3151                            if (orderByComparator != null) {
3152                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3153                                            orderByComparator);
3154                            }
3155                            else
3156                             if (pagination) {
3157                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3158                            }
3159    
3160                            String sql = query.toString();
3161    
3162                            Session session = null;
3163    
3164                            try {
3165                                    session = openSession();
3166    
3167                                    Query q = session.createQuery(sql);
3168    
3169                                    QueryPos qPos = QueryPos.getInstance(q);
3170    
3171                                    qPos.add(nodeId);
3172    
3173                                    if (bindTitle) {
3174                                            qPos.add(title.toLowerCase());
3175                                    }
3176    
3177                                    if (!pagination) {
3178                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3179                                                            start, end, false);
3180    
3181                                            Collections.sort(list);
3182    
3183                                            list = new UnmodifiableList<WikiPage>(list);
3184                                    }
3185                                    else {
3186                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3187                                                            start, end);
3188                                    }
3189    
3190                                    cacheResult(list);
3191    
3192                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3193                            }
3194                            catch (Exception e) {
3195                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3196    
3197                                    throw processException(e);
3198                            }
3199                            finally {
3200                                    closeSession(session);
3201                            }
3202                    }
3203    
3204                    return list;
3205            }
3206    
3207            /**
3208             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63;.
3209             *
3210             * @param nodeId the node ID
3211             * @param title the title
3212             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3213             * @return the first matching wiki page
3214             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3215             * @throws SystemException if a system exception occurred
3216             */
3217            @Override
3218            public WikiPage findByN_T_First(long nodeId, String title,
3219                    OrderByComparator orderByComparator)
3220                    throws NoSuchPageException, SystemException {
3221                    WikiPage wikiPage = fetchByN_T_First(nodeId, title, orderByComparator);
3222    
3223                    if (wikiPage != null) {
3224                            return wikiPage;
3225                    }
3226    
3227                    StringBundler msg = new StringBundler(6);
3228    
3229                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3230    
3231                    msg.append("nodeId=");
3232                    msg.append(nodeId);
3233    
3234                    msg.append(", title=");
3235                    msg.append(title);
3236    
3237                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3238    
3239                    throw new NoSuchPageException(msg.toString());
3240            }
3241    
3242            /**
3243             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63;.
3244             *
3245             * @param nodeId the node ID
3246             * @param title the title
3247             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3248             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
3249             * @throws SystemException if a system exception occurred
3250             */
3251            @Override
3252            public WikiPage fetchByN_T_First(long nodeId, String title,
3253                    OrderByComparator orderByComparator) throws SystemException {
3254                    List<WikiPage> list = findByN_T(nodeId, title, 0, 1, orderByComparator);
3255    
3256                    if (!list.isEmpty()) {
3257                            return list.get(0);
3258                    }
3259    
3260                    return null;
3261            }
3262    
3263            /**
3264             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63;.
3265             *
3266             * @param nodeId the node ID
3267             * @param title the title
3268             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3269             * @return the last matching wiki page
3270             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3271             * @throws SystemException if a system exception occurred
3272             */
3273            @Override
3274            public WikiPage findByN_T_Last(long nodeId, String title,
3275                    OrderByComparator orderByComparator)
3276                    throws NoSuchPageException, SystemException {
3277                    WikiPage wikiPage = fetchByN_T_Last(nodeId, title, orderByComparator);
3278    
3279                    if (wikiPage != null) {
3280                            return wikiPage;
3281                    }
3282    
3283                    StringBundler msg = new StringBundler(6);
3284    
3285                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3286    
3287                    msg.append("nodeId=");
3288                    msg.append(nodeId);
3289    
3290                    msg.append(", title=");
3291                    msg.append(title);
3292    
3293                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3294    
3295                    throw new NoSuchPageException(msg.toString());
3296            }
3297    
3298            /**
3299             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63;.
3300             *
3301             * @param nodeId the node ID
3302             * @param title the title
3303             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3304             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
3305             * @throws SystemException if a system exception occurred
3306             */
3307            @Override
3308            public WikiPage fetchByN_T_Last(long nodeId, String title,
3309                    OrderByComparator orderByComparator) throws SystemException {
3310                    int count = countByN_T(nodeId, title);
3311    
3312                    if (count == 0) {
3313                            return null;
3314                    }
3315    
3316                    List<WikiPage> list = findByN_T(nodeId, title, count - 1, count,
3317                                    orderByComparator);
3318    
3319                    if (!list.isEmpty()) {
3320                            return list.get(0);
3321                    }
3322    
3323                    return null;
3324            }
3325    
3326            /**
3327             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and title = &#63;.
3328             *
3329             * @param pageId the primary key of the current wiki page
3330             * @param nodeId the node ID
3331             * @param title the title
3332             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3333             * @return the previous, current, and next wiki page
3334             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
3335             * @throws SystemException if a system exception occurred
3336             */
3337            @Override
3338            public WikiPage[] findByN_T_PrevAndNext(long pageId, long nodeId,
3339                    String title, OrderByComparator orderByComparator)
3340                    throws NoSuchPageException, SystemException {
3341                    WikiPage wikiPage = findByPrimaryKey(pageId);
3342    
3343                    Session session = null;
3344    
3345                    try {
3346                            session = openSession();
3347    
3348                            WikiPage[] array = new WikiPageImpl[3];
3349    
3350                            array[0] = getByN_T_PrevAndNext(session, wikiPage, nodeId, title,
3351                                            orderByComparator, true);
3352    
3353                            array[1] = wikiPage;
3354    
3355                            array[2] = getByN_T_PrevAndNext(session, wikiPage, nodeId, title,
3356                                            orderByComparator, false);
3357    
3358                            return array;
3359                    }
3360                    catch (Exception e) {
3361                            throw processException(e);
3362                    }
3363                    finally {
3364                            closeSession(session);
3365                    }
3366            }
3367    
3368            protected WikiPage getByN_T_PrevAndNext(Session session, WikiPage wikiPage,
3369                    long nodeId, String title, OrderByComparator orderByComparator,
3370                    boolean previous) {
3371                    StringBundler query = null;
3372    
3373                    if (orderByComparator != null) {
3374                            query = new StringBundler(6 +
3375                                            (orderByComparator.getOrderByFields().length * 6));
3376                    }
3377                    else {
3378                            query = new StringBundler(3);
3379                    }
3380    
3381                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3382    
3383                    query.append(_FINDER_COLUMN_N_T_NODEID_2);
3384    
3385                    boolean bindTitle = false;
3386    
3387                    if (title == null) {
3388                            query.append(_FINDER_COLUMN_N_T_TITLE_1);
3389                    }
3390                    else if (title.equals(StringPool.BLANK)) {
3391                            query.append(_FINDER_COLUMN_N_T_TITLE_3);
3392                    }
3393                    else {
3394                            bindTitle = true;
3395    
3396                            query.append(_FINDER_COLUMN_N_T_TITLE_2);
3397                    }
3398    
3399                    if (orderByComparator != null) {
3400                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3401    
3402                            if (orderByConditionFields.length > 0) {
3403                                    query.append(WHERE_AND);
3404                            }
3405    
3406                            for (int i = 0; i < orderByConditionFields.length; i++) {
3407                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3408                                    query.append(orderByConditionFields[i]);
3409    
3410                                    if ((i + 1) < orderByConditionFields.length) {
3411                                            if (orderByComparator.isAscending() ^ previous) {
3412                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3413                                            }
3414                                            else {
3415                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3416                                            }
3417                                    }
3418                                    else {
3419                                            if (orderByComparator.isAscending() ^ previous) {
3420                                                    query.append(WHERE_GREATER_THAN);
3421                                            }
3422                                            else {
3423                                                    query.append(WHERE_LESSER_THAN);
3424                                            }
3425                                    }
3426                            }
3427    
3428                            query.append(ORDER_BY_CLAUSE);
3429    
3430                            String[] orderByFields = orderByComparator.getOrderByFields();
3431    
3432                            for (int i = 0; i < orderByFields.length; i++) {
3433                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3434                                    query.append(orderByFields[i]);
3435    
3436                                    if ((i + 1) < orderByFields.length) {
3437                                            if (orderByComparator.isAscending() ^ previous) {
3438                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3439                                            }
3440                                            else {
3441                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3442                                            }
3443                                    }
3444                                    else {
3445                                            if (orderByComparator.isAscending() ^ previous) {
3446                                                    query.append(ORDER_BY_ASC);
3447                                            }
3448                                            else {
3449                                                    query.append(ORDER_BY_DESC);
3450                                            }
3451                                    }
3452                            }
3453                    }
3454                    else {
3455                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3456                    }
3457    
3458                    String sql = query.toString();
3459    
3460                    Query q = session.createQuery(sql);
3461    
3462                    q.setFirstResult(0);
3463                    q.setMaxResults(2);
3464    
3465                    QueryPos qPos = QueryPos.getInstance(q);
3466    
3467                    qPos.add(nodeId);
3468    
3469                    if (bindTitle) {
3470                            qPos.add(title.toLowerCase());
3471                    }
3472    
3473                    if (orderByComparator != null) {
3474                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
3475    
3476                            for (Object value : values) {
3477                                    qPos.add(value);
3478                            }
3479                    }
3480    
3481                    List<WikiPage> list = q.list();
3482    
3483                    if (list.size() == 2) {
3484                            return list.get(1);
3485                    }
3486                    else {
3487                            return null;
3488                    }
3489            }
3490    
3491            /**
3492             * Removes all the wiki pages where nodeId = &#63; and title = &#63; from the database.
3493             *
3494             * @param nodeId the node ID
3495             * @param title the title
3496             * @throws SystemException if a system exception occurred
3497             */
3498            @Override
3499            public void removeByN_T(long nodeId, String title)
3500                    throws SystemException {
3501                    for (WikiPage wikiPage : findByN_T(nodeId, title, QueryUtil.ALL_POS,
3502                                    QueryUtil.ALL_POS, null)) {
3503                            remove(wikiPage);
3504                    }
3505            }
3506    
3507            /**
3508             * Returns the number of wiki pages where nodeId = &#63; and title = &#63;.
3509             *
3510             * @param nodeId the node ID
3511             * @param title the title
3512             * @return the number of matching wiki pages
3513             * @throws SystemException if a system exception occurred
3514             */
3515            @Override
3516            public int countByN_T(long nodeId, String title) throws SystemException {
3517                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T;
3518    
3519                    Object[] finderArgs = new Object[] { nodeId, title };
3520    
3521                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3522                                    this);
3523    
3524                    if (count == null) {
3525                            StringBundler query = new StringBundler(3);
3526    
3527                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
3528    
3529                            query.append(_FINDER_COLUMN_N_T_NODEID_2);
3530    
3531                            boolean bindTitle = false;
3532    
3533                            if (title == null) {
3534                                    query.append(_FINDER_COLUMN_N_T_TITLE_1);
3535                            }
3536                            else if (title.equals(StringPool.BLANK)) {
3537                                    query.append(_FINDER_COLUMN_N_T_TITLE_3);
3538                            }
3539                            else {
3540                                    bindTitle = true;
3541    
3542                                    query.append(_FINDER_COLUMN_N_T_TITLE_2);
3543                            }
3544    
3545                            String sql = query.toString();
3546    
3547                            Session session = null;
3548    
3549                            try {
3550                                    session = openSession();
3551    
3552                                    Query q = session.createQuery(sql);
3553    
3554                                    QueryPos qPos = QueryPos.getInstance(q);
3555    
3556                                    qPos.add(nodeId);
3557    
3558                                    if (bindTitle) {
3559                                            qPos.add(title.toLowerCase());
3560                                    }
3561    
3562                                    count = (Long)q.uniqueResult();
3563    
3564                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3565                            }
3566                            catch (Exception e) {
3567                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3568    
3569                                    throw processException(e);
3570                            }
3571                            finally {
3572                                    closeSession(session);
3573                            }
3574                    }
3575    
3576                    return count.intValue();
3577            }
3578    
3579            private static final String _FINDER_COLUMN_N_T_NODEID_2 = "wikiPage.nodeId = ? AND ";
3580            private static final String _FINDER_COLUMN_N_T_TITLE_1 = "wikiPage.title IS NULL";
3581            private static final String _FINDER_COLUMN_N_T_TITLE_2 = "lower(wikiPage.title) = ?";
3582            private static final String _FINDER_COLUMN_N_T_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '')";
3583            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3584                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
3585                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H",
3586                            new String[] {
3587                                    Long.class.getName(), Boolean.class.getName(),
3588                                    
3589                            Integer.class.getName(), Integer.class.getName(),
3590                                    OrderByComparator.class.getName()
3591                            });
3592            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3593                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
3594                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H",
3595                            new String[] { Long.class.getName(), Boolean.class.getName() },
3596                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
3597                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
3598                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
3599                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
3600            public static final FinderPath FINDER_PATH_COUNT_BY_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3601                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3602                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H",
3603                            new String[] { Long.class.getName(), Boolean.class.getName() });
3604    
3605            /**
3606             * Returns all the wiki pages where nodeId = &#63; and head = &#63;.
3607             *
3608             * @param nodeId the node ID
3609             * @param head the head
3610             * @return the matching wiki pages
3611             * @throws SystemException if a system exception occurred
3612             */
3613            @Override
3614            public List<WikiPage> findByN_H(long nodeId, boolean head)
3615                    throws SystemException {
3616                    return findByN_H(nodeId, head, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3617                            null);
3618            }
3619    
3620            /**
3621             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63;.
3622             *
3623             * <p>
3624             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3625             * </p>
3626             *
3627             * @param nodeId the node ID
3628             * @param head the head
3629             * @param start the lower bound of the range of wiki pages
3630             * @param end the upper bound of the range of wiki pages (not inclusive)
3631             * @return the range of matching wiki pages
3632             * @throws SystemException if a system exception occurred
3633             */
3634            @Override
3635            public List<WikiPage> findByN_H(long nodeId, boolean head, int start,
3636                    int end) throws SystemException {
3637                    return findByN_H(nodeId, head, start, end, null);
3638            }
3639    
3640            /**
3641             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63;.
3642             *
3643             * <p>
3644             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3645             * </p>
3646             *
3647             * @param nodeId the node ID
3648             * @param head the head
3649             * @param start the lower bound of the range of wiki pages
3650             * @param end the upper bound of the range of wiki pages (not inclusive)
3651             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3652             * @return the ordered range of matching wiki pages
3653             * @throws SystemException if a system exception occurred
3654             */
3655            @Override
3656            public List<WikiPage> findByN_H(long nodeId, boolean head, int start,
3657                    int end, OrderByComparator orderByComparator) throws SystemException {
3658                    boolean pagination = true;
3659                    FinderPath finderPath = null;
3660                    Object[] finderArgs = null;
3661    
3662                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3663                                    (orderByComparator == null)) {
3664                            pagination = false;
3665                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H;
3666                            finderArgs = new Object[] { nodeId, head };
3667                    }
3668                    else {
3669                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H;
3670                            finderArgs = new Object[] {
3671                                            nodeId, head,
3672                                            
3673                                            start, end, orderByComparator
3674                                    };
3675                    }
3676    
3677                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
3678                                    finderArgs, this);
3679    
3680                    if ((list != null) && !list.isEmpty()) {
3681                            for (WikiPage wikiPage : list) {
3682                                    if ((nodeId != wikiPage.getNodeId()) ||
3683                                                    (head != wikiPage.getHead())) {
3684                                            list = null;
3685    
3686                                            break;
3687                                    }
3688                            }
3689                    }
3690    
3691                    if (list == null) {
3692                            StringBundler query = null;
3693    
3694                            if (orderByComparator != null) {
3695                                    query = new StringBundler(4 +
3696                                                    (orderByComparator.getOrderByFields().length * 3));
3697                            }
3698                            else {
3699                                    query = new StringBundler(4);
3700                            }
3701    
3702                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3703    
3704                            query.append(_FINDER_COLUMN_N_H_NODEID_2);
3705    
3706                            query.append(_FINDER_COLUMN_N_H_HEAD_2);
3707    
3708                            if (orderByComparator != null) {
3709                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3710                                            orderByComparator);
3711                            }
3712                            else
3713                             if (pagination) {
3714                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3715                            }
3716    
3717                            String sql = query.toString();
3718    
3719                            Session session = null;
3720    
3721                            try {
3722                                    session = openSession();
3723    
3724                                    Query q = session.createQuery(sql);
3725    
3726                                    QueryPos qPos = QueryPos.getInstance(q);
3727    
3728                                    qPos.add(nodeId);
3729    
3730                                    qPos.add(head);
3731    
3732                                    if (!pagination) {
3733                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3734                                                            start, end, false);
3735    
3736                                            Collections.sort(list);
3737    
3738                                            list = new UnmodifiableList<WikiPage>(list);
3739                                    }
3740                                    else {
3741                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3742                                                            start, end);
3743                                    }
3744    
3745                                    cacheResult(list);
3746    
3747                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3748                            }
3749                            catch (Exception e) {
3750                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3751    
3752                                    throw processException(e);
3753                            }
3754                            finally {
3755                                    closeSession(session);
3756                            }
3757                    }
3758    
3759                    return list;
3760            }
3761    
3762            /**
3763             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63;.
3764             *
3765             * @param nodeId the node ID
3766             * @param head the head
3767             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3768             * @return the first matching wiki page
3769             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3770             * @throws SystemException if a system exception occurred
3771             */
3772            @Override
3773            public WikiPage findByN_H_First(long nodeId, boolean head,
3774                    OrderByComparator orderByComparator)
3775                    throws NoSuchPageException, SystemException {
3776                    WikiPage wikiPage = fetchByN_H_First(nodeId, head, orderByComparator);
3777    
3778                    if (wikiPage != null) {
3779                            return wikiPage;
3780                    }
3781    
3782                    StringBundler msg = new StringBundler(6);
3783    
3784                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3785    
3786                    msg.append("nodeId=");
3787                    msg.append(nodeId);
3788    
3789                    msg.append(", head=");
3790                    msg.append(head);
3791    
3792                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3793    
3794                    throw new NoSuchPageException(msg.toString());
3795            }
3796    
3797            /**
3798             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63;.
3799             *
3800             * @param nodeId the node ID
3801             * @param head the head
3802             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3803             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
3804             * @throws SystemException if a system exception occurred
3805             */
3806            @Override
3807            public WikiPage fetchByN_H_First(long nodeId, boolean head,
3808                    OrderByComparator orderByComparator) throws SystemException {
3809                    List<WikiPage> list = findByN_H(nodeId, head, 0, 1, orderByComparator);
3810    
3811                    if (!list.isEmpty()) {
3812                            return list.get(0);
3813                    }
3814    
3815                    return null;
3816            }
3817    
3818            /**
3819             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63;.
3820             *
3821             * @param nodeId the node ID
3822             * @param head the head
3823             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3824             * @return the last matching wiki page
3825             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3826             * @throws SystemException if a system exception occurred
3827             */
3828            @Override
3829            public WikiPage findByN_H_Last(long nodeId, boolean head,
3830                    OrderByComparator orderByComparator)
3831                    throws NoSuchPageException, SystemException {
3832                    WikiPage wikiPage = fetchByN_H_Last(nodeId, head, orderByComparator);
3833    
3834                    if (wikiPage != null) {
3835                            return wikiPage;
3836                    }
3837    
3838                    StringBundler msg = new StringBundler(6);
3839    
3840                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3841    
3842                    msg.append("nodeId=");
3843                    msg.append(nodeId);
3844    
3845                    msg.append(", head=");
3846                    msg.append(head);
3847    
3848                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3849    
3850                    throw new NoSuchPageException(msg.toString());
3851            }
3852    
3853            /**
3854             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63;.
3855             *
3856             * @param nodeId the node ID
3857             * @param head the head
3858             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3859             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
3860             * @throws SystemException if a system exception occurred
3861             */
3862            @Override
3863            public WikiPage fetchByN_H_Last(long nodeId, boolean head,
3864                    OrderByComparator orderByComparator) throws SystemException {
3865                    int count = countByN_H(nodeId, head);
3866    
3867                    if (count == 0) {
3868                            return null;
3869                    }
3870    
3871                    List<WikiPage> list = findByN_H(nodeId, head, count - 1, count,
3872                                    orderByComparator);
3873    
3874                    if (!list.isEmpty()) {
3875                            return list.get(0);
3876                    }
3877    
3878                    return null;
3879            }
3880    
3881            /**
3882             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63;.
3883             *
3884             * @param pageId the primary key of the current wiki page
3885             * @param nodeId the node ID
3886             * @param head the head
3887             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3888             * @return the previous, current, and next wiki page
3889             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
3890             * @throws SystemException if a system exception occurred
3891             */
3892            @Override
3893            public WikiPage[] findByN_H_PrevAndNext(long pageId, long nodeId,
3894                    boolean head, OrderByComparator orderByComparator)
3895                    throws NoSuchPageException, SystemException {
3896                    WikiPage wikiPage = findByPrimaryKey(pageId);
3897    
3898                    Session session = null;
3899    
3900                    try {
3901                            session = openSession();
3902    
3903                            WikiPage[] array = new WikiPageImpl[3];
3904    
3905                            array[0] = getByN_H_PrevAndNext(session, wikiPage, nodeId, head,
3906                                            orderByComparator, true);
3907    
3908                            array[1] = wikiPage;
3909    
3910                            array[2] = getByN_H_PrevAndNext(session, wikiPage, nodeId, head,
3911                                            orderByComparator, false);
3912    
3913                            return array;
3914                    }
3915                    catch (Exception e) {
3916                            throw processException(e);
3917                    }
3918                    finally {
3919                            closeSession(session);
3920                    }
3921            }
3922    
3923            protected WikiPage getByN_H_PrevAndNext(Session session, WikiPage wikiPage,
3924                    long nodeId, boolean head, OrderByComparator orderByComparator,
3925                    boolean previous) {
3926                    StringBundler query = null;
3927    
3928                    if (orderByComparator != null) {
3929                            query = new StringBundler(6 +
3930                                            (orderByComparator.getOrderByFields().length * 6));
3931                    }
3932                    else {
3933                            query = new StringBundler(3);
3934                    }
3935    
3936                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3937    
3938                    query.append(_FINDER_COLUMN_N_H_NODEID_2);
3939    
3940                    query.append(_FINDER_COLUMN_N_H_HEAD_2);
3941    
3942                    if (orderByComparator != null) {
3943                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3944    
3945                            if (orderByConditionFields.length > 0) {
3946                                    query.append(WHERE_AND);
3947                            }
3948    
3949                            for (int i = 0; i < orderByConditionFields.length; i++) {
3950                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3951                                    query.append(orderByConditionFields[i]);
3952    
3953                                    if ((i + 1) < orderByConditionFields.length) {
3954                                            if (orderByComparator.isAscending() ^ previous) {
3955                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3956                                            }
3957                                            else {
3958                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3959                                            }
3960                                    }
3961                                    else {
3962                                            if (orderByComparator.isAscending() ^ previous) {
3963                                                    query.append(WHERE_GREATER_THAN);
3964                                            }
3965                                            else {
3966                                                    query.append(WHERE_LESSER_THAN);
3967                                            }
3968                                    }
3969                            }
3970    
3971                            query.append(ORDER_BY_CLAUSE);
3972    
3973                            String[] orderByFields = orderByComparator.getOrderByFields();
3974    
3975                            for (int i = 0; i < orderByFields.length; i++) {
3976                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3977                                    query.append(orderByFields[i]);
3978    
3979                                    if ((i + 1) < orderByFields.length) {
3980                                            if (orderByComparator.isAscending() ^ previous) {
3981                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3982                                            }
3983                                            else {
3984                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3985                                            }
3986                                    }
3987                                    else {
3988                                            if (orderByComparator.isAscending() ^ previous) {
3989                                                    query.append(ORDER_BY_ASC);
3990                                            }
3991                                            else {
3992                                                    query.append(ORDER_BY_DESC);
3993                                            }
3994                                    }
3995                            }
3996                    }
3997                    else {
3998                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3999                    }
4000    
4001                    String sql = query.toString();
4002    
4003                    Query q = session.createQuery(sql);
4004    
4005                    q.setFirstResult(0);
4006                    q.setMaxResults(2);
4007    
4008                    QueryPos qPos = QueryPos.getInstance(q);
4009    
4010                    qPos.add(nodeId);
4011    
4012                    qPos.add(head);
4013    
4014                    if (orderByComparator != null) {
4015                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
4016    
4017                            for (Object value : values) {
4018                                    qPos.add(value);
4019                            }
4020                    }
4021    
4022                    List<WikiPage> list = q.list();
4023    
4024                    if (list.size() == 2) {
4025                            return list.get(1);
4026                    }
4027                    else {
4028                            return null;
4029                    }
4030            }
4031    
4032            /**
4033             * Removes all the wiki pages where nodeId = &#63; and head = &#63; from the database.
4034             *
4035             * @param nodeId the node ID
4036             * @param head the head
4037             * @throws SystemException if a system exception occurred
4038             */
4039            @Override
4040            public void removeByN_H(long nodeId, boolean head)
4041                    throws SystemException {
4042                    for (WikiPage wikiPage : findByN_H(nodeId, head, QueryUtil.ALL_POS,
4043                                    QueryUtil.ALL_POS, null)) {
4044                            remove(wikiPage);
4045                    }
4046            }
4047    
4048            /**
4049             * Returns the number of wiki pages where nodeId = &#63; and head = &#63;.
4050             *
4051             * @param nodeId the node ID
4052             * @param head the head
4053             * @return the number of matching wiki pages
4054             * @throws SystemException if a system exception occurred
4055             */
4056            @Override
4057            public int countByN_H(long nodeId, boolean head) throws SystemException {
4058                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H;
4059    
4060                    Object[] finderArgs = new Object[] { nodeId, head };
4061    
4062                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4063                                    this);
4064    
4065                    if (count == null) {
4066                            StringBundler query = new StringBundler(3);
4067    
4068                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
4069    
4070                            query.append(_FINDER_COLUMN_N_H_NODEID_2);
4071    
4072                            query.append(_FINDER_COLUMN_N_H_HEAD_2);
4073    
4074                            String sql = query.toString();
4075    
4076                            Session session = null;
4077    
4078                            try {
4079                                    session = openSession();
4080    
4081                                    Query q = session.createQuery(sql);
4082    
4083                                    QueryPos qPos = QueryPos.getInstance(q);
4084    
4085                                    qPos.add(nodeId);
4086    
4087                                    qPos.add(head);
4088    
4089                                    count = (Long)q.uniqueResult();
4090    
4091                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4092                            }
4093                            catch (Exception e) {
4094                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4095    
4096                                    throw processException(e);
4097                            }
4098                            finally {
4099                                    closeSession(session);
4100                            }
4101                    }
4102    
4103                    return count.intValue();
4104            }
4105    
4106            private static final String _FINDER_COLUMN_N_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
4107            private static final String _FINDER_COLUMN_N_H_HEAD_2 = "wikiPage.head = ?";
4108            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4109                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
4110                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_P",
4111                            new String[] {
4112                                    Long.class.getName(), String.class.getName(),
4113                                    
4114                            Integer.class.getName(), Integer.class.getName(),
4115                                    OrderByComparator.class.getName()
4116                            });
4117            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4118                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
4119                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_P",
4120                            new String[] { Long.class.getName(), String.class.getName() },
4121                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
4122                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
4123                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
4124                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
4125            public static final FinderPath FINDER_PATH_COUNT_BY_N_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4126                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4127                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_P",
4128                            new String[] { Long.class.getName(), String.class.getName() });
4129    
4130            /**
4131             * Returns all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
4132             *
4133             * @param nodeId the node ID
4134             * @param parentTitle the parent title
4135             * @return the matching wiki pages
4136             * @throws SystemException if a system exception occurred
4137             */
4138            @Override
4139            public List<WikiPage> findByN_P(long nodeId, String parentTitle)
4140                    throws SystemException {
4141                    return findByN_P(nodeId, parentTitle, QueryUtil.ALL_POS,
4142                            QueryUtil.ALL_POS, null);
4143            }
4144    
4145            /**
4146             * Returns a range of all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
4147             *
4148             * <p>
4149             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4150             * </p>
4151             *
4152             * @param nodeId the node ID
4153             * @param parentTitle the parent title
4154             * @param start the lower bound of the range of wiki pages
4155             * @param end the upper bound of the range of wiki pages (not inclusive)
4156             * @return the range of matching wiki pages
4157             * @throws SystemException if a system exception occurred
4158             */
4159            @Override
4160            public List<WikiPage> findByN_P(long nodeId, String parentTitle, int start,
4161                    int end) throws SystemException {
4162                    return findByN_P(nodeId, parentTitle, start, end, null);
4163            }
4164    
4165            /**
4166             * Returns an ordered range of all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
4167             *
4168             * <p>
4169             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4170             * </p>
4171             *
4172             * @param nodeId the node ID
4173             * @param parentTitle the parent title
4174             * @param start the lower bound of the range of wiki pages
4175             * @param end the upper bound of the range of wiki pages (not inclusive)
4176             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4177             * @return the ordered range of matching wiki pages
4178             * @throws SystemException if a system exception occurred
4179             */
4180            @Override
4181            public List<WikiPage> findByN_P(long nodeId, String parentTitle, int start,
4182                    int end, OrderByComparator orderByComparator) throws SystemException {
4183                    boolean pagination = true;
4184                    FinderPath finderPath = null;
4185                    Object[] finderArgs = null;
4186    
4187                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4188                                    (orderByComparator == null)) {
4189                            pagination = false;
4190                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P;
4191                            finderArgs = new Object[] { nodeId, parentTitle };
4192                    }
4193                    else {
4194                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_P;
4195                            finderArgs = new Object[] {
4196                                            nodeId, parentTitle,
4197                                            
4198                                            start, end, orderByComparator
4199                                    };
4200                    }
4201    
4202                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
4203                                    finderArgs, this);
4204    
4205                    if ((list != null) && !list.isEmpty()) {
4206                            for (WikiPage wikiPage : list) {
4207                                    if ((nodeId != wikiPage.getNodeId()) ||
4208                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle())) {
4209                                            list = null;
4210    
4211                                            break;
4212                                    }
4213                            }
4214                    }
4215    
4216                    if (list == null) {
4217                            StringBundler query = null;
4218    
4219                            if (orderByComparator != null) {
4220                                    query = new StringBundler(4 +
4221                                                    (orderByComparator.getOrderByFields().length * 3));
4222                            }
4223                            else {
4224                                    query = new StringBundler(4);
4225                            }
4226    
4227                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4228    
4229                            query.append(_FINDER_COLUMN_N_P_NODEID_2);
4230    
4231                            boolean bindParentTitle = false;
4232    
4233                            if (parentTitle == null) {
4234                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_1);
4235                            }
4236                            else if (parentTitle.equals(StringPool.BLANK)) {
4237                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_3);
4238                            }
4239                            else {
4240                                    bindParentTitle = true;
4241    
4242                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_2);
4243                            }
4244    
4245                            if (orderByComparator != null) {
4246                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4247                                            orderByComparator);
4248                            }
4249                            else
4250                             if (pagination) {
4251                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4252                            }
4253    
4254                            String sql = query.toString();
4255    
4256                            Session session = null;
4257    
4258                            try {
4259                                    session = openSession();
4260    
4261                                    Query q = session.createQuery(sql);
4262    
4263                                    QueryPos qPos = QueryPos.getInstance(q);
4264    
4265                                    qPos.add(nodeId);
4266    
4267                                    if (bindParentTitle) {
4268                                            qPos.add(parentTitle.toLowerCase());
4269                                    }
4270    
4271                                    if (!pagination) {
4272                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4273                                                            start, end, false);
4274    
4275                                            Collections.sort(list);
4276    
4277                                            list = new UnmodifiableList<WikiPage>(list);
4278                                    }
4279                                    else {
4280                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4281                                                            start, end);
4282                                    }
4283    
4284                                    cacheResult(list);
4285    
4286                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4287                            }
4288                            catch (Exception e) {
4289                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4290    
4291                                    throw processException(e);
4292                            }
4293                            finally {
4294                                    closeSession(session);
4295                            }
4296                    }
4297    
4298                    return list;
4299            }
4300    
4301            /**
4302             * Returns the first wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
4303             *
4304             * @param nodeId the node ID
4305             * @param parentTitle the parent title
4306             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4307             * @return the first matching wiki page
4308             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4309             * @throws SystemException if a system exception occurred
4310             */
4311            @Override
4312            public WikiPage findByN_P_First(long nodeId, String parentTitle,
4313                    OrderByComparator orderByComparator)
4314                    throws NoSuchPageException, SystemException {
4315                    WikiPage wikiPage = fetchByN_P_First(nodeId, parentTitle,
4316                                    orderByComparator);
4317    
4318                    if (wikiPage != null) {
4319                            return wikiPage;
4320                    }
4321    
4322                    StringBundler msg = new StringBundler(6);
4323    
4324                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4325    
4326                    msg.append("nodeId=");
4327                    msg.append(nodeId);
4328    
4329                    msg.append(", parentTitle=");
4330                    msg.append(parentTitle);
4331    
4332                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4333    
4334                    throw new NoSuchPageException(msg.toString());
4335            }
4336    
4337            /**
4338             * Returns the first wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
4339             *
4340             * @param nodeId the node ID
4341             * @param parentTitle the parent title
4342             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4343             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
4344             * @throws SystemException if a system exception occurred
4345             */
4346            @Override
4347            public WikiPage fetchByN_P_First(long nodeId, String parentTitle,
4348                    OrderByComparator orderByComparator) throws SystemException {
4349                    List<WikiPage> list = findByN_P(nodeId, parentTitle, 0, 1,
4350                                    orderByComparator);
4351    
4352                    if (!list.isEmpty()) {
4353                            return list.get(0);
4354                    }
4355    
4356                    return null;
4357            }
4358    
4359            /**
4360             * Returns the last wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
4361             *
4362             * @param nodeId the node ID
4363             * @param parentTitle the parent title
4364             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4365             * @return the last matching wiki page
4366             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4367             * @throws SystemException if a system exception occurred
4368             */
4369            @Override
4370            public WikiPage findByN_P_Last(long nodeId, String parentTitle,
4371                    OrderByComparator orderByComparator)
4372                    throws NoSuchPageException, SystemException {
4373                    WikiPage wikiPage = fetchByN_P_Last(nodeId, parentTitle,
4374                                    orderByComparator);
4375    
4376                    if (wikiPage != null) {
4377                            return wikiPage;
4378                    }
4379    
4380                    StringBundler msg = new StringBundler(6);
4381    
4382                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4383    
4384                    msg.append("nodeId=");
4385                    msg.append(nodeId);
4386    
4387                    msg.append(", parentTitle=");
4388                    msg.append(parentTitle);
4389    
4390                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4391    
4392                    throw new NoSuchPageException(msg.toString());
4393            }
4394    
4395            /**
4396             * Returns the last wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
4397             *
4398             * @param nodeId the node ID
4399             * @param parentTitle the parent title
4400             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4401             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
4402             * @throws SystemException if a system exception occurred
4403             */
4404            @Override
4405            public WikiPage fetchByN_P_Last(long nodeId, String parentTitle,
4406                    OrderByComparator orderByComparator) throws SystemException {
4407                    int count = countByN_P(nodeId, parentTitle);
4408    
4409                    if (count == 0) {
4410                            return null;
4411                    }
4412    
4413                    List<WikiPage> list = findByN_P(nodeId, parentTitle, count - 1, count,
4414                                    orderByComparator);
4415    
4416                    if (!list.isEmpty()) {
4417                            return list.get(0);
4418                    }
4419    
4420                    return null;
4421            }
4422    
4423            /**
4424             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
4425             *
4426             * @param pageId the primary key of the current wiki page
4427             * @param nodeId the node ID
4428             * @param parentTitle the parent title
4429             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4430             * @return the previous, current, and next wiki page
4431             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
4432             * @throws SystemException if a system exception occurred
4433             */
4434            @Override
4435            public WikiPage[] findByN_P_PrevAndNext(long pageId, long nodeId,
4436                    String parentTitle, OrderByComparator orderByComparator)
4437                    throws NoSuchPageException, SystemException {
4438                    WikiPage wikiPage = findByPrimaryKey(pageId);
4439    
4440                    Session session = null;
4441    
4442                    try {
4443                            session = openSession();
4444    
4445                            WikiPage[] array = new WikiPageImpl[3];
4446    
4447                            array[0] = getByN_P_PrevAndNext(session, wikiPage, nodeId,
4448                                            parentTitle, orderByComparator, true);
4449    
4450                            array[1] = wikiPage;
4451    
4452                            array[2] = getByN_P_PrevAndNext(session, wikiPage, nodeId,
4453                                            parentTitle, orderByComparator, false);
4454    
4455                            return array;
4456                    }
4457                    catch (Exception e) {
4458                            throw processException(e);
4459                    }
4460                    finally {
4461                            closeSession(session);
4462                    }
4463            }
4464    
4465            protected WikiPage getByN_P_PrevAndNext(Session session, WikiPage wikiPage,
4466                    long nodeId, String parentTitle, OrderByComparator orderByComparator,
4467                    boolean previous) {
4468                    StringBundler query = null;
4469    
4470                    if (orderByComparator != null) {
4471                            query = new StringBundler(6 +
4472                                            (orderByComparator.getOrderByFields().length * 6));
4473                    }
4474                    else {
4475                            query = new StringBundler(3);
4476                    }
4477    
4478                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4479    
4480                    query.append(_FINDER_COLUMN_N_P_NODEID_2);
4481    
4482                    boolean bindParentTitle = false;
4483    
4484                    if (parentTitle == null) {
4485                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_1);
4486                    }
4487                    else if (parentTitle.equals(StringPool.BLANK)) {
4488                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_3);
4489                    }
4490                    else {
4491                            bindParentTitle = true;
4492    
4493                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_2);
4494                    }
4495    
4496                    if (orderByComparator != null) {
4497                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4498    
4499                            if (orderByConditionFields.length > 0) {
4500                                    query.append(WHERE_AND);
4501                            }
4502    
4503                            for (int i = 0; i < orderByConditionFields.length; i++) {
4504                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4505                                    query.append(orderByConditionFields[i]);
4506    
4507                                    if ((i + 1) < orderByConditionFields.length) {
4508                                            if (orderByComparator.isAscending() ^ previous) {
4509                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4510                                            }
4511                                            else {
4512                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4513                                            }
4514                                    }
4515                                    else {
4516                                            if (orderByComparator.isAscending() ^ previous) {
4517                                                    query.append(WHERE_GREATER_THAN);
4518                                            }
4519                                            else {
4520                                                    query.append(WHERE_LESSER_THAN);
4521                                            }
4522                                    }
4523                            }
4524    
4525                            query.append(ORDER_BY_CLAUSE);
4526    
4527                            String[] orderByFields = orderByComparator.getOrderByFields();
4528    
4529                            for (int i = 0; i < orderByFields.length; i++) {
4530                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4531                                    query.append(orderByFields[i]);
4532    
4533                                    if ((i + 1) < orderByFields.length) {
4534                                            if (orderByComparator.isAscending() ^ previous) {
4535                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4536                                            }
4537                                            else {
4538                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4539                                            }
4540                                    }
4541                                    else {
4542                                            if (orderByComparator.isAscending() ^ previous) {
4543                                                    query.append(ORDER_BY_ASC);
4544                                            }
4545                                            else {
4546                                                    query.append(ORDER_BY_DESC);
4547                                            }
4548                                    }
4549                            }
4550                    }
4551                    else {
4552                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4553                    }
4554    
4555                    String sql = query.toString();
4556    
4557                    Query q = session.createQuery(sql);
4558    
4559                    q.setFirstResult(0);
4560                    q.setMaxResults(2);
4561    
4562                    QueryPos qPos = QueryPos.getInstance(q);
4563    
4564                    qPos.add(nodeId);
4565    
4566                    if (bindParentTitle) {
4567                            qPos.add(parentTitle.toLowerCase());
4568                    }
4569    
4570                    if (orderByComparator != null) {
4571                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
4572    
4573                            for (Object value : values) {
4574                                    qPos.add(value);
4575                            }
4576                    }
4577    
4578                    List<WikiPage> list = q.list();
4579    
4580                    if (list.size() == 2) {
4581                            return list.get(1);
4582                    }
4583                    else {
4584                            return null;
4585                    }
4586            }
4587    
4588            /**
4589             * Removes all the wiki pages where nodeId = &#63; and parentTitle = &#63; from the database.
4590             *
4591             * @param nodeId the node ID
4592             * @param parentTitle the parent title
4593             * @throws SystemException if a system exception occurred
4594             */
4595            @Override
4596            public void removeByN_P(long nodeId, String parentTitle)
4597                    throws SystemException {
4598                    for (WikiPage wikiPage : findByN_P(nodeId, parentTitle,
4599                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4600                            remove(wikiPage);
4601                    }
4602            }
4603    
4604            /**
4605             * Returns the number of wiki pages where nodeId = &#63; and parentTitle = &#63;.
4606             *
4607             * @param nodeId the node ID
4608             * @param parentTitle the parent title
4609             * @return the number of matching wiki pages
4610             * @throws SystemException if a system exception occurred
4611             */
4612            @Override
4613            public int countByN_P(long nodeId, String parentTitle)
4614                    throws SystemException {
4615                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_P;
4616    
4617                    Object[] finderArgs = new Object[] { nodeId, parentTitle };
4618    
4619                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4620                                    this);
4621    
4622                    if (count == null) {
4623                            StringBundler query = new StringBundler(3);
4624    
4625                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
4626    
4627                            query.append(_FINDER_COLUMN_N_P_NODEID_2);
4628    
4629                            boolean bindParentTitle = false;
4630    
4631                            if (parentTitle == null) {
4632                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_1);
4633                            }
4634                            else if (parentTitle.equals(StringPool.BLANK)) {
4635                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_3);
4636                            }
4637                            else {
4638                                    bindParentTitle = true;
4639    
4640                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_2);
4641                            }
4642    
4643                            String sql = query.toString();
4644    
4645                            Session session = null;
4646    
4647                            try {
4648                                    session = openSession();
4649    
4650                                    Query q = session.createQuery(sql);
4651    
4652                                    QueryPos qPos = QueryPos.getInstance(q);
4653    
4654                                    qPos.add(nodeId);
4655    
4656                                    if (bindParentTitle) {
4657                                            qPos.add(parentTitle.toLowerCase());
4658                                    }
4659    
4660                                    count = (Long)q.uniqueResult();
4661    
4662                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4663                            }
4664                            catch (Exception e) {
4665                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4666    
4667                                    throw processException(e);
4668                            }
4669                            finally {
4670                                    closeSession(session);
4671                            }
4672                    }
4673    
4674                    return count.intValue();
4675            }
4676    
4677            private static final String _FINDER_COLUMN_N_P_NODEID_2 = "wikiPage.nodeId = ? AND ";
4678            private static final String _FINDER_COLUMN_N_P_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL";
4679            private static final String _FINDER_COLUMN_N_P_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ?";
4680            private static final String _FINDER_COLUMN_N_P_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '')";
4681            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4682                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
4683                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_R",
4684                            new String[] {
4685                                    Long.class.getName(), String.class.getName(),
4686                                    
4687                            Integer.class.getName(), Integer.class.getName(),
4688                                    OrderByComparator.class.getName()
4689                            });
4690            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4691                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
4692                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_R",
4693                            new String[] { Long.class.getName(), String.class.getName() },
4694                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
4695                            WikiPageModelImpl.REDIRECTTITLE_COLUMN_BITMASK |
4696                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
4697                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
4698            public static final FinderPath FINDER_PATH_COUNT_BY_N_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4699                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4700                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_R",
4701                            new String[] { Long.class.getName(), String.class.getName() });
4702    
4703            /**
4704             * Returns all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
4705             *
4706             * @param nodeId the node ID
4707             * @param redirectTitle the redirect title
4708             * @return the matching wiki pages
4709             * @throws SystemException if a system exception occurred
4710             */
4711            @Override
4712            public List<WikiPage> findByN_R(long nodeId, String redirectTitle)
4713                    throws SystemException {
4714                    return findByN_R(nodeId, redirectTitle, QueryUtil.ALL_POS,
4715                            QueryUtil.ALL_POS, null);
4716            }
4717    
4718            /**
4719             * Returns a range of all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
4720             *
4721             * <p>
4722             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4723             * </p>
4724             *
4725             * @param nodeId the node ID
4726             * @param redirectTitle the redirect title
4727             * @param start the lower bound of the range of wiki pages
4728             * @param end the upper bound of the range of wiki pages (not inclusive)
4729             * @return the range of matching wiki pages
4730             * @throws SystemException if a system exception occurred
4731             */
4732            @Override
4733            public List<WikiPage> findByN_R(long nodeId, String redirectTitle,
4734                    int start, int end) throws SystemException {
4735                    return findByN_R(nodeId, redirectTitle, start, end, null);
4736            }
4737    
4738            /**
4739             * Returns an ordered range of all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
4740             *
4741             * <p>
4742             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4743             * </p>
4744             *
4745             * @param nodeId the node ID
4746             * @param redirectTitle the redirect title
4747             * @param start the lower bound of the range of wiki pages
4748             * @param end the upper bound of the range of wiki pages (not inclusive)
4749             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4750             * @return the ordered range of matching wiki pages
4751             * @throws SystemException if a system exception occurred
4752             */
4753            @Override
4754            public List<WikiPage> findByN_R(long nodeId, String redirectTitle,
4755                    int start, int end, OrderByComparator orderByComparator)
4756                    throws SystemException {
4757                    boolean pagination = true;
4758                    FinderPath finderPath = null;
4759                    Object[] finderArgs = null;
4760    
4761                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4762                                    (orderByComparator == null)) {
4763                            pagination = false;
4764                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R;
4765                            finderArgs = new Object[] { nodeId, redirectTitle };
4766                    }
4767                    else {
4768                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_R;
4769                            finderArgs = new Object[] {
4770                                            nodeId, redirectTitle,
4771                                            
4772                                            start, end, orderByComparator
4773                                    };
4774                    }
4775    
4776                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
4777                                    finderArgs, this);
4778    
4779                    if ((list != null) && !list.isEmpty()) {
4780                            for (WikiPage wikiPage : list) {
4781                                    if ((nodeId != wikiPage.getNodeId()) ||
4782                                                    !Validator.equals(redirectTitle,
4783                                                            wikiPage.getRedirectTitle())) {
4784                                            list = null;
4785    
4786                                            break;
4787                                    }
4788                            }
4789                    }
4790    
4791                    if (list == null) {
4792                            StringBundler query = null;
4793    
4794                            if (orderByComparator != null) {
4795                                    query = new StringBundler(4 +
4796                                                    (orderByComparator.getOrderByFields().length * 3));
4797                            }
4798                            else {
4799                                    query = new StringBundler(4);
4800                            }
4801    
4802                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4803    
4804                            query.append(_FINDER_COLUMN_N_R_NODEID_2);
4805    
4806                            boolean bindRedirectTitle = false;
4807    
4808                            if (redirectTitle == null) {
4809                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_1);
4810                            }
4811                            else if (redirectTitle.equals(StringPool.BLANK)) {
4812                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_3);
4813                            }
4814                            else {
4815                                    bindRedirectTitle = true;
4816    
4817                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_2);
4818                            }
4819    
4820                            if (orderByComparator != null) {
4821                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4822                                            orderByComparator);
4823                            }
4824                            else
4825                             if (pagination) {
4826                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4827                            }
4828    
4829                            String sql = query.toString();
4830    
4831                            Session session = null;
4832    
4833                            try {
4834                                    session = openSession();
4835    
4836                                    Query q = session.createQuery(sql);
4837    
4838                                    QueryPos qPos = QueryPos.getInstance(q);
4839    
4840                                    qPos.add(nodeId);
4841    
4842                                    if (bindRedirectTitle) {
4843                                            qPos.add(redirectTitle.toLowerCase());
4844                                    }
4845    
4846                                    if (!pagination) {
4847                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4848                                                            start, end, false);
4849    
4850                                            Collections.sort(list);
4851    
4852                                            list = new UnmodifiableList<WikiPage>(list);
4853                                    }
4854                                    else {
4855                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4856                                                            start, end);
4857                                    }
4858    
4859                                    cacheResult(list);
4860    
4861                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4862                            }
4863                            catch (Exception e) {
4864                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4865    
4866                                    throw processException(e);
4867                            }
4868                            finally {
4869                                    closeSession(session);
4870                            }
4871                    }
4872    
4873                    return list;
4874            }
4875    
4876            /**
4877             * Returns the first wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
4878             *
4879             * @param nodeId the node ID
4880             * @param redirectTitle the redirect title
4881             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4882             * @return the first matching wiki page
4883             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4884             * @throws SystemException if a system exception occurred
4885             */
4886            @Override
4887            public WikiPage findByN_R_First(long nodeId, String redirectTitle,
4888                    OrderByComparator orderByComparator)
4889                    throws NoSuchPageException, SystemException {
4890                    WikiPage wikiPage = fetchByN_R_First(nodeId, redirectTitle,
4891                                    orderByComparator);
4892    
4893                    if (wikiPage != null) {
4894                            return wikiPage;
4895                    }
4896    
4897                    StringBundler msg = new StringBundler(6);
4898    
4899                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4900    
4901                    msg.append("nodeId=");
4902                    msg.append(nodeId);
4903    
4904                    msg.append(", redirectTitle=");
4905                    msg.append(redirectTitle);
4906    
4907                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4908    
4909                    throw new NoSuchPageException(msg.toString());
4910            }
4911    
4912            /**
4913             * Returns the first wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
4914             *
4915             * @param nodeId the node ID
4916             * @param redirectTitle the redirect title
4917             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4918             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
4919             * @throws SystemException if a system exception occurred
4920             */
4921            @Override
4922            public WikiPage fetchByN_R_First(long nodeId, String redirectTitle,
4923                    OrderByComparator orderByComparator) throws SystemException {
4924                    List<WikiPage> list = findByN_R(nodeId, redirectTitle, 0, 1,
4925                                    orderByComparator);
4926    
4927                    if (!list.isEmpty()) {
4928                            return list.get(0);
4929                    }
4930    
4931                    return null;
4932            }
4933    
4934            /**
4935             * Returns the last wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
4936             *
4937             * @param nodeId the node ID
4938             * @param redirectTitle the redirect title
4939             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4940             * @return the last matching wiki page
4941             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4942             * @throws SystemException if a system exception occurred
4943             */
4944            @Override
4945            public WikiPage findByN_R_Last(long nodeId, String redirectTitle,
4946                    OrderByComparator orderByComparator)
4947                    throws NoSuchPageException, SystemException {
4948                    WikiPage wikiPage = fetchByN_R_Last(nodeId, redirectTitle,
4949                                    orderByComparator);
4950    
4951                    if (wikiPage != null) {
4952                            return wikiPage;
4953                    }
4954    
4955                    StringBundler msg = new StringBundler(6);
4956    
4957                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4958    
4959                    msg.append("nodeId=");
4960                    msg.append(nodeId);
4961    
4962                    msg.append(", redirectTitle=");
4963                    msg.append(redirectTitle);
4964    
4965                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4966    
4967                    throw new NoSuchPageException(msg.toString());
4968            }
4969    
4970            /**
4971             * Returns the last wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
4972             *
4973             * @param nodeId the node ID
4974             * @param redirectTitle the redirect title
4975             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4976             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
4977             * @throws SystemException if a system exception occurred
4978             */
4979            @Override
4980            public WikiPage fetchByN_R_Last(long nodeId, String redirectTitle,
4981                    OrderByComparator orderByComparator) throws SystemException {
4982                    int count = countByN_R(nodeId, redirectTitle);
4983    
4984                    if (count == 0) {
4985                            return null;
4986                    }
4987    
4988                    List<WikiPage> list = findByN_R(nodeId, redirectTitle, count - 1,
4989                                    count, orderByComparator);
4990    
4991                    if (!list.isEmpty()) {
4992                            return list.get(0);
4993                    }
4994    
4995                    return null;
4996            }
4997    
4998            /**
4999             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
5000             *
5001             * @param pageId the primary key of the current wiki page
5002             * @param nodeId the node ID
5003             * @param redirectTitle the redirect title
5004             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5005             * @return the previous, current, and next wiki page
5006             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
5007             * @throws SystemException if a system exception occurred
5008             */
5009            @Override
5010            public WikiPage[] findByN_R_PrevAndNext(long pageId, long nodeId,
5011                    String redirectTitle, OrderByComparator orderByComparator)
5012                    throws NoSuchPageException, SystemException {
5013                    WikiPage wikiPage = findByPrimaryKey(pageId);
5014    
5015                    Session session = null;
5016    
5017                    try {
5018                            session = openSession();
5019    
5020                            WikiPage[] array = new WikiPageImpl[3];
5021    
5022                            array[0] = getByN_R_PrevAndNext(session, wikiPage, nodeId,
5023                                            redirectTitle, orderByComparator, true);
5024    
5025                            array[1] = wikiPage;
5026    
5027                            array[2] = getByN_R_PrevAndNext(session, wikiPage, nodeId,
5028                                            redirectTitle, orderByComparator, false);
5029    
5030                            return array;
5031                    }
5032                    catch (Exception e) {
5033                            throw processException(e);
5034                    }
5035                    finally {
5036                            closeSession(session);
5037                    }
5038            }
5039    
5040            protected WikiPage getByN_R_PrevAndNext(Session session, WikiPage wikiPage,
5041                    long nodeId, String redirectTitle, OrderByComparator orderByComparator,
5042                    boolean previous) {
5043                    StringBundler query = null;
5044    
5045                    if (orderByComparator != null) {
5046                            query = new StringBundler(6 +
5047                                            (orderByComparator.getOrderByFields().length * 6));
5048                    }
5049                    else {
5050                            query = new StringBundler(3);
5051                    }
5052    
5053                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5054    
5055                    query.append(_FINDER_COLUMN_N_R_NODEID_2);
5056    
5057                    boolean bindRedirectTitle = false;
5058    
5059                    if (redirectTitle == null) {
5060                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_1);
5061                    }
5062                    else if (redirectTitle.equals(StringPool.BLANK)) {
5063                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_3);
5064                    }
5065                    else {
5066                            bindRedirectTitle = true;
5067    
5068                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_2);
5069                    }
5070    
5071                    if (orderByComparator != null) {
5072                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5073    
5074                            if (orderByConditionFields.length > 0) {
5075                                    query.append(WHERE_AND);
5076                            }
5077    
5078                            for (int i = 0; i < orderByConditionFields.length; i++) {
5079                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5080                                    query.append(orderByConditionFields[i]);
5081    
5082                                    if ((i + 1) < orderByConditionFields.length) {
5083                                            if (orderByComparator.isAscending() ^ previous) {
5084                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5085                                            }
5086                                            else {
5087                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5088                                            }
5089                                    }
5090                                    else {
5091                                            if (orderByComparator.isAscending() ^ previous) {
5092                                                    query.append(WHERE_GREATER_THAN);
5093                                            }
5094                                            else {
5095                                                    query.append(WHERE_LESSER_THAN);
5096                                            }
5097                                    }
5098                            }
5099    
5100                            query.append(ORDER_BY_CLAUSE);
5101    
5102                            String[] orderByFields = orderByComparator.getOrderByFields();
5103    
5104                            for (int i = 0; i < orderByFields.length; i++) {
5105                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5106                                    query.append(orderByFields[i]);
5107    
5108                                    if ((i + 1) < orderByFields.length) {
5109                                            if (orderByComparator.isAscending() ^ previous) {
5110                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5111                                            }
5112                                            else {
5113                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5114                                            }
5115                                    }
5116                                    else {
5117                                            if (orderByComparator.isAscending() ^ previous) {
5118                                                    query.append(ORDER_BY_ASC);
5119                                            }
5120                                            else {
5121                                                    query.append(ORDER_BY_DESC);
5122                                            }
5123                                    }
5124                            }
5125                    }
5126                    else {
5127                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5128                    }
5129    
5130                    String sql = query.toString();
5131    
5132                    Query q = session.createQuery(sql);
5133    
5134                    q.setFirstResult(0);
5135                    q.setMaxResults(2);
5136    
5137                    QueryPos qPos = QueryPos.getInstance(q);
5138    
5139                    qPos.add(nodeId);
5140    
5141                    if (bindRedirectTitle) {
5142                            qPos.add(redirectTitle.toLowerCase());
5143                    }
5144    
5145                    if (orderByComparator != null) {
5146                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
5147    
5148                            for (Object value : values) {
5149                                    qPos.add(value);
5150                            }
5151                    }
5152    
5153                    List<WikiPage> list = q.list();
5154    
5155                    if (list.size() == 2) {
5156                            return list.get(1);
5157                    }
5158                    else {
5159                            return null;
5160                    }
5161            }
5162    
5163            /**
5164             * Removes all the wiki pages where nodeId = &#63; and redirectTitle = &#63; from the database.
5165             *
5166             * @param nodeId the node ID
5167             * @param redirectTitle the redirect title
5168             * @throws SystemException if a system exception occurred
5169             */
5170            @Override
5171            public void removeByN_R(long nodeId, String redirectTitle)
5172                    throws SystemException {
5173                    for (WikiPage wikiPage : findByN_R(nodeId, redirectTitle,
5174                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5175                            remove(wikiPage);
5176                    }
5177            }
5178    
5179            /**
5180             * Returns the number of wiki pages where nodeId = &#63; and redirectTitle = &#63;.
5181             *
5182             * @param nodeId the node ID
5183             * @param redirectTitle the redirect title
5184             * @return the number of matching wiki pages
5185             * @throws SystemException if a system exception occurred
5186             */
5187            @Override
5188            public int countByN_R(long nodeId, String redirectTitle)
5189                    throws SystemException {
5190                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_R;
5191    
5192                    Object[] finderArgs = new Object[] { nodeId, redirectTitle };
5193    
5194                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5195                                    this);
5196    
5197                    if (count == null) {
5198                            StringBundler query = new StringBundler(3);
5199    
5200                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
5201    
5202                            query.append(_FINDER_COLUMN_N_R_NODEID_2);
5203    
5204                            boolean bindRedirectTitle = false;
5205    
5206                            if (redirectTitle == null) {
5207                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_1);
5208                            }
5209                            else if (redirectTitle.equals(StringPool.BLANK)) {
5210                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_3);
5211                            }
5212                            else {
5213                                    bindRedirectTitle = true;
5214    
5215                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_2);
5216                            }
5217    
5218                            String sql = query.toString();
5219    
5220                            Session session = null;
5221    
5222                            try {
5223                                    session = openSession();
5224    
5225                                    Query q = session.createQuery(sql);
5226    
5227                                    QueryPos qPos = QueryPos.getInstance(q);
5228    
5229                                    qPos.add(nodeId);
5230    
5231                                    if (bindRedirectTitle) {
5232                                            qPos.add(redirectTitle.toLowerCase());
5233                                    }
5234    
5235                                    count = (Long)q.uniqueResult();
5236    
5237                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5238                            }
5239                            catch (Exception e) {
5240                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5241    
5242                                    throw processException(e);
5243                            }
5244                            finally {
5245                                    closeSession(session);
5246                            }
5247                    }
5248    
5249                    return count.intValue();
5250            }
5251    
5252            private static final String _FINDER_COLUMN_N_R_NODEID_2 = "wikiPage.nodeId = ? AND ";
5253            private static final String _FINDER_COLUMN_N_R_REDIRECTTITLE_1 = "wikiPage.redirectTitle IS NULL";
5254            private static final String _FINDER_COLUMN_N_R_REDIRECTTITLE_2 = "lower(wikiPage.redirectTitle) = ?";
5255            private static final String _FINDER_COLUMN_N_R_REDIRECTTITLE_3 = "(wikiPage.redirectTitle IS NULL OR wikiPage.redirectTitle = '')";
5256            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5257                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5258                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_S",
5259                            new String[] {
5260                                    Long.class.getName(), Integer.class.getName(),
5261                                    
5262                            Integer.class.getName(), Integer.class.getName(),
5263                                    OrderByComparator.class.getName()
5264                            });
5265            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5266                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5267                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_S",
5268                            new String[] { Long.class.getName(), Integer.class.getName() },
5269                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
5270                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
5271                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
5272                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
5273            public static final FinderPath FINDER_PATH_COUNT_BY_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5274                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5275                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_S",
5276                            new String[] { Long.class.getName(), Integer.class.getName() });
5277    
5278            /**
5279             * Returns all the wiki pages where nodeId = &#63; and status = &#63;.
5280             *
5281             * @param nodeId the node ID
5282             * @param status the status
5283             * @return the matching wiki pages
5284             * @throws SystemException if a system exception occurred
5285             */
5286            @Override
5287            public List<WikiPage> findByN_S(long nodeId, int status)
5288                    throws SystemException {
5289                    return findByN_S(nodeId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5290                            null);
5291            }
5292    
5293            /**
5294             * Returns a range of all the wiki pages where nodeId = &#63; and status = &#63;.
5295             *
5296             * <p>
5297             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5298             * </p>
5299             *
5300             * @param nodeId the node ID
5301             * @param status the status
5302             * @param start the lower bound of the range of wiki pages
5303             * @param end the upper bound of the range of wiki pages (not inclusive)
5304             * @return the range of matching wiki pages
5305             * @throws SystemException if a system exception occurred
5306             */
5307            @Override
5308            public List<WikiPage> findByN_S(long nodeId, int status, int start, int end)
5309                    throws SystemException {
5310                    return findByN_S(nodeId, status, start, end, null);
5311            }
5312    
5313            /**
5314             * Returns an ordered range of all the wiki pages where nodeId = &#63; and status = &#63;.
5315             *
5316             * <p>
5317             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5318             * </p>
5319             *
5320             * @param nodeId the node ID
5321             * @param status the status
5322             * @param start the lower bound of the range of wiki pages
5323             * @param end the upper bound of the range of wiki pages (not inclusive)
5324             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5325             * @return the ordered range of matching wiki pages
5326             * @throws SystemException if a system exception occurred
5327             */
5328            @Override
5329            public List<WikiPage> findByN_S(long nodeId, int status, int start,
5330                    int end, OrderByComparator orderByComparator) throws SystemException {
5331                    boolean pagination = true;
5332                    FinderPath finderPath = null;
5333                    Object[] finderArgs = null;
5334    
5335                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5336                                    (orderByComparator == null)) {
5337                            pagination = false;
5338                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S;
5339                            finderArgs = new Object[] { nodeId, status };
5340                    }
5341                    else {
5342                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_S;
5343                            finderArgs = new Object[] {
5344                                            nodeId, status,
5345                                            
5346                                            start, end, orderByComparator
5347                                    };
5348                    }
5349    
5350                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
5351                                    finderArgs, this);
5352    
5353                    if ((list != null) && !list.isEmpty()) {
5354                            for (WikiPage wikiPage : list) {
5355                                    if ((nodeId != wikiPage.getNodeId()) ||
5356                                                    (status != wikiPage.getStatus())) {
5357                                            list = null;
5358    
5359                                            break;
5360                                    }
5361                            }
5362                    }
5363    
5364                    if (list == null) {
5365                            StringBundler query = null;
5366    
5367                            if (orderByComparator != null) {
5368                                    query = new StringBundler(4 +
5369                                                    (orderByComparator.getOrderByFields().length * 3));
5370                            }
5371                            else {
5372                                    query = new StringBundler(4);
5373                            }
5374    
5375                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5376    
5377                            query.append(_FINDER_COLUMN_N_S_NODEID_2);
5378    
5379                            query.append(_FINDER_COLUMN_N_S_STATUS_2);
5380    
5381                            if (orderByComparator != null) {
5382                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5383                                            orderByComparator);
5384                            }
5385                            else
5386                             if (pagination) {
5387                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5388                            }
5389    
5390                            String sql = query.toString();
5391    
5392                            Session session = null;
5393    
5394                            try {
5395                                    session = openSession();
5396    
5397                                    Query q = session.createQuery(sql);
5398    
5399                                    QueryPos qPos = QueryPos.getInstance(q);
5400    
5401                                    qPos.add(nodeId);
5402    
5403                                    qPos.add(status);
5404    
5405                                    if (!pagination) {
5406                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
5407                                                            start, end, false);
5408    
5409                                            Collections.sort(list);
5410    
5411                                            list = new UnmodifiableList<WikiPage>(list);
5412                                    }
5413                                    else {
5414                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
5415                                                            start, end);
5416                                    }
5417    
5418                                    cacheResult(list);
5419    
5420                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5421                            }
5422                            catch (Exception e) {
5423                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5424    
5425                                    throw processException(e);
5426                            }
5427                            finally {
5428                                    closeSession(session);
5429                            }
5430                    }
5431    
5432                    return list;
5433            }
5434    
5435            /**
5436             * Returns the first wiki page in the ordered set where nodeId = &#63; and status = &#63;.
5437             *
5438             * @param nodeId the node ID
5439             * @param status the status
5440             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5441             * @return the first matching wiki page
5442             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5443             * @throws SystemException if a system exception occurred
5444             */
5445            @Override
5446            public WikiPage findByN_S_First(long nodeId, int status,
5447                    OrderByComparator orderByComparator)
5448                    throws NoSuchPageException, SystemException {
5449                    WikiPage wikiPage = fetchByN_S_First(nodeId, status, orderByComparator);
5450    
5451                    if (wikiPage != null) {
5452                            return wikiPage;
5453                    }
5454    
5455                    StringBundler msg = new StringBundler(6);
5456    
5457                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5458    
5459                    msg.append("nodeId=");
5460                    msg.append(nodeId);
5461    
5462                    msg.append(", status=");
5463                    msg.append(status);
5464    
5465                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5466    
5467                    throw new NoSuchPageException(msg.toString());
5468            }
5469    
5470            /**
5471             * Returns the first wiki page in the ordered set where nodeId = &#63; and status = &#63;.
5472             *
5473             * @param nodeId the node ID
5474             * @param status the status
5475             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5476             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
5477             * @throws SystemException if a system exception occurred
5478             */
5479            @Override
5480            public WikiPage fetchByN_S_First(long nodeId, int status,
5481                    OrderByComparator orderByComparator) throws SystemException {
5482                    List<WikiPage> list = findByN_S(nodeId, status, 0, 1, orderByComparator);
5483    
5484                    if (!list.isEmpty()) {
5485                            return list.get(0);
5486                    }
5487    
5488                    return null;
5489            }
5490    
5491            /**
5492             * Returns the last wiki page in the ordered set where nodeId = &#63; and status = &#63;.
5493             *
5494             * @param nodeId the node ID
5495             * @param status the status
5496             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5497             * @return the last matching wiki page
5498             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5499             * @throws SystemException if a system exception occurred
5500             */
5501            @Override
5502            public WikiPage findByN_S_Last(long nodeId, int status,
5503                    OrderByComparator orderByComparator)
5504                    throws NoSuchPageException, SystemException {
5505                    WikiPage wikiPage = fetchByN_S_Last(nodeId, status, orderByComparator);
5506    
5507                    if (wikiPage != null) {
5508                            return wikiPage;
5509                    }
5510    
5511                    StringBundler msg = new StringBundler(6);
5512    
5513                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5514    
5515                    msg.append("nodeId=");
5516                    msg.append(nodeId);
5517    
5518                    msg.append(", status=");
5519                    msg.append(status);
5520    
5521                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5522    
5523                    throw new NoSuchPageException(msg.toString());
5524            }
5525    
5526            /**
5527             * Returns the last wiki page in the ordered set where nodeId = &#63; and status = &#63;.
5528             *
5529             * @param nodeId the node ID
5530             * @param status the status
5531             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5532             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
5533             * @throws SystemException if a system exception occurred
5534             */
5535            @Override
5536            public WikiPage fetchByN_S_Last(long nodeId, int status,
5537                    OrderByComparator orderByComparator) throws SystemException {
5538                    int count = countByN_S(nodeId, status);
5539    
5540                    if (count == 0) {
5541                            return null;
5542                    }
5543    
5544                    List<WikiPage> list = findByN_S(nodeId, status, count - 1, count,
5545                                    orderByComparator);
5546    
5547                    if (!list.isEmpty()) {
5548                            return list.get(0);
5549                    }
5550    
5551                    return null;
5552            }
5553    
5554            /**
5555             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and status = &#63;.
5556             *
5557             * @param pageId the primary key of the current wiki page
5558             * @param nodeId the node ID
5559             * @param status the status
5560             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5561             * @return the previous, current, and next wiki page
5562             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
5563             * @throws SystemException if a system exception occurred
5564             */
5565            @Override
5566            public WikiPage[] findByN_S_PrevAndNext(long pageId, long nodeId,
5567                    int status, OrderByComparator orderByComparator)
5568                    throws NoSuchPageException, SystemException {
5569                    WikiPage wikiPage = findByPrimaryKey(pageId);
5570    
5571                    Session session = null;
5572    
5573                    try {
5574                            session = openSession();
5575    
5576                            WikiPage[] array = new WikiPageImpl[3];
5577    
5578                            array[0] = getByN_S_PrevAndNext(session, wikiPage, nodeId, status,
5579                                            orderByComparator, true);
5580    
5581                            array[1] = wikiPage;
5582    
5583                            array[2] = getByN_S_PrevAndNext(session, wikiPage, nodeId, status,
5584                                            orderByComparator, false);
5585    
5586                            return array;
5587                    }
5588                    catch (Exception e) {
5589                            throw processException(e);
5590                    }
5591                    finally {
5592                            closeSession(session);
5593                    }
5594            }
5595    
5596            protected WikiPage getByN_S_PrevAndNext(Session session, WikiPage wikiPage,
5597                    long nodeId, int status, OrderByComparator orderByComparator,
5598                    boolean previous) {
5599                    StringBundler query = null;
5600    
5601                    if (orderByComparator != null) {
5602                            query = new StringBundler(6 +
5603                                            (orderByComparator.getOrderByFields().length * 6));
5604                    }
5605                    else {
5606                            query = new StringBundler(3);
5607                    }
5608    
5609                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5610    
5611                    query.append(_FINDER_COLUMN_N_S_NODEID_2);
5612    
5613                    query.append(_FINDER_COLUMN_N_S_STATUS_2);
5614    
5615                    if (orderByComparator != null) {
5616                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5617    
5618                            if (orderByConditionFields.length > 0) {
5619                                    query.append(WHERE_AND);
5620                            }
5621    
5622                            for (int i = 0; i < orderByConditionFields.length; i++) {
5623                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5624                                    query.append(orderByConditionFields[i]);
5625    
5626                                    if ((i + 1) < orderByConditionFields.length) {
5627                                            if (orderByComparator.isAscending() ^ previous) {
5628                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5629                                            }
5630                                            else {
5631                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5632                                            }
5633                                    }
5634                                    else {
5635                                            if (orderByComparator.isAscending() ^ previous) {
5636                                                    query.append(WHERE_GREATER_THAN);
5637                                            }
5638                                            else {
5639                                                    query.append(WHERE_LESSER_THAN);
5640                                            }
5641                                    }
5642                            }
5643    
5644                            query.append(ORDER_BY_CLAUSE);
5645    
5646                            String[] orderByFields = orderByComparator.getOrderByFields();
5647    
5648                            for (int i = 0; i < orderByFields.length; i++) {
5649                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5650                                    query.append(orderByFields[i]);
5651    
5652                                    if ((i + 1) < orderByFields.length) {
5653                                            if (orderByComparator.isAscending() ^ previous) {
5654                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5655                                            }
5656                                            else {
5657                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5658                                            }
5659                                    }
5660                                    else {
5661                                            if (orderByComparator.isAscending() ^ previous) {
5662                                                    query.append(ORDER_BY_ASC);
5663                                            }
5664                                            else {
5665                                                    query.append(ORDER_BY_DESC);
5666                                            }
5667                                    }
5668                            }
5669                    }
5670                    else {
5671                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5672                    }
5673    
5674                    String sql = query.toString();
5675    
5676                    Query q = session.createQuery(sql);
5677    
5678                    q.setFirstResult(0);
5679                    q.setMaxResults(2);
5680    
5681                    QueryPos qPos = QueryPos.getInstance(q);
5682    
5683                    qPos.add(nodeId);
5684    
5685                    qPos.add(status);
5686    
5687                    if (orderByComparator != null) {
5688                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
5689    
5690                            for (Object value : values) {
5691                                    qPos.add(value);
5692                            }
5693                    }
5694    
5695                    List<WikiPage> list = q.list();
5696    
5697                    if (list.size() == 2) {
5698                            return list.get(1);
5699                    }
5700                    else {
5701                            return null;
5702                    }
5703            }
5704    
5705            /**
5706             * Removes all the wiki pages where nodeId = &#63; and status = &#63; from the database.
5707             *
5708             * @param nodeId the node ID
5709             * @param status the status
5710             * @throws SystemException if a system exception occurred
5711             */
5712            @Override
5713            public void removeByN_S(long nodeId, int status) throws SystemException {
5714                    for (WikiPage wikiPage : findByN_S(nodeId, status, QueryUtil.ALL_POS,
5715                                    QueryUtil.ALL_POS, null)) {
5716                            remove(wikiPage);
5717                    }
5718            }
5719    
5720            /**
5721             * Returns the number of wiki pages where nodeId = &#63; and status = &#63;.
5722             *
5723             * @param nodeId the node ID
5724             * @param status the status
5725             * @return the number of matching wiki pages
5726             * @throws SystemException if a system exception occurred
5727             */
5728            @Override
5729            public int countByN_S(long nodeId, int status) throws SystemException {
5730                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_S;
5731    
5732                    Object[] finderArgs = new Object[] { nodeId, status };
5733    
5734                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5735                                    this);
5736    
5737                    if (count == null) {
5738                            StringBundler query = new StringBundler(3);
5739    
5740                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
5741    
5742                            query.append(_FINDER_COLUMN_N_S_NODEID_2);
5743    
5744                            query.append(_FINDER_COLUMN_N_S_STATUS_2);
5745    
5746                            String sql = query.toString();
5747    
5748                            Session session = null;
5749    
5750                            try {
5751                                    session = openSession();
5752    
5753                                    Query q = session.createQuery(sql);
5754    
5755                                    QueryPos qPos = QueryPos.getInstance(q);
5756    
5757                                    qPos.add(nodeId);
5758    
5759                                    qPos.add(status);
5760    
5761                                    count = (Long)q.uniqueResult();
5762    
5763                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5764                            }
5765                            catch (Exception e) {
5766                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5767    
5768                                    throw processException(e);
5769                            }
5770                            finally {
5771                                    closeSession(session);
5772                            }
5773                    }
5774    
5775                    return count.intValue();
5776            }
5777    
5778            private static final String _FINDER_COLUMN_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
5779            private static final String _FINDER_COLUMN_N_S_STATUS_2 = "wikiPage.status = ?";
5780            public static final FinderPath FINDER_PATH_FETCH_BY_R_N_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5781                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5782                            FINDER_CLASS_NAME_ENTITY, "fetchByR_N_V",
5783                            new String[] {
5784                                    Long.class.getName(), Long.class.getName(),
5785                                    Double.class.getName()
5786                            },
5787                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
5788                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
5789                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
5790            public static final FinderPath FINDER_PATH_COUNT_BY_R_N_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5791                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5792                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N_V",
5793                            new String[] {
5794                                    Long.class.getName(), Long.class.getName(),
5795                                    Double.class.getName()
5796                            });
5797    
5798            /**
5799             * 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.
5800             *
5801             * @param resourcePrimKey the resource prim key
5802             * @param nodeId the node ID
5803             * @param version the version
5804             * @return the matching wiki page
5805             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5806             * @throws SystemException if a system exception occurred
5807             */
5808            @Override
5809            public WikiPage findByR_N_V(long resourcePrimKey, long nodeId,
5810                    double version) throws NoSuchPageException, SystemException {
5811                    WikiPage wikiPage = fetchByR_N_V(resourcePrimKey, nodeId, version);
5812    
5813                    if (wikiPage == null) {
5814                            StringBundler msg = new StringBundler(8);
5815    
5816                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5817    
5818                            msg.append("resourcePrimKey=");
5819                            msg.append(resourcePrimKey);
5820    
5821                            msg.append(", nodeId=");
5822                            msg.append(nodeId);
5823    
5824                            msg.append(", version=");
5825                            msg.append(version);
5826    
5827                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5828    
5829                            if (_log.isWarnEnabled()) {
5830                                    _log.warn(msg.toString());
5831                            }
5832    
5833                            throw new NoSuchPageException(msg.toString());
5834                    }
5835    
5836                    return wikiPage;
5837            }
5838    
5839            /**
5840             * 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.
5841             *
5842             * @param resourcePrimKey the resource prim key
5843             * @param nodeId the node ID
5844             * @param version the version
5845             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
5846             * @throws SystemException if a system exception occurred
5847             */
5848            @Override
5849            public WikiPage fetchByR_N_V(long resourcePrimKey, long nodeId,
5850                    double version) throws SystemException {
5851                    return fetchByR_N_V(resourcePrimKey, nodeId, version, true);
5852            }
5853    
5854            /**
5855             * 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.
5856             *
5857             * @param resourcePrimKey the resource prim key
5858             * @param nodeId the node ID
5859             * @param version the version
5860             * @param retrieveFromCache whether to use the finder cache
5861             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
5862             * @throws SystemException if a system exception occurred
5863             */
5864            @Override
5865            public WikiPage fetchByR_N_V(long resourcePrimKey, long nodeId,
5866                    double version, boolean retrieveFromCache) throws SystemException {
5867                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, version };
5868    
5869                    Object result = null;
5870    
5871                    if (retrieveFromCache) {
5872                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_R_N_V,
5873                                            finderArgs, this);
5874                    }
5875    
5876                    if (result instanceof WikiPage) {
5877                            WikiPage wikiPage = (WikiPage)result;
5878    
5879                            if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
5880                                            (nodeId != wikiPage.getNodeId()) ||
5881                                            (version != wikiPage.getVersion())) {
5882                                    result = null;
5883                            }
5884                    }
5885    
5886                    if (result == null) {
5887                            StringBundler query = new StringBundler(5);
5888    
5889                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5890    
5891                            query.append(_FINDER_COLUMN_R_N_V_RESOURCEPRIMKEY_2);
5892    
5893                            query.append(_FINDER_COLUMN_R_N_V_NODEID_2);
5894    
5895                            query.append(_FINDER_COLUMN_R_N_V_VERSION_2);
5896    
5897                            String sql = query.toString();
5898    
5899                            Session session = null;
5900    
5901                            try {
5902                                    session = openSession();
5903    
5904                                    Query q = session.createQuery(sql);
5905    
5906                                    QueryPos qPos = QueryPos.getInstance(q);
5907    
5908                                    qPos.add(resourcePrimKey);
5909    
5910                                    qPos.add(nodeId);
5911    
5912                                    qPos.add(version);
5913    
5914                                    List<WikiPage> list = q.list();
5915    
5916                                    if (list.isEmpty()) {
5917                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
5918                                                    finderArgs, list);
5919                                    }
5920                                    else {
5921                                            WikiPage wikiPage = list.get(0);
5922    
5923                                            result = wikiPage;
5924    
5925                                            cacheResult(wikiPage);
5926    
5927                                            if ((wikiPage.getResourcePrimKey() != resourcePrimKey) ||
5928                                                            (wikiPage.getNodeId() != nodeId) ||
5929                                                            (wikiPage.getVersion() != version)) {
5930                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
5931                                                            finderArgs, wikiPage);
5932                                            }
5933                                    }
5934                            }
5935                            catch (Exception e) {
5936                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V,
5937                                            finderArgs);
5938    
5939                                    throw processException(e);
5940                            }
5941                            finally {
5942                                    closeSession(session);
5943                            }
5944                    }
5945    
5946                    if (result instanceof List<?>) {
5947                            return null;
5948                    }
5949                    else {
5950                            return (WikiPage)result;
5951                    }
5952            }
5953    
5954            /**
5955             * Removes the wiki page where resourcePrimKey = &#63; and nodeId = &#63; and version = &#63; from the database.
5956             *
5957             * @param resourcePrimKey the resource prim key
5958             * @param nodeId the node ID
5959             * @param version the version
5960             * @return the wiki page that was removed
5961             * @throws SystemException if a system exception occurred
5962             */
5963            @Override
5964            public WikiPage removeByR_N_V(long resourcePrimKey, long nodeId,
5965                    double version) throws NoSuchPageException, SystemException {
5966                    WikiPage wikiPage = findByR_N_V(resourcePrimKey, nodeId, version);
5967    
5968                    return remove(wikiPage);
5969            }
5970    
5971            /**
5972             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and version = &#63;.
5973             *
5974             * @param resourcePrimKey the resource prim key
5975             * @param nodeId the node ID
5976             * @param version the version
5977             * @return the number of matching wiki pages
5978             * @throws SystemException if a system exception occurred
5979             */
5980            @Override
5981            public int countByR_N_V(long resourcePrimKey, long nodeId, double version)
5982                    throws SystemException {
5983                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N_V;
5984    
5985                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, version };
5986    
5987                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5988                                    this);
5989    
5990                    if (count == null) {
5991                            StringBundler query = new StringBundler(4);
5992    
5993                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
5994    
5995                            query.append(_FINDER_COLUMN_R_N_V_RESOURCEPRIMKEY_2);
5996    
5997                            query.append(_FINDER_COLUMN_R_N_V_NODEID_2);
5998    
5999                            query.append(_FINDER_COLUMN_R_N_V_VERSION_2);
6000    
6001                            String sql = query.toString();
6002    
6003                            Session session = null;
6004    
6005                            try {
6006                                    session = openSession();
6007    
6008                                    Query q = session.createQuery(sql);
6009    
6010                                    QueryPos qPos = QueryPos.getInstance(q);
6011    
6012                                    qPos.add(resourcePrimKey);
6013    
6014                                    qPos.add(nodeId);
6015    
6016                                    qPos.add(version);
6017    
6018                                    count = (Long)q.uniqueResult();
6019    
6020                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6021                            }
6022                            catch (Exception e) {
6023                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6024    
6025                                    throw processException(e);
6026                            }
6027                            finally {
6028                                    closeSession(session);
6029                            }
6030                    }
6031    
6032                    return count.intValue();
6033            }
6034    
6035            private static final String _FINDER_COLUMN_R_N_V_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
6036            private static final String _FINDER_COLUMN_R_N_V_NODEID_2 = "wikiPage.nodeId = ? AND ";
6037            private static final String _FINDER_COLUMN_R_N_V_VERSION_2 = "wikiPage.version = ?";
6038            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6039                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
6040                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_N_H",
6041                            new String[] {
6042                                    Long.class.getName(), Long.class.getName(),
6043                                    Boolean.class.getName(),
6044                                    
6045                            Integer.class.getName(), Integer.class.getName(),
6046                                    OrderByComparator.class.getName()
6047                            });
6048            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6049                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
6050                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_N_H",
6051                            new String[] {
6052                                    Long.class.getName(), Long.class.getName(),
6053                                    Boolean.class.getName()
6054                            },
6055                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
6056                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
6057                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
6058                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
6059                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
6060            public static final FinderPath FINDER_PATH_COUNT_BY_R_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6061                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6062                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N_H",
6063                            new String[] {
6064                                    Long.class.getName(), Long.class.getName(),
6065                                    Boolean.class.getName()
6066                            });
6067    
6068            /**
6069             * Returns all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6070             *
6071             * @param resourcePrimKey the resource prim key
6072             * @param nodeId the node ID
6073             * @param head the head
6074             * @return the matching wiki pages
6075             * @throws SystemException if a system exception occurred
6076             */
6077            @Override
6078            public List<WikiPage> findByR_N_H(long resourcePrimKey, long nodeId,
6079                    boolean head) throws SystemException {
6080                    return findByR_N_H(resourcePrimKey, nodeId, head, QueryUtil.ALL_POS,
6081                            QueryUtil.ALL_POS, null);
6082            }
6083    
6084            /**
6085             * Returns a range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6086             *
6087             * <p>
6088             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6089             * </p>
6090             *
6091             * @param resourcePrimKey the resource prim key
6092             * @param nodeId the node ID
6093             * @param head the head
6094             * @param start the lower bound of the range of wiki pages
6095             * @param end the upper bound of the range of wiki pages (not inclusive)
6096             * @return the range of matching wiki pages
6097             * @throws SystemException if a system exception occurred
6098             */
6099            @Override
6100            public List<WikiPage> findByR_N_H(long resourcePrimKey, long nodeId,
6101                    boolean head, int start, int end) throws SystemException {
6102                    return findByR_N_H(resourcePrimKey, nodeId, head, start, end, null);
6103            }
6104    
6105            /**
6106             * Returns an ordered range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6107             *
6108             * <p>
6109             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6110             * </p>
6111             *
6112             * @param resourcePrimKey the resource prim key
6113             * @param nodeId the node ID
6114             * @param head the head
6115             * @param start the lower bound of the range of wiki pages
6116             * @param end the upper bound of the range of wiki pages (not inclusive)
6117             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6118             * @return the ordered range of matching wiki pages
6119             * @throws SystemException if a system exception occurred
6120             */
6121            @Override
6122            public List<WikiPage> findByR_N_H(long resourcePrimKey, long nodeId,
6123                    boolean head, int start, int end, OrderByComparator orderByComparator)
6124                    throws SystemException {
6125                    boolean pagination = true;
6126                    FinderPath finderPath = null;
6127                    Object[] finderArgs = null;
6128    
6129                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6130                                    (orderByComparator == null)) {
6131                            pagination = false;
6132                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H;
6133                            finderArgs = new Object[] { resourcePrimKey, nodeId, head };
6134                    }
6135                    else {
6136                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_H;
6137                            finderArgs = new Object[] {
6138                                            resourcePrimKey, nodeId, head,
6139                                            
6140                                            start, end, orderByComparator
6141                                    };
6142                    }
6143    
6144                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
6145                                    finderArgs, this);
6146    
6147                    if ((list != null) && !list.isEmpty()) {
6148                            for (WikiPage wikiPage : list) {
6149                                    if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
6150                                                    (nodeId != wikiPage.getNodeId()) ||
6151                                                    (head != wikiPage.getHead())) {
6152                                            list = null;
6153    
6154                                            break;
6155                                    }
6156                            }
6157                    }
6158    
6159                    if (list == null) {
6160                            StringBundler query = null;
6161    
6162                            if (orderByComparator != null) {
6163                                    query = new StringBundler(5 +
6164                                                    (orderByComparator.getOrderByFields().length * 3));
6165                            }
6166                            else {
6167                                    query = new StringBundler(5);
6168                            }
6169    
6170                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6171    
6172                            query.append(_FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2);
6173    
6174                            query.append(_FINDER_COLUMN_R_N_H_NODEID_2);
6175    
6176                            query.append(_FINDER_COLUMN_R_N_H_HEAD_2);
6177    
6178                            if (orderByComparator != null) {
6179                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6180                                            orderByComparator);
6181                            }
6182                            else
6183                             if (pagination) {
6184                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6185                            }
6186    
6187                            String sql = query.toString();
6188    
6189                            Session session = null;
6190    
6191                            try {
6192                                    session = openSession();
6193    
6194                                    Query q = session.createQuery(sql);
6195    
6196                                    QueryPos qPos = QueryPos.getInstance(q);
6197    
6198                                    qPos.add(resourcePrimKey);
6199    
6200                                    qPos.add(nodeId);
6201    
6202                                    qPos.add(head);
6203    
6204                                    if (!pagination) {
6205                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
6206                                                            start, end, false);
6207    
6208                                            Collections.sort(list);
6209    
6210                                            list = new UnmodifiableList<WikiPage>(list);
6211                                    }
6212                                    else {
6213                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
6214                                                            start, end);
6215                                    }
6216    
6217                                    cacheResult(list);
6218    
6219                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6220                            }
6221                            catch (Exception e) {
6222                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6223    
6224                                    throw processException(e);
6225                            }
6226                            finally {
6227                                    closeSession(session);
6228                            }
6229                    }
6230    
6231                    return list;
6232            }
6233    
6234            /**
6235             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6236             *
6237             * @param resourcePrimKey the resource prim key
6238             * @param nodeId the node ID
6239             * @param head the head
6240             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6241             * @return the first matching wiki page
6242             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6243             * @throws SystemException if a system exception occurred
6244             */
6245            @Override
6246            public WikiPage findByR_N_H_First(long resourcePrimKey, long nodeId,
6247                    boolean head, OrderByComparator orderByComparator)
6248                    throws NoSuchPageException, SystemException {
6249                    WikiPage wikiPage = fetchByR_N_H_First(resourcePrimKey, nodeId, head,
6250                                    orderByComparator);
6251    
6252                    if (wikiPage != null) {
6253                            return wikiPage;
6254                    }
6255    
6256                    StringBundler msg = new StringBundler(8);
6257    
6258                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6259    
6260                    msg.append("resourcePrimKey=");
6261                    msg.append(resourcePrimKey);
6262    
6263                    msg.append(", nodeId=");
6264                    msg.append(nodeId);
6265    
6266                    msg.append(", head=");
6267                    msg.append(head);
6268    
6269                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6270    
6271                    throw new NoSuchPageException(msg.toString());
6272            }
6273    
6274            /**
6275             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6276             *
6277             * @param resourcePrimKey the resource prim key
6278             * @param nodeId the node ID
6279             * @param head the head
6280             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6281             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
6282             * @throws SystemException if a system exception occurred
6283             */
6284            @Override
6285            public WikiPage fetchByR_N_H_First(long resourcePrimKey, long nodeId,
6286                    boolean head, OrderByComparator orderByComparator)
6287                    throws SystemException {
6288                    List<WikiPage> list = findByR_N_H(resourcePrimKey, nodeId, head, 0, 1,
6289                                    orderByComparator);
6290    
6291                    if (!list.isEmpty()) {
6292                            return list.get(0);
6293                    }
6294    
6295                    return null;
6296            }
6297    
6298            /**
6299             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6300             *
6301             * @param resourcePrimKey the resource prim key
6302             * @param nodeId the node ID
6303             * @param head the head
6304             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6305             * @return the last matching wiki page
6306             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6307             * @throws SystemException if a system exception occurred
6308             */
6309            @Override
6310            public WikiPage findByR_N_H_Last(long resourcePrimKey, long nodeId,
6311                    boolean head, OrderByComparator orderByComparator)
6312                    throws NoSuchPageException, SystemException {
6313                    WikiPage wikiPage = fetchByR_N_H_Last(resourcePrimKey, nodeId, head,
6314                                    orderByComparator);
6315    
6316                    if (wikiPage != null) {
6317                            return wikiPage;
6318                    }
6319    
6320                    StringBundler msg = new StringBundler(8);
6321    
6322                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6323    
6324                    msg.append("resourcePrimKey=");
6325                    msg.append(resourcePrimKey);
6326    
6327                    msg.append(", nodeId=");
6328                    msg.append(nodeId);
6329    
6330                    msg.append(", head=");
6331                    msg.append(head);
6332    
6333                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6334    
6335                    throw new NoSuchPageException(msg.toString());
6336            }
6337    
6338            /**
6339             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6340             *
6341             * @param resourcePrimKey the resource prim key
6342             * @param nodeId the node ID
6343             * @param head the head
6344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6345             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
6346             * @throws SystemException if a system exception occurred
6347             */
6348            @Override
6349            public WikiPage fetchByR_N_H_Last(long resourcePrimKey, long nodeId,
6350                    boolean head, OrderByComparator orderByComparator)
6351                    throws SystemException {
6352                    int count = countByR_N_H(resourcePrimKey, nodeId, head);
6353    
6354                    if (count == 0) {
6355                            return null;
6356                    }
6357    
6358                    List<WikiPage> list = findByR_N_H(resourcePrimKey, nodeId, head,
6359                                    count - 1, count, orderByComparator);
6360    
6361                    if (!list.isEmpty()) {
6362                            return list.get(0);
6363                    }
6364    
6365                    return null;
6366            }
6367    
6368            /**
6369             * Returns the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6370             *
6371             * @param pageId the primary key of the current wiki page
6372             * @param resourcePrimKey the resource prim key
6373             * @param nodeId the node ID
6374             * @param head the head
6375             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6376             * @return the previous, current, and next wiki page
6377             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
6378             * @throws SystemException if a system exception occurred
6379             */
6380            @Override
6381            public WikiPage[] findByR_N_H_PrevAndNext(long pageId,
6382                    long resourcePrimKey, long nodeId, boolean head,
6383                    OrderByComparator orderByComparator)
6384                    throws NoSuchPageException, SystemException {
6385                    WikiPage wikiPage = findByPrimaryKey(pageId);
6386    
6387                    Session session = null;
6388    
6389                    try {
6390                            session = openSession();
6391    
6392                            WikiPage[] array = new WikiPageImpl[3];
6393    
6394                            array[0] = getByR_N_H_PrevAndNext(session, wikiPage,
6395                                            resourcePrimKey, nodeId, head, orderByComparator, true);
6396    
6397                            array[1] = wikiPage;
6398    
6399                            array[2] = getByR_N_H_PrevAndNext(session, wikiPage,
6400                                            resourcePrimKey, nodeId, head, orderByComparator, false);
6401    
6402                            return array;
6403                    }
6404                    catch (Exception e) {
6405                            throw processException(e);
6406                    }
6407                    finally {
6408                            closeSession(session);
6409                    }
6410            }
6411    
6412            protected WikiPage getByR_N_H_PrevAndNext(Session session,
6413                    WikiPage wikiPage, long resourcePrimKey, long nodeId, boolean head,
6414                    OrderByComparator orderByComparator, boolean previous) {
6415                    StringBundler query = null;
6416    
6417                    if (orderByComparator != null) {
6418                            query = new StringBundler(6 +
6419                                            (orderByComparator.getOrderByFields().length * 6));
6420                    }
6421                    else {
6422                            query = new StringBundler(3);
6423                    }
6424    
6425                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6426    
6427                    query.append(_FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2);
6428    
6429                    query.append(_FINDER_COLUMN_R_N_H_NODEID_2);
6430    
6431                    query.append(_FINDER_COLUMN_R_N_H_HEAD_2);
6432    
6433                    if (orderByComparator != null) {
6434                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6435    
6436                            if (orderByConditionFields.length > 0) {
6437                                    query.append(WHERE_AND);
6438                            }
6439    
6440                            for (int i = 0; i < orderByConditionFields.length; i++) {
6441                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6442                                    query.append(orderByConditionFields[i]);
6443    
6444                                    if ((i + 1) < orderByConditionFields.length) {
6445                                            if (orderByComparator.isAscending() ^ previous) {
6446                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6447                                            }
6448                                            else {
6449                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6450                                            }
6451                                    }
6452                                    else {
6453                                            if (orderByComparator.isAscending() ^ previous) {
6454                                                    query.append(WHERE_GREATER_THAN);
6455                                            }
6456                                            else {
6457                                                    query.append(WHERE_LESSER_THAN);
6458                                            }
6459                                    }
6460                            }
6461    
6462                            query.append(ORDER_BY_CLAUSE);
6463    
6464                            String[] orderByFields = orderByComparator.getOrderByFields();
6465    
6466                            for (int i = 0; i < orderByFields.length; i++) {
6467                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6468                                    query.append(orderByFields[i]);
6469    
6470                                    if ((i + 1) < orderByFields.length) {
6471                                            if (orderByComparator.isAscending() ^ previous) {
6472                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6473                                            }
6474                                            else {
6475                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6476                                            }
6477                                    }
6478                                    else {
6479                                            if (orderByComparator.isAscending() ^ previous) {
6480                                                    query.append(ORDER_BY_ASC);
6481                                            }
6482                                            else {
6483                                                    query.append(ORDER_BY_DESC);
6484                                            }
6485                                    }
6486                            }
6487                    }
6488                    else {
6489                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6490                    }
6491    
6492                    String sql = query.toString();
6493    
6494                    Query q = session.createQuery(sql);
6495    
6496                    q.setFirstResult(0);
6497                    q.setMaxResults(2);
6498    
6499                    QueryPos qPos = QueryPos.getInstance(q);
6500    
6501                    qPos.add(resourcePrimKey);
6502    
6503                    qPos.add(nodeId);
6504    
6505                    qPos.add(head);
6506    
6507                    if (orderByComparator != null) {
6508                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
6509    
6510                            for (Object value : values) {
6511                                    qPos.add(value);
6512                            }
6513                    }
6514    
6515                    List<WikiPage> list = q.list();
6516    
6517                    if (list.size() == 2) {
6518                            return list.get(1);
6519                    }
6520                    else {
6521                            return null;
6522                    }
6523            }
6524    
6525            /**
6526             * Removes all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63; from the database.
6527             *
6528             * @param resourcePrimKey the resource prim key
6529             * @param nodeId the node ID
6530             * @param head the head
6531             * @throws SystemException if a system exception occurred
6532             */
6533            @Override
6534            public void removeByR_N_H(long resourcePrimKey, long nodeId, boolean head)
6535                    throws SystemException {
6536                    for (WikiPage wikiPage : findByR_N_H(resourcePrimKey, nodeId, head,
6537                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6538                            remove(wikiPage);
6539                    }
6540            }
6541    
6542            /**
6543             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6544             *
6545             * @param resourcePrimKey the resource prim key
6546             * @param nodeId the node ID
6547             * @param head the head
6548             * @return the number of matching wiki pages
6549             * @throws SystemException if a system exception occurred
6550             */
6551            @Override
6552            public int countByR_N_H(long resourcePrimKey, long nodeId, boolean head)
6553                    throws SystemException {
6554                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N_H;
6555    
6556                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, head };
6557    
6558                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6559                                    this);
6560    
6561                    if (count == null) {
6562                            StringBundler query = new StringBundler(4);
6563    
6564                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
6565    
6566                            query.append(_FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2);
6567    
6568                            query.append(_FINDER_COLUMN_R_N_H_NODEID_2);
6569    
6570                            query.append(_FINDER_COLUMN_R_N_H_HEAD_2);
6571    
6572                            String sql = query.toString();
6573    
6574                            Session session = null;
6575    
6576                            try {
6577                                    session = openSession();
6578    
6579                                    Query q = session.createQuery(sql);
6580    
6581                                    QueryPos qPos = QueryPos.getInstance(q);
6582    
6583                                    qPos.add(resourcePrimKey);
6584    
6585                                    qPos.add(nodeId);
6586    
6587                                    qPos.add(head);
6588    
6589                                    count = (Long)q.uniqueResult();
6590    
6591                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6592                            }
6593                            catch (Exception e) {
6594                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6595    
6596                                    throw processException(e);
6597                            }
6598                            finally {
6599                                    closeSession(session);
6600                            }
6601                    }
6602    
6603                    return count.intValue();
6604            }
6605    
6606            private static final String _FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
6607            private static final String _FINDER_COLUMN_R_N_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
6608            private static final String _FINDER_COLUMN_R_N_H_HEAD_2 = "wikiPage.head = ?";
6609            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6610                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
6611                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_N_S",
6612                            new String[] {
6613                                    Long.class.getName(), Long.class.getName(),
6614                                    Integer.class.getName(),
6615                                    
6616                            Integer.class.getName(), Integer.class.getName(),
6617                                    OrderByComparator.class.getName()
6618                            });
6619            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6620                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
6621                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_N_S",
6622                            new String[] {
6623                                    Long.class.getName(), Long.class.getName(),
6624                                    Integer.class.getName()
6625                            },
6626                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
6627                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
6628                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
6629                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
6630                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
6631            public static final FinderPath FINDER_PATH_COUNT_BY_R_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6632                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6633                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N_S",
6634                            new String[] {
6635                                    Long.class.getName(), Long.class.getName(),
6636                                    Integer.class.getName()
6637                            });
6638    
6639            /**
6640             * Returns all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6641             *
6642             * @param resourcePrimKey the resource prim key
6643             * @param nodeId the node ID
6644             * @param status the status
6645             * @return the matching wiki pages
6646             * @throws SystemException if a system exception occurred
6647             */
6648            @Override
6649            public List<WikiPage> findByR_N_S(long resourcePrimKey, long nodeId,
6650                    int status) throws SystemException {
6651                    return findByR_N_S(resourcePrimKey, nodeId, status, QueryUtil.ALL_POS,
6652                            QueryUtil.ALL_POS, null);
6653            }
6654    
6655            /**
6656             * Returns a range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6657             *
6658             * <p>
6659             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6660             * </p>
6661             *
6662             * @param resourcePrimKey the resource prim key
6663             * @param nodeId the node ID
6664             * @param status the status
6665             * @param start the lower bound of the range of wiki pages
6666             * @param end the upper bound of the range of wiki pages (not inclusive)
6667             * @return the range of matching wiki pages
6668             * @throws SystemException if a system exception occurred
6669             */
6670            @Override
6671            public List<WikiPage> findByR_N_S(long resourcePrimKey, long nodeId,
6672                    int status, int start, int end) throws SystemException {
6673                    return findByR_N_S(resourcePrimKey, nodeId, status, start, end, null);
6674            }
6675    
6676            /**
6677             * Returns an ordered range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6678             *
6679             * <p>
6680             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6681             * </p>
6682             *
6683             * @param resourcePrimKey the resource prim key
6684             * @param nodeId the node ID
6685             * @param status the status
6686             * @param start the lower bound of the range of wiki pages
6687             * @param end the upper bound of the range of wiki pages (not inclusive)
6688             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6689             * @return the ordered range of matching wiki pages
6690             * @throws SystemException if a system exception occurred
6691             */
6692            @Override
6693            public List<WikiPage> findByR_N_S(long resourcePrimKey, long nodeId,
6694                    int status, int start, int end, OrderByComparator orderByComparator)
6695                    throws SystemException {
6696                    boolean pagination = true;
6697                    FinderPath finderPath = null;
6698                    Object[] finderArgs = null;
6699    
6700                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6701                                    (orderByComparator == null)) {
6702                            pagination = false;
6703                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S;
6704                            finderArgs = new Object[] { resourcePrimKey, nodeId, status };
6705                    }
6706                    else {
6707                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_S;
6708                            finderArgs = new Object[] {
6709                                            resourcePrimKey, nodeId, status,
6710                                            
6711                                            start, end, orderByComparator
6712                                    };
6713                    }
6714    
6715                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
6716                                    finderArgs, this);
6717    
6718                    if ((list != null) && !list.isEmpty()) {
6719                            for (WikiPage wikiPage : list) {
6720                                    if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
6721                                                    (nodeId != wikiPage.getNodeId()) ||
6722                                                    (status != wikiPage.getStatus())) {
6723                                            list = null;
6724    
6725                                            break;
6726                                    }
6727                            }
6728                    }
6729    
6730                    if (list == null) {
6731                            StringBundler query = null;
6732    
6733                            if (orderByComparator != null) {
6734                                    query = new StringBundler(5 +
6735                                                    (orderByComparator.getOrderByFields().length * 3));
6736                            }
6737                            else {
6738                                    query = new StringBundler(5);
6739                            }
6740    
6741                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6742    
6743                            query.append(_FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2);
6744    
6745                            query.append(_FINDER_COLUMN_R_N_S_NODEID_2);
6746    
6747                            query.append(_FINDER_COLUMN_R_N_S_STATUS_2);
6748    
6749                            if (orderByComparator != null) {
6750                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6751                                            orderByComparator);
6752                            }
6753                            else
6754                             if (pagination) {
6755                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6756                            }
6757    
6758                            String sql = query.toString();
6759    
6760                            Session session = null;
6761    
6762                            try {
6763                                    session = openSession();
6764    
6765                                    Query q = session.createQuery(sql);
6766    
6767                                    QueryPos qPos = QueryPos.getInstance(q);
6768    
6769                                    qPos.add(resourcePrimKey);
6770    
6771                                    qPos.add(nodeId);
6772    
6773                                    qPos.add(status);
6774    
6775                                    if (!pagination) {
6776                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
6777                                                            start, end, false);
6778    
6779                                            Collections.sort(list);
6780    
6781                                            list = new UnmodifiableList<WikiPage>(list);
6782                                    }
6783                                    else {
6784                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
6785                                                            start, end);
6786                                    }
6787    
6788                                    cacheResult(list);
6789    
6790                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6791                            }
6792                            catch (Exception e) {
6793                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6794    
6795                                    throw processException(e);
6796                            }
6797                            finally {
6798                                    closeSession(session);
6799                            }
6800                    }
6801    
6802                    return list;
6803            }
6804    
6805            /**
6806             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6807             *
6808             * @param resourcePrimKey the resource prim key
6809             * @param nodeId the node ID
6810             * @param status the status
6811             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6812             * @return the first matching wiki page
6813             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6814             * @throws SystemException if a system exception occurred
6815             */
6816            @Override
6817            public WikiPage findByR_N_S_First(long resourcePrimKey, long nodeId,
6818                    int status, OrderByComparator orderByComparator)
6819                    throws NoSuchPageException, SystemException {
6820                    WikiPage wikiPage = fetchByR_N_S_First(resourcePrimKey, nodeId, status,
6821                                    orderByComparator);
6822    
6823                    if (wikiPage != null) {
6824                            return wikiPage;
6825                    }
6826    
6827                    StringBundler msg = new StringBundler(8);
6828    
6829                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6830    
6831                    msg.append("resourcePrimKey=");
6832                    msg.append(resourcePrimKey);
6833    
6834                    msg.append(", nodeId=");
6835                    msg.append(nodeId);
6836    
6837                    msg.append(", status=");
6838                    msg.append(status);
6839    
6840                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6841    
6842                    throw new NoSuchPageException(msg.toString());
6843            }
6844    
6845            /**
6846             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6847             *
6848             * @param resourcePrimKey the resource prim key
6849             * @param nodeId the node ID
6850             * @param status the status
6851             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6852             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
6853             * @throws SystemException if a system exception occurred
6854             */
6855            @Override
6856            public WikiPage fetchByR_N_S_First(long resourcePrimKey, long nodeId,
6857                    int status, OrderByComparator orderByComparator)
6858                    throws SystemException {
6859                    List<WikiPage> list = findByR_N_S(resourcePrimKey, nodeId, status, 0,
6860                                    1, orderByComparator);
6861    
6862                    if (!list.isEmpty()) {
6863                            return list.get(0);
6864                    }
6865    
6866                    return null;
6867            }
6868    
6869            /**
6870             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6871             *
6872             * @param resourcePrimKey the resource prim key
6873             * @param nodeId the node ID
6874             * @param status the status
6875             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6876             * @return the last matching wiki page
6877             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6878             * @throws SystemException if a system exception occurred
6879             */
6880            @Override
6881            public WikiPage findByR_N_S_Last(long resourcePrimKey, long nodeId,
6882                    int status, OrderByComparator orderByComparator)
6883                    throws NoSuchPageException, SystemException {
6884                    WikiPage wikiPage = fetchByR_N_S_Last(resourcePrimKey, nodeId, status,
6885                                    orderByComparator);
6886    
6887                    if (wikiPage != null) {
6888                            return wikiPage;
6889                    }
6890    
6891                    StringBundler msg = new StringBundler(8);
6892    
6893                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6894    
6895                    msg.append("resourcePrimKey=");
6896                    msg.append(resourcePrimKey);
6897    
6898                    msg.append(", nodeId=");
6899                    msg.append(nodeId);
6900    
6901                    msg.append(", status=");
6902                    msg.append(status);
6903    
6904                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6905    
6906                    throw new NoSuchPageException(msg.toString());
6907            }
6908    
6909            /**
6910             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6911             *
6912             * @param resourcePrimKey the resource prim key
6913             * @param nodeId the node ID
6914             * @param status the status
6915             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6916             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
6917             * @throws SystemException if a system exception occurred
6918             */
6919            @Override
6920            public WikiPage fetchByR_N_S_Last(long resourcePrimKey, long nodeId,
6921                    int status, OrderByComparator orderByComparator)
6922                    throws SystemException {
6923                    int count = countByR_N_S(resourcePrimKey, nodeId, status);
6924    
6925                    if (count == 0) {
6926                            return null;
6927                    }
6928    
6929                    List<WikiPage> list = findByR_N_S(resourcePrimKey, nodeId, status,
6930                                    count - 1, count, orderByComparator);
6931    
6932                    if (!list.isEmpty()) {
6933                            return list.get(0);
6934                    }
6935    
6936                    return null;
6937            }
6938    
6939            /**
6940             * Returns the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6941             *
6942             * @param pageId the primary key of the current wiki page
6943             * @param resourcePrimKey the resource prim key
6944             * @param nodeId the node ID
6945             * @param status the status
6946             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6947             * @return the previous, current, and next wiki page
6948             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
6949             * @throws SystemException if a system exception occurred
6950             */
6951            @Override
6952            public WikiPage[] findByR_N_S_PrevAndNext(long pageId,
6953                    long resourcePrimKey, long nodeId, int status,
6954                    OrderByComparator orderByComparator)
6955                    throws NoSuchPageException, SystemException {
6956                    WikiPage wikiPage = findByPrimaryKey(pageId);
6957    
6958                    Session session = null;
6959    
6960                    try {
6961                            session = openSession();
6962    
6963                            WikiPage[] array = new WikiPageImpl[3];
6964    
6965                            array[0] = getByR_N_S_PrevAndNext(session, wikiPage,
6966                                            resourcePrimKey, nodeId, status, orderByComparator, true);
6967    
6968                            array[1] = wikiPage;
6969    
6970                            array[2] = getByR_N_S_PrevAndNext(session, wikiPage,
6971                                            resourcePrimKey, nodeId, status, orderByComparator, false);
6972    
6973                            return array;
6974                    }
6975                    catch (Exception e) {
6976                            throw processException(e);
6977                    }
6978                    finally {
6979                            closeSession(session);
6980                    }
6981            }
6982    
6983            protected WikiPage getByR_N_S_PrevAndNext(Session session,
6984                    WikiPage wikiPage, long resourcePrimKey, long nodeId, int status,
6985                    OrderByComparator orderByComparator, boolean previous) {
6986                    StringBundler query = null;
6987    
6988                    if (orderByComparator != null) {
6989                            query = new StringBundler(6 +
6990                                            (orderByComparator.getOrderByFields().length * 6));
6991                    }
6992                    else {
6993                            query = new StringBundler(3);
6994                    }
6995    
6996                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6997    
6998                    query.append(_FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2);
6999    
7000                    query.append(_FINDER_COLUMN_R_N_S_NODEID_2);
7001    
7002                    query.append(_FINDER_COLUMN_R_N_S_STATUS_2);
7003    
7004                    if (orderByComparator != null) {
7005                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7006    
7007                            if (orderByConditionFields.length > 0) {
7008                                    query.append(WHERE_AND);
7009                            }
7010    
7011                            for (int i = 0; i < orderByConditionFields.length; i++) {
7012                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7013                                    query.append(orderByConditionFields[i]);
7014    
7015                                    if ((i + 1) < orderByConditionFields.length) {
7016                                            if (orderByComparator.isAscending() ^ previous) {
7017                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7018                                            }
7019                                            else {
7020                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7021                                            }
7022                                    }
7023                                    else {
7024                                            if (orderByComparator.isAscending() ^ previous) {
7025                                                    query.append(WHERE_GREATER_THAN);
7026                                            }
7027                                            else {
7028                                                    query.append(WHERE_LESSER_THAN);
7029                                            }
7030                                    }
7031                            }
7032    
7033                            query.append(ORDER_BY_CLAUSE);
7034    
7035                            String[] orderByFields = orderByComparator.getOrderByFields();
7036    
7037                            for (int i = 0; i < orderByFields.length; i++) {
7038                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7039                                    query.append(orderByFields[i]);
7040    
7041                                    if ((i + 1) < orderByFields.length) {
7042                                            if (orderByComparator.isAscending() ^ previous) {
7043                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7044                                            }
7045                                            else {
7046                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7047                                            }
7048                                    }
7049                                    else {
7050                                            if (orderByComparator.isAscending() ^ previous) {
7051                                                    query.append(ORDER_BY_ASC);
7052                                            }
7053                                            else {
7054                                                    query.append(ORDER_BY_DESC);
7055                                            }
7056                                    }
7057                            }
7058                    }
7059                    else {
7060                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7061                    }
7062    
7063                    String sql = query.toString();
7064    
7065                    Query q = session.createQuery(sql);
7066    
7067                    q.setFirstResult(0);
7068                    q.setMaxResults(2);
7069    
7070                    QueryPos qPos = QueryPos.getInstance(q);
7071    
7072                    qPos.add(resourcePrimKey);
7073    
7074                    qPos.add(nodeId);
7075    
7076                    qPos.add(status);
7077    
7078                    if (orderByComparator != null) {
7079                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
7080    
7081                            for (Object value : values) {
7082                                    qPos.add(value);
7083                            }
7084                    }
7085    
7086                    List<WikiPage> list = q.list();
7087    
7088                    if (list.size() == 2) {
7089                            return list.get(1);
7090                    }
7091                    else {
7092                            return null;
7093                    }
7094            }
7095    
7096            /**
7097             * Removes all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63; from the database.
7098             *
7099             * @param resourcePrimKey the resource prim key
7100             * @param nodeId the node ID
7101             * @param status the status
7102             * @throws SystemException if a system exception occurred
7103             */
7104            @Override
7105            public void removeByR_N_S(long resourcePrimKey, long nodeId, int status)
7106                    throws SystemException {
7107                    for (WikiPage wikiPage : findByR_N_S(resourcePrimKey, nodeId, status,
7108                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7109                            remove(wikiPage);
7110                    }
7111            }
7112    
7113            /**
7114             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
7115             *
7116             * @param resourcePrimKey the resource prim key
7117             * @param nodeId the node ID
7118             * @param status the status
7119             * @return the number of matching wiki pages
7120             * @throws SystemException if a system exception occurred
7121             */
7122            @Override
7123            public int countByR_N_S(long resourcePrimKey, long nodeId, int status)
7124                    throws SystemException {
7125                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N_S;
7126    
7127                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, status };
7128    
7129                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7130                                    this);
7131    
7132                    if (count == null) {
7133                            StringBundler query = new StringBundler(4);
7134    
7135                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
7136    
7137                            query.append(_FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2);
7138    
7139                            query.append(_FINDER_COLUMN_R_N_S_NODEID_2);
7140    
7141                            query.append(_FINDER_COLUMN_R_N_S_STATUS_2);
7142    
7143                            String sql = query.toString();
7144    
7145                            Session session = null;
7146    
7147                            try {
7148                                    session = openSession();
7149    
7150                                    Query q = session.createQuery(sql);
7151    
7152                                    QueryPos qPos = QueryPos.getInstance(q);
7153    
7154                                    qPos.add(resourcePrimKey);
7155    
7156                                    qPos.add(nodeId);
7157    
7158                                    qPos.add(status);
7159    
7160                                    count = (Long)q.uniqueResult();
7161    
7162                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7163                            }
7164                            catch (Exception e) {
7165                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7166    
7167                                    throw processException(e);
7168                            }
7169                            finally {
7170                                    closeSession(session);
7171                            }
7172                    }
7173    
7174                    return count.intValue();
7175            }
7176    
7177            private static final String _FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
7178            private static final String _FINDER_COLUMN_R_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
7179            private static final String _FINDER_COLUMN_R_N_S_STATUS_2 = "wikiPage.status = ?";
7180            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7181                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
7182                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H",
7183                            new String[] {
7184                                    Long.class.getName(), Long.class.getName(),
7185                                    Boolean.class.getName(),
7186                                    
7187                            Integer.class.getName(), Integer.class.getName(),
7188                                    OrderByComparator.class.getName()
7189                            });
7190            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7191                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
7192                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H",
7193                            new String[] {
7194                                    Long.class.getName(), Long.class.getName(),
7195                                    Boolean.class.getName()
7196                            },
7197                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
7198                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
7199                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
7200                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
7201                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
7202            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7203                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7204                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H",
7205                            new String[] {
7206                                    Long.class.getName(), Long.class.getName(),
7207                                    Boolean.class.getName()
7208                            });
7209    
7210            /**
7211             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
7212             *
7213             * @param groupId the group ID
7214             * @param nodeId the node ID
7215             * @param head the head
7216             * @return the matching wiki pages
7217             * @throws SystemException if a system exception occurred
7218             */
7219            @Override
7220            public List<WikiPage> findByG_N_H(long groupId, long nodeId, boolean head)
7221                    throws SystemException {
7222                    return findByG_N_H(groupId, nodeId, head, QueryUtil.ALL_POS,
7223                            QueryUtil.ALL_POS, null);
7224            }
7225    
7226            /**
7227             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
7228             *
7229             * <p>
7230             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7231             * </p>
7232             *
7233             * @param groupId the group ID
7234             * @param nodeId the node ID
7235             * @param head the head
7236             * @param start the lower bound of the range of wiki pages
7237             * @param end the upper bound of the range of wiki pages (not inclusive)
7238             * @return the range of matching wiki pages
7239             * @throws SystemException if a system exception occurred
7240             */
7241            @Override
7242            public List<WikiPage> findByG_N_H(long groupId, long nodeId, boolean head,
7243                    int start, int end) throws SystemException {
7244                    return findByG_N_H(groupId, nodeId, head, start, end, null);
7245            }
7246    
7247            /**
7248             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
7249             *
7250             * <p>
7251             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7252             * </p>
7253             *
7254             * @param groupId the group ID
7255             * @param nodeId the node ID
7256             * @param head the head
7257             * @param start the lower bound of the range of wiki pages
7258             * @param end the upper bound of the range of wiki pages (not inclusive)
7259             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7260             * @return the ordered range of matching wiki pages
7261             * @throws SystemException if a system exception occurred
7262             */
7263            @Override
7264            public List<WikiPage> findByG_N_H(long groupId, long nodeId, boolean head,
7265                    int start, int end, OrderByComparator orderByComparator)
7266                    throws SystemException {
7267                    boolean pagination = true;
7268                    FinderPath finderPath = null;
7269                    Object[] finderArgs = null;
7270    
7271                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7272                                    (orderByComparator == null)) {
7273                            pagination = false;
7274                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H;
7275                            finderArgs = new Object[] { groupId, nodeId, head };
7276                    }
7277                    else {
7278                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H;
7279                            finderArgs = new Object[] {
7280                                            groupId, nodeId, head,
7281                                            
7282                                            start, end, orderByComparator
7283                                    };
7284                    }
7285    
7286                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
7287                                    finderArgs, this);
7288    
7289                    if ((list != null) && !list.isEmpty()) {
7290                            for (WikiPage wikiPage : list) {
7291                                    if ((groupId != wikiPage.getGroupId()) ||
7292                                                    (nodeId != wikiPage.getNodeId()) ||
7293                                                    (head != wikiPage.getHead())) {
7294                                            list = null;
7295    
7296                                            break;
7297                                    }
7298                            }
7299                    }
7300    
7301                    if (list == null) {
7302                            StringBundler query = null;
7303    
7304                            if (orderByComparator != null) {
7305                                    query = new StringBundler(5 +
7306                                                    (orderByComparator.getOrderByFields().length * 3));
7307                            }
7308                            else {
7309                                    query = new StringBundler(5);
7310                            }
7311    
7312                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
7313    
7314                            query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7315    
7316                            query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7317    
7318                            query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7319    
7320                            if (orderByComparator != null) {
7321                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7322                                            orderByComparator);
7323                            }
7324                            else
7325                             if (pagination) {
7326                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7327                            }
7328    
7329                            String sql = query.toString();
7330    
7331                            Session session = null;
7332    
7333                            try {
7334                                    session = openSession();
7335    
7336                                    Query q = session.createQuery(sql);
7337    
7338                                    QueryPos qPos = QueryPos.getInstance(q);
7339    
7340                                    qPos.add(groupId);
7341    
7342                                    qPos.add(nodeId);
7343    
7344                                    qPos.add(head);
7345    
7346                                    if (!pagination) {
7347                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
7348                                                            start, end, false);
7349    
7350                                            Collections.sort(list);
7351    
7352                                            list = new UnmodifiableList<WikiPage>(list);
7353                                    }
7354                                    else {
7355                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
7356                                                            start, end);
7357                                    }
7358    
7359                                    cacheResult(list);
7360    
7361                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7362                            }
7363                            catch (Exception e) {
7364                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7365    
7366                                    throw processException(e);
7367                            }
7368                            finally {
7369                                    closeSession(session);
7370                            }
7371                    }
7372    
7373                    return list;
7374            }
7375    
7376            /**
7377             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
7378             *
7379             * @param groupId the group ID
7380             * @param nodeId the node ID
7381             * @param head the head
7382             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7383             * @return the first matching wiki page
7384             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
7385             * @throws SystemException if a system exception occurred
7386             */
7387            @Override
7388            public WikiPage findByG_N_H_First(long groupId, long nodeId, boolean head,
7389                    OrderByComparator orderByComparator)
7390                    throws NoSuchPageException, SystemException {
7391                    WikiPage wikiPage = fetchByG_N_H_First(groupId, nodeId, head,
7392                                    orderByComparator);
7393    
7394                    if (wikiPage != null) {
7395                            return wikiPage;
7396                    }
7397    
7398                    StringBundler msg = new StringBundler(8);
7399    
7400                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7401    
7402                    msg.append("groupId=");
7403                    msg.append(groupId);
7404    
7405                    msg.append(", nodeId=");
7406                    msg.append(nodeId);
7407    
7408                    msg.append(", head=");
7409                    msg.append(head);
7410    
7411                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7412    
7413                    throw new NoSuchPageException(msg.toString());
7414            }
7415    
7416            /**
7417             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
7418             *
7419             * @param groupId the group ID
7420             * @param nodeId the node ID
7421             * @param head the head
7422             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7423             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
7424             * @throws SystemException if a system exception occurred
7425             */
7426            @Override
7427            public WikiPage fetchByG_N_H_First(long groupId, long nodeId, boolean head,
7428                    OrderByComparator orderByComparator) throws SystemException {
7429                    List<WikiPage> list = findByG_N_H(groupId, nodeId, head, 0, 1,
7430                                    orderByComparator);
7431    
7432                    if (!list.isEmpty()) {
7433                            return list.get(0);
7434                    }
7435    
7436                    return null;
7437            }
7438    
7439            /**
7440             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
7441             *
7442             * @param groupId the group ID
7443             * @param nodeId the node ID
7444             * @param head the head
7445             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7446             * @return the last matching wiki page
7447             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
7448             * @throws SystemException if a system exception occurred
7449             */
7450            @Override
7451            public WikiPage findByG_N_H_Last(long groupId, long nodeId, boolean head,
7452                    OrderByComparator orderByComparator)
7453                    throws NoSuchPageException, SystemException {
7454                    WikiPage wikiPage = fetchByG_N_H_Last(groupId, nodeId, head,
7455                                    orderByComparator);
7456    
7457                    if (wikiPage != null) {
7458                            return wikiPage;
7459                    }
7460    
7461                    StringBundler msg = new StringBundler(8);
7462    
7463                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7464    
7465                    msg.append("groupId=");
7466                    msg.append(groupId);
7467    
7468                    msg.append(", nodeId=");
7469                    msg.append(nodeId);
7470    
7471                    msg.append(", head=");
7472                    msg.append(head);
7473    
7474                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7475    
7476                    throw new NoSuchPageException(msg.toString());
7477            }
7478    
7479            /**
7480             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
7481             *
7482             * @param groupId the group ID
7483             * @param nodeId the node ID
7484             * @param head the head
7485             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7486             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
7487             * @throws SystemException if a system exception occurred
7488             */
7489            @Override
7490            public WikiPage fetchByG_N_H_Last(long groupId, long nodeId, boolean head,
7491                    OrderByComparator orderByComparator) throws SystemException {
7492                    int count = countByG_N_H(groupId, nodeId, head);
7493    
7494                    if (count == 0) {
7495                            return null;
7496                    }
7497    
7498                    List<WikiPage> list = findByG_N_H(groupId, nodeId, head, count - 1,
7499                                    count, orderByComparator);
7500    
7501                    if (!list.isEmpty()) {
7502                            return list.get(0);
7503                    }
7504    
7505                    return null;
7506            }
7507    
7508            /**
7509             * Returns the wiki pages before and after the current wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
7510             *
7511             * @param pageId the primary key of the current wiki page
7512             * @param groupId the group ID
7513             * @param nodeId the node ID
7514             * @param head the head
7515             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7516             * @return the previous, current, and next wiki page
7517             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
7518             * @throws SystemException if a system exception occurred
7519             */
7520            @Override
7521            public WikiPage[] findByG_N_H_PrevAndNext(long pageId, long groupId,
7522                    long nodeId, boolean head, OrderByComparator orderByComparator)
7523                    throws NoSuchPageException, SystemException {
7524                    WikiPage wikiPage = findByPrimaryKey(pageId);
7525    
7526                    Session session = null;
7527    
7528                    try {
7529                            session = openSession();
7530    
7531                            WikiPage[] array = new WikiPageImpl[3];
7532    
7533                            array[0] = getByG_N_H_PrevAndNext(session, wikiPage, groupId,
7534                                            nodeId, head, orderByComparator, true);
7535    
7536                            array[1] = wikiPage;
7537    
7538                            array[2] = getByG_N_H_PrevAndNext(session, wikiPage, groupId,
7539                                            nodeId, head, orderByComparator, false);
7540    
7541                            return array;
7542                    }
7543                    catch (Exception e) {
7544                            throw processException(e);
7545                    }
7546                    finally {
7547                            closeSession(session);
7548                    }
7549            }
7550    
7551            protected WikiPage getByG_N_H_PrevAndNext(Session session,
7552                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
7553                    OrderByComparator orderByComparator, boolean previous) {
7554                    StringBundler query = null;
7555    
7556                    if (orderByComparator != null) {
7557                            query = new StringBundler(6 +
7558                                            (orderByComparator.getOrderByFields().length * 6));
7559                    }
7560                    else {
7561                            query = new StringBundler(3);
7562                    }
7563    
7564                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
7565    
7566                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7567    
7568                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7569    
7570                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7571    
7572                    if (orderByComparator != null) {
7573                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7574    
7575                            if (orderByConditionFields.length > 0) {
7576                                    query.append(WHERE_AND);
7577                            }
7578    
7579                            for (int i = 0; i < orderByConditionFields.length; i++) {
7580                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7581                                    query.append(orderByConditionFields[i]);
7582    
7583                                    if ((i + 1) < orderByConditionFields.length) {
7584                                            if (orderByComparator.isAscending() ^ previous) {
7585                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7586                                            }
7587                                            else {
7588                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7589                                            }
7590                                    }
7591                                    else {
7592                                            if (orderByComparator.isAscending() ^ previous) {
7593                                                    query.append(WHERE_GREATER_THAN);
7594                                            }
7595                                            else {
7596                                                    query.append(WHERE_LESSER_THAN);
7597                                            }
7598                                    }
7599                            }
7600    
7601                            query.append(ORDER_BY_CLAUSE);
7602    
7603                            String[] orderByFields = orderByComparator.getOrderByFields();
7604    
7605                            for (int i = 0; i < orderByFields.length; i++) {
7606                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7607                                    query.append(orderByFields[i]);
7608    
7609                                    if ((i + 1) < orderByFields.length) {
7610                                            if (orderByComparator.isAscending() ^ previous) {
7611                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7612                                            }
7613                                            else {
7614                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7615                                            }
7616                                    }
7617                                    else {
7618                                            if (orderByComparator.isAscending() ^ previous) {
7619                                                    query.append(ORDER_BY_ASC);
7620                                            }
7621                                            else {
7622                                                    query.append(ORDER_BY_DESC);
7623                                            }
7624                                    }
7625                            }
7626                    }
7627                    else {
7628                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7629                    }
7630    
7631                    String sql = query.toString();
7632    
7633                    Query q = session.createQuery(sql);
7634    
7635                    q.setFirstResult(0);
7636                    q.setMaxResults(2);
7637    
7638                    QueryPos qPos = QueryPos.getInstance(q);
7639    
7640                    qPos.add(groupId);
7641    
7642                    qPos.add(nodeId);
7643    
7644                    qPos.add(head);
7645    
7646                    if (orderByComparator != null) {
7647                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
7648    
7649                            for (Object value : values) {
7650                                    qPos.add(value);
7651                            }
7652                    }
7653    
7654                    List<WikiPage> list = q.list();
7655    
7656                    if (list.size() == 2) {
7657                            return list.get(1);
7658                    }
7659                    else {
7660                            return null;
7661                    }
7662            }
7663    
7664            /**
7665             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63;.
7666             *
7667             * @param groupId the group ID
7668             * @param nodeId the node ID
7669             * @param head the head
7670             * @return the matching wiki pages that the user has permission to view
7671             * @throws SystemException if a system exception occurred
7672             */
7673            @Override
7674            public List<WikiPage> filterFindByG_N_H(long groupId, long nodeId,
7675                    boolean head) throws SystemException {
7676                    return filterFindByG_N_H(groupId, nodeId, head, QueryUtil.ALL_POS,
7677                            QueryUtil.ALL_POS, null);
7678            }
7679    
7680            /**
7681             * Returns a range of all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63;.
7682             *
7683             * <p>
7684             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7685             * </p>
7686             *
7687             * @param groupId the group ID
7688             * @param nodeId the node ID
7689             * @param head the head
7690             * @param start the lower bound of the range of wiki pages
7691             * @param end the upper bound of the range of wiki pages (not inclusive)
7692             * @return the range of matching wiki pages that the user has permission to view
7693             * @throws SystemException if a system exception occurred
7694             */
7695            @Override
7696            public List<WikiPage> filterFindByG_N_H(long groupId, long nodeId,
7697                    boolean head, int start, int end) throws SystemException {
7698                    return filterFindByG_N_H(groupId, nodeId, head, start, end, null);
7699            }
7700    
7701            /**
7702             * 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;.
7703             *
7704             * <p>
7705             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7706             * </p>
7707             *
7708             * @param groupId the group ID
7709             * @param nodeId the node ID
7710             * @param head the head
7711             * @param start the lower bound of the range of wiki pages
7712             * @param end the upper bound of the range of wiki pages (not inclusive)
7713             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7714             * @return the ordered range of matching wiki pages that the user has permission to view
7715             * @throws SystemException if a system exception occurred
7716             */
7717            @Override
7718            public List<WikiPage> filterFindByG_N_H(long groupId, long nodeId,
7719                    boolean head, int start, int end, OrderByComparator orderByComparator)
7720                    throws SystemException {
7721                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7722                            return findByG_N_H(groupId, nodeId, head, start, end,
7723                                    orderByComparator);
7724                    }
7725    
7726                    StringBundler query = null;
7727    
7728                    if (orderByComparator != null) {
7729                            query = new StringBundler(5 +
7730                                            (orderByComparator.getOrderByFields().length * 3));
7731                    }
7732                    else {
7733                            query = new StringBundler(5);
7734                    }
7735    
7736                    if (getDB().isSupportsInlineDistinct()) {
7737                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
7738                    }
7739                    else {
7740                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
7741                    }
7742    
7743                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7744    
7745                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7746    
7747                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7748    
7749                    if (!getDB().isSupportsInlineDistinct()) {
7750                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
7751                    }
7752    
7753                    if (orderByComparator != null) {
7754                            if (getDB().isSupportsInlineDistinct()) {
7755                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7756                                            orderByComparator, true);
7757                            }
7758                            else {
7759                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7760                                            orderByComparator, true);
7761                            }
7762                    }
7763                    else {
7764                            if (getDB().isSupportsInlineDistinct()) {
7765                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7766                            }
7767                            else {
7768                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
7769                            }
7770                    }
7771    
7772                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7773                                    WikiPage.class.getName(),
7774                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7775    
7776                    Session session = null;
7777    
7778                    try {
7779                            session = openSession();
7780    
7781                            SQLQuery q = session.createSQLQuery(sql);
7782    
7783                            if (getDB().isSupportsInlineDistinct()) {
7784                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
7785                            }
7786                            else {
7787                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
7788                            }
7789    
7790                            QueryPos qPos = QueryPos.getInstance(q);
7791    
7792                            qPos.add(groupId);
7793    
7794                            qPos.add(nodeId);
7795    
7796                            qPos.add(head);
7797    
7798                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
7799                    }
7800                    catch (Exception e) {
7801                            throw processException(e);
7802                    }
7803                    finally {
7804                            closeSession(session);
7805                    }
7806            }
7807    
7808            /**
7809             * 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;.
7810             *
7811             * @param pageId the primary key of the current wiki page
7812             * @param groupId the group ID
7813             * @param nodeId the node ID
7814             * @param head the head
7815             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7816             * @return the previous, current, and next wiki page
7817             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
7818             * @throws SystemException if a system exception occurred
7819             */
7820            @Override
7821            public WikiPage[] filterFindByG_N_H_PrevAndNext(long pageId, long groupId,
7822                    long nodeId, boolean head, OrderByComparator orderByComparator)
7823                    throws NoSuchPageException, SystemException {
7824                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7825                            return findByG_N_H_PrevAndNext(pageId, groupId, nodeId, head,
7826                                    orderByComparator);
7827                    }
7828    
7829                    WikiPage wikiPage = findByPrimaryKey(pageId);
7830    
7831                    Session session = null;
7832    
7833                    try {
7834                            session = openSession();
7835    
7836                            WikiPage[] array = new WikiPageImpl[3];
7837    
7838                            array[0] = filterGetByG_N_H_PrevAndNext(session, wikiPage, groupId,
7839                                            nodeId, head, orderByComparator, true);
7840    
7841                            array[1] = wikiPage;
7842    
7843                            array[2] = filterGetByG_N_H_PrevAndNext(session, wikiPage, groupId,
7844                                            nodeId, head, orderByComparator, false);
7845    
7846                            return array;
7847                    }
7848                    catch (Exception e) {
7849                            throw processException(e);
7850                    }
7851                    finally {
7852                            closeSession(session);
7853                    }
7854            }
7855    
7856            protected WikiPage filterGetByG_N_H_PrevAndNext(Session session,
7857                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
7858                    OrderByComparator orderByComparator, boolean previous) {
7859                    StringBundler query = null;
7860    
7861                    if (orderByComparator != null) {
7862                            query = new StringBundler(6 +
7863                                            (orderByComparator.getOrderByFields().length * 6));
7864                    }
7865                    else {
7866                            query = new StringBundler(3);
7867                    }
7868    
7869                    if (getDB().isSupportsInlineDistinct()) {
7870                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
7871                    }
7872                    else {
7873                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
7874                    }
7875    
7876                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7877    
7878                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7879    
7880                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7881    
7882                    if (!getDB().isSupportsInlineDistinct()) {
7883                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
7884                    }
7885    
7886                    if (orderByComparator != null) {
7887                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7888    
7889                            if (orderByConditionFields.length > 0) {
7890                                    query.append(WHERE_AND);
7891                            }
7892    
7893                            for (int i = 0; i < orderByConditionFields.length; i++) {
7894                                    if (getDB().isSupportsInlineDistinct()) {
7895                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7896                                    }
7897                                    else {
7898                                            query.append(_ORDER_BY_ENTITY_TABLE);
7899                                    }
7900    
7901                                    query.append(orderByConditionFields[i]);
7902    
7903                                    if ((i + 1) < orderByConditionFields.length) {
7904                                            if (orderByComparator.isAscending() ^ previous) {
7905                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7906                                            }
7907                                            else {
7908                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7909                                            }
7910                                    }
7911                                    else {
7912                                            if (orderByComparator.isAscending() ^ previous) {
7913                                                    query.append(WHERE_GREATER_THAN);
7914                                            }
7915                                            else {
7916                                                    query.append(WHERE_LESSER_THAN);
7917                                            }
7918                                    }
7919                            }
7920    
7921                            query.append(ORDER_BY_CLAUSE);
7922    
7923                            String[] orderByFields = orderByComparator.getOrderByFields();
7924    
7925                            for (int i = 0; i < orderByFields.length; i++) {
7926                                    if (getDB().isSupportsInlineDistinct()) {
7927                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7928                                    }
7929                                    else {
7930                                            query.append(_ORDER_BY_ENTITY_TABLE);
7931                                    }
7932    
7933                                    query.append(orderByFields[i]);
7934    
7935                                    if ((i + 1) < orderByFields.length) {
7936                                            if (orderByComparator.isAscending() ^ previous) {
7937                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7938                                            }
7939                                            else {
7940                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7941                                            }
7942                                    }
7943                                    else {
7944                                            if (orderByComparator.isAscending() ^ previous) {
7945                                                    query.append(ORDER_BY_ASC);
7946                                            }
7947                                            else {
7948                                                    query.append(ORDER_BY_DESC);
7949                                            }
7950                                    }
7951                            }
7952                    }
7953                    else {
7954                            if (getDB().isSupportsInlineDistinct()) {
7955                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7956                            }
7957                            else {
7958                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
7959                            }
7960                    }
7961    
7962                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7963                                    WikiPage.class.getName(),
7964                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7965    
7966                    SQLQuery q = session.createSQLQuery(sql);
7967    
7968                    q.setFirstResult(0);
7969                    q.setMaxResults(2);
7970    
7971                    if (getDB().isSupportsInlineDistinct()) {
7972                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
7973                    }
7974                    else {
7975                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
7976                    }
7977    
7978                    QueryPos qPos = QueryPos.getInstance(q);
7979    
7980                    qPos.add(groupId);
7981    
7982                    qPos.add(nodeId);
7983    
7984                    qPos.add(head);
7985    
7986                    if (orderByComparator != null) {
7987                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
7988    
7989                            for (Object value : values) {
7990                                    qPos.add(value);
7991                            }
7992                    }
7993    
7994                    List<WikiPage> list = q.list();
7995    
7996                    if (list.size() == 2) {
7997                            return list.get(1);
7998                    }
7999                    else {
8000                            return null;
8001                    }
8002            }
8003    
8004            /**
8005             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; from the database.
8006             *
8007             * @param groupId the group ID
8008             * @param nodeId the node ID
8009             * @param head the head
8010             * @throws SystemException if a system exception occurred
8011             */
8012            @Override
8013            public void removeByG_N_H(long groupId, long nodeId, boolean head)
8014                    throws SystemException {
8015                    for (WikiPage wikiPage : findByG_N_H(groupId, nodeId, head,
8016                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8017                            remove(wikiPage);
8018                    }
8019            }
8020    
8021            /**
8022             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
8023             *
8024             * @param groupId the group ID
8025             * @param nodeId the node ID
8026             * @param head the head
8027             * @return the number of matching wiki pages
8028             * @throws SystemException if a system exception occurred
8029             */
8030            @Override
8031            public int countByG_N_H(long groupId, long nodeId, boolean head)
8032                    throws SystemException {
8033                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H;
8034    
8035                    Object[] finderArgs = new Object[] { groupId, nodeId, head };
8036    
8037                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8038                                    this);
8039    
8040                    if (count == null) {
8041                            StringBundler query = new StringBundler(4);
8042    
8043                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8044    
8045                            query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
8046    
8047                            query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
8048    
8049                            query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
8050    
8051                            String sql = query.toString();
8052    
8053                            Session session = null;
8054    
8055                            try {
8056                                    session = openSession();
8057    
8058                                    Query q = session.createQuery(sql);
8059    
8060                                    QueryPos qPos = QueryPos.getInstance(q);
8061    
8062                                    qPos.add(groupId);
8063    
8064                                    qPos.add(nodeId);
8065    
8066                                    qPos.add(head);
8067    
8068                                    count = (Long)q.uniqueResult();
8069    
8070                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8071                            }
8072                            catch (Exception e) {
8073                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8074    
8075                                    throw processException(e);
8076                            }
8077                            finally {
8078                                    closeSession(session);
8079                            }
8080                    }
8081    
8082                    return count.intValue();
8083            }
8084    
8085            /**
8086             * Returns the number of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63;.
8087             *
8088             * @param groupId the group ID
8089             * @param nodeId the node ID
8090             * @param head the head
8091             * @return the number of matching wiki pages that the user has permission to view
8092             * @throws SystemException if a system exception occurred
8093             */
8094            @Override
8095            public int filterCountByG_N_H(long groupId, long nodeId, boolean head)
8096                    throws SystemException {
8097                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8098                            return countByG_N_H(groupId, nodeId, head);
8099                    }
8100    
8101                    StringBundler query = new StringBundler(4);
8102    
8103                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
8104    
8105                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
8106    
8107                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
8108    
8109                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
8110    
8111                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8112                                    WikiPage.class.getName(),
8113                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8114    
8115                    Session session = null;
8116    
8117                    try {
8118                            session = openSession();
8119    
8120                            SQLQuery q = session.createSQLQuery(sql);
8121    
8122                            q.addScalar(COUNT_COLUMN_NAME,
8123                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8124    
8125                            QueryPos qPos = QueryPos.getInstance(q);
8126    
8127                            qPos.add(groupId);
8128    
8129                            qPos.add(nodeId);
8130    
8131                            qPos.add(head);
8132    
8133                            Long count = (Long)q.uniqueResult();
8134    
8135                            return count.intValue();
8136                    }
8137                    catch (Exception e) {
8138                            throw processException(e);
8139                    }
8140                    finally {
8141                            closeSession(session);
8142                    }
8143            }
8144    
8145            private static final String _FINDER_COLUMN_G_N_H_GROUPID_2 = "wikiPage.groupId = ? AND ";
8146            private static final String _FINDER_COLUMN_G_N_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
8147            private static final String _FINDER_COLUMN_G_N_H_HEAD_2 = "wikiPage.head = ?";
8148            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
8149                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
8150                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_S",
8151                            new String[] {
8152                                    Long.class.getName(), Long.class.getName(),
8153                                    Integer.class.getName(),
8154                                    
8155                            Integer.class.getName(), Integer.class.getName(),
8156                                    OrderByComparator.class.getName()
8157                            });
8158            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
8159                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
8160                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_S",
8161                            new String[] {
8162                                    Long.class.getName(), Long.class.getName(),
8163                                    Integer.class.getName()
8164                            },
8165                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
8166                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
8167                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
8168                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
8169                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
8170            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
8171                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8172                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_S",
8173                            new String[] {
8174                                    Long.class.getName(), Long.class.getName(),
8175                                    Integer.class.getName()
8176                            });
8177    
8178            /**
8179             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
8180             *
8181             * @param groupId the group ID
8182             * @param nodeId the node ID
8183             * @param status the status
8184             * @return the matching wiki pages
8185             * @throws SystemException if a system exception occurred
8186             */
8187            @Override
8188            public List<WikiPage> findByG_N_S(long groupId, long nodeId, int status)
8189                    throws SystemException {
8190                    return findByG_N_S(groupId, nodeId, status, QueryUtil.ALL_POS,
8191                            QueryUtil.ALL_POS, null);
8192            }
8193    
8194            /**
8195             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
8196             *
8197             * <p>
8198             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8199             * </p>
8200             *
8201             * @param groupId the group ID
8202             * @param nodeId the node ID
8203             * @param status the status
8204             * @param start the lower bound of the range of wiki pages
8205             * @param end the upper bound of the range of wiki pages (not inclusive)
8206             * @return the range of matching wiki pages
8207             * @throws SystemException if a system exception occurred
8208             */
8209            @Override
8210            public List<WikiPage> findByG_N_S(long groupId, long nodeId, int status,
8211                    int start, int end) throws SystemException {
8212                    return findByG_N_S(groupId, nodeId, status, start, end, null);
8213            }
8214    
8215            /**
8216             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
8217             *
8218             * <p>
8219             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8220             * </p>
8221             *
8222             * @param groupId the group ID
8223             * @param nodeId the node ID
8224             * @param status the status
8225             * @param start the lower bound of the range of wiki pages
8226             * @param end the upper bound of the range of wiki pages (not inclusive)
8227             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8228             * @return the ordered range of matching wiki pages
8229             * @throws SystemException if a system exception occurred
8230             */
8231            @Override
8232            public List<WikiPage> findByG_N_S(long groupId, long nodeId, int status,
8233                    int start, int end, OrderByComparator orderByComparator)
8234                    throws SystemException {
8235                    boolean pagination = true;
8236                    FinderPath finderPath = null;
8237                    Object[] finderArgs = null;
8238    
8239                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8240                                    (orderByComparator == null)) {
8241                            pagination = false;
8242                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S;
8243                            finderArgs = new Object[] { groupId, nodeId, status };
8244                    }
8245                    else {
8246                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_S;
8247                            finderArgs = new Object[] {
8248                                            groupId, nodeId, status,
8249                                            
8250                                            start, end, orderByComparator
8251                                    };
8252                    }
8253    
8254                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
8255                                    finderArgs, this);
8256    
8257                    if ((list != null) && !list.isEmpty()) {
8258                            for (WikiPage wikiPage : list) {
8259                                    if ((groupId != wikiPage.getGroupId()) ||
8260                                                    (nodeId != wikiPage.getNodeId()) ||
8261                                                    (status != wikiPage.getStatus())) {
8262                                            list = null;
8263    
8264                                            break;
8265                                    }
8266                            }
8267                    }
8268    
8269                    if (list == null) {
8270                            StringBundler query = null;
8271    
8272                            if (orderByComparator != null) {
8273                                    query = new StringBundler(5 +
8274                                                    (orderByComparator.getOrderByFields().length * 3));
8275                            }
8276                            else {
8277                                    query = new StringBundler(5);
8278                            }
8279    
8280                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
8281    
8282                            query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8283    
8284                            query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8285    
8286                            query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8287    
8288                            if (orderByComparator != null) {
8289                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8290                                            orderByComparator);
8291                            }
8292                            else
8293                             if (pagination) {
8294                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8295                            }
8296    
8297                            String sql = query.toString();
8298    
8299                            Session session = null;
8300    
8301                            try {
8302                                    session = openSession();
8303    
8304                                    Query q = session.createQuery(sql);
8305    
8306                                    QueryPos qPos = QueryPos.getInstance(q);
8307    
8308                                    qPos.add(groupId);
8309    
8310                                    qPos.add(nodeId);
8311    
8312                                    qPos.add(status);
8313    
8314                                    if (!pagination) {
8315                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
8316                                                            start, end, false);
8317    
8318                                            Collections.sort(list);
8319    
8320                                            list = new UnmodifiableList<WikiPage>(list);
8321                                    }
8322                                    else {
8323                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
8324                                                            start, end);
8325                                    }
8326    
8327                                    cacheResult(list);
8328    
8329                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8330                            }
8331                            catch (Exception e) {
8332                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8333    
8334                                    throw processException(e);
8335                            }
8336                            finally {
8337                                    closeSession(session);
8338                            }
8339                    }
8340    
8341                    return list;
8342            }
8343    
8344            /**
8345             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
8346             *
8347             * @param groupId the group ID
8348             * @param nodeId the node ID
8349             * @param status the status
8350             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8351             * @return the first matching wiki page
8352             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
8353             * @throws SystemException if a system exception occurred
8354             */
8355            @Override
8356            public WikiPage findByG_N_S_First(long groupId, long nodeId, int status,
8357                    OrderByComparator orderByComparator)
8358                    throws NoSuchPageException, SystemException {
8359                    WikiPage wikiPage = fetchByG_N_S_First(groupId, nodeId, status,
8360                                    orderByComparator);
8361    
8362                    if (wikiPage != null) {
8363                            return wikiPage;
8364                    }
8365    
8366                    StringBundler msg = new StringBundler(8);
8367    
8368                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8369    
8370                    msg.append("groupId=");
8371                    msg.append(groupId);
8372    
8373                    msg.append(", nodeId=");
8374                    msg.append(nodeId);
8375    
8376                    msg.append(", status=");
8377                    msg.append(status);
8378    
8379                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8380    
8381                    throw new NoSuchPageException(msg.toString());
8382            }
8383    
8384            /**
8385             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
8386             *
8387             * @param groupId the group ID
8388             * @param nodeId the node ID
8389             * @param status the status
8390             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8391             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
8392             * @throws SystemException if a system exception occurred
8393             */
8394            @Override
8395            public WikiPage fetchByG_N_S_First(long groupId, long nodeId, int status,
8396                    OrderByComparator orderByComparator) throws SystemException {
8397                    List<WikiPage> list = findByG_N_S(groupId, nodeId, status, 0, 1,
8398                                    orderByComparator);
8399    
8400                    if (!list.isEmpty()) {
8401                            return list.get(0);
8402                    }
8403    
8404                    return null;
8405            }
8406    
8407            /**
8408             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
8409             *
8410             * @param groupId the group ID
8411             * @param nodeId the node ID
8412             * @param status the status
8413             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8414             * @return the last matching wiki page
8415             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
8416             * @throws SystemException if a system exception occurred
8417             */
8418            @Override
8419            public WikiPage findByG_N_S_Last(long groupId, long nodeId, int status,
8420                    OrderByComparator orderByComparator)
8421                    throws NoSuchPageException, SystemException {
8422                    WikiPage wikiPage = fetchByG_N_S_Last(groupId, nodeId, status,
8423                                    orderByComparator);
8424    
8425                    if (wikiPage != null) {
8426                            return wikiPage;
8427                    }
8428    
8429                    StringBundler msg = new StringBundler(8);
8430    
8431                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8432    
8433                    msg.append("groupId=");
8434                    msg.append(groupId);
8435    
8436                    msg.append(", nodeId=");
8437                    msg.append(nodeId);
8438    
8439                    msg.append(", status=");
8440                    msg.append(status);
8441    
8442                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8443    
8444                    throw new NoSuchPageException(msg.toString());
8445            }
8446    
8447            /**
8448             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
8449             *
8450             * @param groupId the group ID
8451             * @param nodeId the node ID
8452             * @param status the status
8453             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8454             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
8455             * @throws SystemException if a system exception occurred
8456             */
8457            @Override
8458            public WikiPage fetchByG_N_S_Last(long groupId, long nodeId, int status,
8459                    OrderByComparator orderByComparator) throws SystemException {
8460                    int count = countByG_N_S(groupId, nodeId, status);
8461    
8462                    if (count == 0) {
8463                            return null;
8464                    }
8465    
8466                    List<WikiPage> list = findByG_N_S(groupId, nodeId, status, count - 1,
8467                                    count, orderByComparator);
8468    
8469                    if (!list.isEmpty()) {
8470                            return list.get(0);
8471                    }
8472    
8473                    return null;
8474            }
8475    
8476            /**
8477             * Returns the wiki pages before and after the current wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
8478             *
8479             * @param pageId the primary key of the current wiki page
8480             * @param groupId the group ID
8481             * @param nodeId the node ID
8482             * @param status the status
8483             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8484             * @return the previous, current, and next wiki page
8485             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
8486             * @throws SystemException if a system exception occurred
8487             */
8488            @Override
8489            public WikiPage[] findByG_N_S_PrevAndNext(long pageId, long groupId,
8490                    long nodeId, int status, OrderByComparator orderByComparator)
8491                    throws NoSuchPageException, SystemException {
8492                    WikiPage wikiPage = findByPrimaryKey(pageId);
8493    
8494                    Session session = null;
8495    
8496                    try {
8497                            session = openSession();
8498    
8499                            WikiPage[] array = new WikiPageImpl[3];
8500    
8501                            array[0] = getByG_N_S_PrevAndNext(session, wikiPage, groupId,
8502                                            nodeId, status, orderByComparator, true);
8503    
8504                            array[1] = wikiPage;
8505    
8506                            array[2] = getByG_N_S_PrevAndNext(session, wikiPage, groupId,
8507                                            nodeId, status, orderByComparator, false);
8508    
8509                            return array;
8510                    }
8511                    catch (Exception e) {
8512                            throw processException(e);
8513                    }
8514                    finally {
8515                            closeSession(session);
8516                    }
8517            }
8518    
8519            protected WikiPage getByG_N_S_PrevAndNext(Session session,
8520                    WikiPage wikiPage, long groupId, long nodeId, int status,
8521                    OrderByComparator orderByComparator, boolean previous) {
8522                    StringBundler query = null;
8523    
8524                    if (orderByComparator != null) {
8525                            query = new StringBundler(6 +
8526                                            (orderByComparator.getOrderByFields().length * 6));
8527                    }
8528                    else {
8529                            query = new StringBundler(3);
8530                    }
8531    
8532                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
8533    
8534                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8535    
8536                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8537    
8538                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8539    
8540                    if (orderByComparator != null) {
8541                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8542    
8543                            if (orderByConditionFields.length > 0) {
8544                                    query.append(WHERE_AND);
8545                            }
8546    
8547                            for (int i = 0; i < orderByConditionFields.length; i++) {
8548                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8549                                    query.append(orderByConditionFields[i]);
8550    
8551                                    if ((i + 1) < orderByConditionFields.length) {
8552                                            if (orderByComparator.isAscending() ^ previous) {
8553                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8554                                            }
8555                                            else {
8556                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8557                                            }
8558                                    }
8559                                    else {
8560                                            if (orderByComparator.isAscending() ^ previous) {
8561                                                    query.append(WHERE_GREATER_THAN);
8562                                            }
8563                                            else {
8564                                                    query.append(WHERE_LESSER_THAN);
8565                                            }
8566                                    }
8567                            }
8568    
8569                            query.append(ORDER_BY_CLAUSE);
8570    
8571                            String[] orderByFields = orderByComparator.getOrderByFields();
8572    
8573                            for (int i = 0; i < orderByFields.length; i++) {
8574                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8575                                    query.append(orderByFields[i]);
8576    
8577                                    if ((i + 1) < orderByFields.length) {
8578                                            if (orderByComparator.isAscending() ^ previous) {
8579                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8580                                            }
8581                                            else {
8582                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8583                                            }
8584                                    }
8585                                    else {
8586                                            if (orderByComparator.isAscending() ^ previous) {
8587                                                    query.append(ORDER_BY_ASC);
8588                                            }
8589                                            else {
8590                                                    query.append(ORDER_BY_DESC);
8591                                            }
8592                                    }
8593                            }
8594                    }
8595                    else {
8596                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8597                    }
8598    
8599                    String sql = query.toString();
8600    
8601                    Query q = session.createQuery(sql);
8602    
8603                    q.setFirstResult(0);
8604                    q.setMaxResults(2);
8605    
8606                    QueryPos qPos = QueryPos.getInstance(q);
8607    
8608                    qPos.add(groupId);
8609    
8610                    qPos.add(nodeId);
8611    
8612                    qPos.add(status);
8613    
8614                    if (orderByComparator != null) {
8615                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
8616    
8617                            for (Object value : values) {
8618                                    qPos.add(value);
8619                            }
8620                    }
8621    
8622                    List<WikiPage> list = q.list();
8623    
8624                    if (list.size() == 2) {
8625                            return list.get(1);
8626                    }
8627                    else {
8628                            return null;
8629                    }
8630            }
8631    
8632            /**
8633             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and status = &#63;.
8634             *
8635             * @param groupId the group ID
8636             * @param nodeId the node ID
8637             * @param status the status
8638             * @return the matching wiki pages that the user has permission to view
8639             * @throws SystemException if a system exception occurred
8640             */
8641            @Override
8642            public List<WikiPage> filterFindByG_N_S(long groupId, long nodeId,
8643                    int status) throws SystemException {
8644                    return filterFindByG_N_S(groupId, nodeId, status, QueryUtil.ALL_POS,
8645                            QueryUtil.ALL_POS, null);
8646            }
8647    
8648            /**
8649             * Returns a range of all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and status = &#63;.
8650             *
8651             * <p>
8652             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8653             * </p>
8654             *
8655             * @param groupId the group ID
8656             * @param nodeId the node ID
8657             * @param status the status
8658             * @param start the lower bound of the range of wiki pages
8659             * @param end the upper bound of the range of wiki pages (not inclusive)
8660             * @return the range of matching wiki pages that the user has permission to view
8661             * @throws SystemException if a system exception occurred
8662             */
8663            @Override
8664            public List<WikiPage> filterFindByG_N_S(long groupId, long nodeId,
8665                    int status, int start, int end) throws SystemException {
8666                    return filterFindByG_N_S(groupId, nodeId, status, start, end, null);
8667            }
8668    
8669            /**
8670             * 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;.
8671             *
8672             * <p>
8673             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8674             * </p>
8675             *
8676             * @param groupId the group ID
8677             * @param nodeId the node ID
8678             * @param status the status
8679             * @param start the lower bound of the range of wiki pages
8680             * @param end the upper bound of the range of wiki pages (not inclusive)
8681             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8682             * @return the ordered range of matching wiki pages that the user has permission to view
8683             * @throws SystemException if a system exception occurred
8684             */
8685            @Override
8686            public List<WikiPage> filterFindByG_N_S(long groupId, long nodeId,
8687                    int status, int start, int end, OrderByComparator orderByComparator)
8688                    throws SystemException {
8689                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8690                            return findByG_N_S(groupId, nodeId, status, start, end,
8691                                    orderByComparator);
8692                    }
8693    
8694                    StringBundler query = null;
8695    
8696                    if (orderByComparator != null) {
8697                            query = new StringBundler(5 +
8698                                            (orderByComparator.getOrderByFields().length * 3));
8699                    }
8700                    else {
8701                            query = new StringBundler(5);
8702                    }
8703    
8704                    if (getDB().isSupportsInlineDistinct()) {
8705                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
8706                    }
8707                    else {
8708                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
8709                    }
8710    
8711                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8712    
8713                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8714    
8715                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8716    
8717                    if (!getDB().isSupportsInlineDistinct()) {
8718                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
8719                    }
8720    
8721                    if (orderByComparator != null) {
8722                            if (getDB().isSupportsInlineDistinct()) {
8723                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8724                                            orderByComparator, true);
8725                            }
8726                            else {
8727                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8728                                            orderByComparator, true);
8729                            }
8730                    }
8731                    else {
8732                            if (getDB().isSupportsInlineDistinct()) {
8733                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8734                            }
8735                            else {
8736                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
8737                            }
8738                    }
8739    
8740                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8741                                    WikiPage.class.getName(),
8742                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8743    
8744                    Session session = null;
8745    
8746                    try {
8747                            session = openSession();
8748    
8749                            SQLQuery q = session.createSQLQuery(sql);
8750    
8751                            if (getDB().isSupportsInlineDistinct()) {
8752                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
8753                            }
8754                            else {
8755                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
8756                            }
8757    
8758                            QueryPos qPos = QueryPos.getInstance(q);
8759    
8760                            qPos.add(groupId);
8761    
8762                            qPos.add(nodeId);
8763    
8764                            qPos.add(status);
8765    
8766                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
8767                    }
8768                    catch (Exception e) {
8769                            throw processException(e);
8770                    }
8771                    finally {
8772                            closeSession(session);
8773                    }
8774            }
8775    
8776            /**
8777             * 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;.
8778             *
8779             * @param pageId the primary key of the current wiki page
8780             * @param groupId the group ID
8781             * @param nodeId the node ID
8782             * @param status the status
8783             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8784             * @return the previous, current, and next wiki page
8785             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
8786             * @throws SystemException if a system exception occurred
8787             */
8788            @Override
8789            public WikiPage[] filterFindByG_N_S_PrevAndNext(long pageId, long groupId,
8790                    long nodeId, int status, OrderByComparator orderByComparator)
8791                    throws NoSuchPageException, SystemException {
8792                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8793                            return findByG_N_S_PrevAndNext(pageId, groupId, nodeId, status,
8794                                    orderByComparator);
8795                    }
8796    
8797                    WikiPage wikiPage = findByPrimaryKey(pageId);
8798    
8799                    Session session = null;
8800    
8801                    try {
8802                            session = openSession();
8803    
8804                            WikiPage[] array = new WikiPageImpl[3];
8805    
8806                            array[0] = filterGetByG_N_S_PrevAndNext(session, wikiPage, groupId,
8807                                            nodeId, status, orderByComparator, true);
8808    
8809                            array[1] = wikiPage;
8810    
8811                            array[2] = filterGetByG_N_S_PrevAndNext(session, wikiPage, groupId,
8812                                            nodeId, status, orderByComparator, false);
8813    
8814                            return array;
8815                    }
8816                    catch (Exception e) {
8817                            throw processException(e);
8818                    }
8819                    finally {
8820                            closeSession(session);
8821                    }
8822            }
8823    
8824            protected WikiPage filterGetByG_N_S_PrevAndNext(Session session,
8825                    WikiPage wikiPage, long groupId, long nodeId, int status,
8826                    OrderByComparator orderByComparator, boolean previous) {
8827                    StringBundler query = null;
8828    
8829                    if (orderByComparator != null) {
8830                            query = new StringBundler(6 +
8831                                            (orderByComparator.getOrderByFields().length * 6));
8832                    }
8833                    else {
8834                            query = new StringBundler(3);
8835                    }
8836    
8837                    if (getDB().isSupportsInlineDistinct()) {
8838                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
8839                    }
8840                    else {
8841                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
8842                    }
8843    
8844                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8845    
8846                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8847    
8848                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8849    
8850                    if (!getDB().isSupportsInlineDistinct()) {
8851                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
8852                    }
8853    
8854                    if (orderByComparator != null) {
8855                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8856    
8857                            if (orderByConditionFields.length > 0) {
8858                                    query.append(WHERE_AND);
8859                            }
8860    
8861                            for (int i = 0; i < orderByConditionFields.length; i++) {
8862                                    if (getDB().isSupportsInlineDistinct()) {
8863                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8864                                    }
8865                                    else {
8866                                            query.append(_ORDER_BY_ENTITY_TABLE);
8867                                    }
8868    
8869                                    query.append(orderByConditionFields[i]);
8870    
8871                                    if ((i + 1) < orderByConditionFields.length) {
8872                                            if (orderByComparator.isAscending() ^ previous) {
8873                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8874                                            }
8875                                            else {
8876                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8877                                            }
8878                                    }
8879                                    else {
8880                                            if (orderByComparator.isAscending() ^ previous) {
8881                                                    query.append(WHERE_GREATER_THAN);
8882                                            }
8883                                            else {
8884                                                    query.append(WHERE_LESSER_THAN);
8885                                            }
8886                                    }
8887                            }
8888    
8889                            query.append(ORDER_BY_CLAUSE);
8890    
8891                            String[] orderByFields = orderByComparator.getOrderByFields();
8892    
8893                            for (int i = 0; i < orderByFields.length; i++) {
8894                                    if (getDB().isSupportsInlineDistinct()) {
8895                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8896                                    }
8897                                    else {
8898                                            query.append(_ORDER_BY_ENTITY_TABLE);
8899                                    }
8900    
8901                                    query.append(orderByFields[i]);
8902    
8903                                    if ((i + 1) < orderByFields.length) {
8904                                            if (orderByComparator.isAscending() ^ previous) {
8905                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8906                                            }
8907                                            else {
8908                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8909                                            }
8910                                    }
8911                                    else {
8912                                            if (orderByComparator.isAscending() ^ previous) {
8913                                                    query.append(ORDER_BY_ASC);
8914                                            }
8915                                            else {
8916                                                    query.append(ORDER_BY_DESC);
8917                                            }
8918                                    }
8919                            }
8920                    }
8921                    else {
8922                            if (getDB().isSupportsInlineDistinct()) {
8923                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8924                            }
8925                            else {
8926                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
8927                            }
8928                    }
8929    
8930                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8931                                    WikiPage.class.getName(),
8932                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8933    
8934                    SQLQuery q = session.createSQLQuery(sql);
8935    
8936                    q.setFirstResult(0);
8937                    q.setMaxResults(2);
8938    
8939                    if (getDB().isSupportsInlineDistinct()) {
8940                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
8941                    }
8942                    else {
8943                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
8944                    }
8945    
8946                    QueryPos qPos = QueryPos.getInstance(q);
8947    
8948                    qPos.add(groupId);
8949    
8950                    qPos.add(nodeId);
8951    
8952                    qPos.add(status);
8953    
8954                    if (orderByComparator != null) {
8955                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
8956    
8957                            for (Object value : values) {
8958                                    qPos.add(value);
8959                            }
8960                    }
8961    
8962                    List<WikiPage> list = q.list();
8963    
8964                    if (list.size() == 2) {
8965                            return list.get(1);
8966                    }
8967                    else {
8968                            return null;
8969                    }
8970            }
8971    
8972            /**
8973             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63; from the database.
8974             *
8975             * @param groupId the group ID
8976             * @param nodeId the node ID
8977             * @param status the status
8978             * @throws SystemException if a system exception occurred
8979             */
8980            @Override
8981            public void removeByG_N_S(long groupId, long nodeId, int status)
8982                    throws SystemException {
8983                    for (WikiPage wikiPage : findByG_N_S(groupId, nodeId, status,
8984                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8985                            remove(wikiPage);
8986                    }
8987            }
8988    
8989            /**
8990             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
8991             *
8992             * @param groupId the group ID
8993             * @param nodeId the node ID
8994             * @param status the status
8995             * @return the number of matching wiki pages
8996             * @throws SystemException if a system exception occurred
8997             */
8998            @Override
8999            public int countByG_N_S(long groupId, long nodeId, int status)
9000                    throws SystemException {
9001                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_S;
9002    
9003                    Object[] finderArgs = new Object[] { groupId, nodeId, status };
9004    
9005                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9006                                    this);
9007    
9008                    if (count == null) {
9009                            StringBundler query = new StringBundler(4);
9010    
9011                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
9012    
9013                            query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
9014    
9015                            query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
9016    
9017                            query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
9018    
9019                            String sql = query.toString();
9020    
9021                            Session session = null;
9022    
9023                            try {
9024                                    session = openSession();
9025    
9026                                    Query q = session.createQuery(sql);
9027    
9028                                    QueryPos qPos = QueryPos.getInstance(q);
9029    
9030                                    qPos.add(groupId);
9031    
9032                                    qPos.add(nodeId);
9033    
9034                                    qPos.add(status);
9035    
9036                                    count = (Long)q.uniqueResult();
9037    
9038                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9039                            }
9040                            catch (Exception e) {
9041                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9042    
9043                                    throw processException(e);
9044                            }
9045                            finally {
9046                                    closeSession(session);
9047                            }
9048                    }
9049    
9050                    return count.intValue();
9051            }
9052    
9053            /**
9054             * Returns the number of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and status = &#63;.
9055             *
9056             * @param groupId the group ID
9057             * @param nodeId the node ID
9058             * @param status the status
9059             * @return the number of matching wiki pages that the user has permission to view
9060             * @throws SystemException if a system exception occurred
9061             */
9062            @Override
9063            public int filterCountByG_N_S(long groupId, long nodeId, int status)
9064                    throws SystemException {
9065                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9066                            return countByG_N_S(groupId, nodeId, status);
9067                    }
9068    
9069                    StringBundler query = new StringBundler(4);
9070    
9071                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
9072    
9073                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
9074    
9075                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
9076    
9077                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
9078    
9079                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9080                                    WikiPage.class.getName(),
9081                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9082    
9083                    Session session = null;
9084    
9085                    try {
9086                            session = openSession();
9087    
9088                            SQLQuery q = session.createSQLQuery(sql);
9089    
9090                            q.addScalar(COUNT_COLUMN_NAME,
9091                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9092    
9093                            QueryPos qPos = QueryPos.getInstance(q);
9094    
9095                            qPos.add(groupId);
9096    
9097                            qPos.add(nodeId);
9098    
9099                            qPos.add(status);
9100    
9101                            Long count = (Long)q.uniqueResult();
9102    
9103                            return count.intValue();
9104                    }
9105                    catch (Exception e) {
9106                            throw processException(e);
9107                    }
9108                    finally {
9109                            closeSession(session);
9110                    }
9111            }
9112    
9113            private static final String _FINDER_COLUMN_G_N_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
9114            private static final String _FINDER_COLUMN_G_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
9115            private static final String _FINDER_COLUMN_G_N_S_STATUS_2 = "wikiPage.status = ?";
9116            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9117                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
9118                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_N_S",
9119                            new String[] {
9120                                    Long.class.getName(), Long.class.getName(),
9121                                    Integer.class.getName(),
9122                                    
9123                            Integer.class.getName(), Integer.class.getName(),
9124                                    OrderByComparator.class.getName()
9125                            });
9126            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9127                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
9128                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_N_S",
9129                            new String[] {
9130                                    Long.class.getName(), Long.class.getName(),
9131                                    Integer.class.getName()
9132                            },
9133                            WikiPageModelImpl.USERID_COLUMN_BITMASK |
9134                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
9135                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
9136                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
9137                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
9138            public static final FinderPath FINDER_PATH_COUNT_BY_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9139                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9140                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_N_S",
9141                            new String[] {
9142                                    Long.class.getName(), Long.class.getName(),
9143                                    Integer.class.getName()
9144                            });
9145    
9146            /**
9147             * Returns all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
9148             *
9149             * @param userId the user ID
9150             * @param nodeId the node ID
9151             * @param status the status
9152             * @return the matching wiki pages
9153             * @throws SystemException if a system exception occurred
9154             */
9155            @Override
9156            public List<WikiPage> findByU_N_S(long userId, long nodeId, int status)
9157                    throws SystemException {
9158                    return findByU_N_S(userId, nodeId, status, QueryUtil.ALL_POS,
9159                            QueryUtil.ALL_POS, null);
9160            }
9161    
9162            /**
9163             * Returns a range of all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
9164             *
9165             * <p>
9166             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9167             * </p>
9168             *
9169             * @param userId the user ID
9170             * @param nodeId the node ID
9171             * @param status the status
9172             * @param start the lower bound of the range of wiki pages
9173             * @param end the upper bound of the range of wiki pages (not inclusive)
9174             * @return the range of matching wiki pages
9175             * @throws SystemException if a system exception occurred
9176             */
9177            @Override
9178            public List<WikiPage> findByU_N_S(long userId, long nodeId, int status,
9179                    int start, int end) throws SystemException {
9180                    return findByU_N_S(userId, nodeId, status, start, end, null);
9181            }
9182    
9183            /**
9184             * Returns an ordered range of all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
9185             *
9186             * <p>
9187             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9188             * </p>
9189             *
9190             * @param userId the user ID
9191             * @param nodeId the node ID
9192             * @param status the status
9193             * @param start the lower bound of the range of wiki pages
9194             * @param end the upper bound of the range of wiki pages (not inclusive)
9195             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9196             * @return the ordered range of matching wiki pages
9197             * @throws SystemException if a system exception occurred
9198             */
9199            @Override
9200            public List<WikiPage> findByU_N_S(long userId, long nodeId, int status,
9201                    int start, int end, OrderByComparator orderByComparator)
9202                    throws SystemException {
9203                    boolean pagination = true;
9204                    FinderPath finderPath = null;
9205                    Object[] finderArgs = null;
9206    
9207                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9208                                    (orderByComparator == null)) {
9209                            pagination = false;
9210                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S;
9211                            finderArgs = new Object[] { userId, nodeId, status };
9212                    }
9213                    else {
9214                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_N_S;
9215                            finderArgs = new Object[] {
9216                                            userId, nodeId, status,
9217                                            
9218                                            start, end, orderByComparator
9219                                    };
9220                    }
9221    
9222                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
9223                                    finderArgs, this);
9224    
9225                    if ((list != null) && !list.isEmpty()) {
9226                            for (WikiPage wikiPage : list) {
9227                                    if ((userId != wikiPage.getUserId()) ||
9228                                                    (nodeId != wikiPage.getNodeId()) ||
9229                                                    (status != wikiPage.getStatus())) {
9230                                            list = null;
9231    
9232                                            break;
9233                                    }
9234                            }
9235                    }
9236    
9237                    if (list == null) {
9238                            StringBundler query = null;
9239    
9240                            if (orderByComparator != null) {
9241                                    query = new StringBundler(5 +
9242                                                    (orderByComparator.getOrderByFields().length * 3));
9243                            }
9244                            else {
9245                                    query = new StringBundler(5);
9246                            }
9247    
9248                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
9249    
9250                            query.append(_FINDER_COLUMN_U_N_S_USERID_2);
9251    
9252                            query.append(_FINDER_COLUMN_U_N_S_NODEID_2);
9253    
9254                            query.append(_FINDER_COLUMN_U_N_S_STATUS_2);
9255    
9256                            if (orderByComparator != null) {
9257                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9258                                            orderByComparator);
9259                            }
9260                            else
9261                             if (pagination) {
9262                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
9263                            }
9264    
9265                            String sql = query.toString();
9266    
9267                            Session session = null;
9268    
9269                            try {
9270                                    session = openSession();
9271    
9272                                    Query q = session.createQuery(sql);
9273    
9274                                    QueryPos qPos = QueryPos.getInstance(q);
9275    
9276                                    qPos.add(userId);
9277    
9278                                    qPos.add(nodeId);
9279    
9280                                    qPos.add(status);
9281    
9282                                    if (!pagination) {
9283                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
9284                                                            start, end, false);
9285    
9286                                            Collections.sort(list);
9287    
9288                                            list = new UnmodifiableList<WikiPage>(list);
9289                                    }
9290                                    else {
9291                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
9292                                                            start, end);
9293                                    }
9294    
9295                                    cacheResult(list);
9296    
9297                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9298                            }
9299                            catch (Exception e) {
9300                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9301    
9302                                    throw processException(e);
9303                            }
9304                            finally {
9305                                    closeSession(session);
9306                            }
9307                    }
9308    
9309                    return list;
9310            }
9311    
9312            /**
9313             * Returns the first wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
9314             *
9315             * @param userId the user ID
9316             * @param nodeId the node ID
9317             * @param status the status
9318             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9319             * @return the first matching wiki page
9320             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
9321             * @throws SystemException if a system exception occurred
9322             */
9323            @Override
9324            public WikiPage findByU_N_S_First(long userId, long nodeId, int status,
9325                    OrderByComparator orderByComparator)
9326                    throws NoSuchPageException, SystemException {
9327                    WikiPage wikiPage = fetchByU_N_S_First(userId, nodeId, status,
9328                                    orderByComparator);
9329    
9330                    if (wikiPage != null) {
9331                            return wikiPage;
9332                    }
9333    
9334                    StringBundler msg = new StringBundler(8);
9335    
9336                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9337    
9338                    msg.append("userId=");
9339                    msg.append(userId);
9340    
9341                    msg.append(", nodeId=");
9342                    msg.append(nodeId);
9343    
9344                    msg.append(", status=");
9345                    msg.append(status);
9346    
9347                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9348    
9349                    throw new NoSuchPageException(msg.toString());
9350            }
9351    
9352            /**
9353             * Returns the first wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
9354             *
9355             * @param userId the user ID
9356             * @param nodeId the node ID
9357             * @param status the status
9358             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9359             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
9360             * @throws SystemException if a system exception occurred
9361             */
9362            @Override
9363            public WikiPage fetchByU_N_S_First(long userId, long nodeId, int status,
9364                    OrderByComparator orderByComparator) throws SystemException {
9365                    List<WikiPage> list = findByU_N_S(userId, nodeId, status, 0, 1,
9366                                    orderByComparator);
9367    
9368                    if (!list.isEmpty()) {
9369                            return list.get(0);
9370                    }
9371    
9372                    return null;
9373            }
9374    
9375            /**
9376             * Returns the last wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
9377             *
9378             * @param userId the user ID
9379             * @param nodeId the node ID
9380             * @param status the status
9381             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9382             * @return the last matching wiki page
9383             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
9384             * @throws SystemException if a system exception occurred
9385             */
9386            @Override
9387            public WikiPage findByU_N_S_Last(long userId, long nodeId, int status,
9388                    OrderByComparator orderByComparator)
9389                    throws NoSuchPageException, SystemException {
9390                    WikiPage wikiPage = fetchByU_N_S_Last(userId, nodeId, status,
9391                                    orderByComparator);
9392    
9393                    if (wikiPage != null) {
9394                            return wikiPage;
9395                    }
9396    
9397                    StringBundler msg = new StringBundler(8);
9398    
9399                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9400    
9401                    msg.append("userId=");
9402                    msg.append(userId);
9403    
9404                    msg.append(", nodeId=");
9405                    msg.append(nodeId);
9406    
9407                    msg.append(", status=");
9408                    msg.append(status);
9409    
9410                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9411    
9412                    throw new NoSuchPageException(msg.toString());
9413            }
9414    
9415            /**
9416             * Returns the last wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
9417             *
9418             * @param userId the user ID
9419             * @param nodeId the node ID
9420             * @param status the status
9421             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9422             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
9423             * @throws SystemException if a system exception occurred
9424             */
9425            @Override
9426            public WikiPage fetchByU_N_S_Last(long userId, long nodeId, int status,
9427                    OrderByComparator orderByComparator) throws SystemException {
9428                    int count = countByU_N_S(userId, nodeId, status);
9429    
9430                    if (count == 0) {
9431                            return null;
9432                    }
9433    
9434                    List<WikiPage> list = findByU_N_S(userId, nodeId, status, count - 1,
9435                                    count, orderByComparator);
9436    
9437                    if (!list.isEmpty()) {
9438                            return list.get(0);
9439                    }
9440    
9441                    return null;
9442            }
9443    
9444            /**
9445             * Returns the wiki pages before and after the current wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
9446             *
9447             * @param pageId the primary key of the current wiki page
9448             * @param userId the user ID
9449             * @param nodeId the node ID
9450             * @param status the status
9451             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9452             * @return the previous, current, and next wiki page
9453             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
9454             * @throws SystemException if a system exception occurred
9455             */
9456            @Override
9457            public WikiPage[] findByU_N_S_PrevAndNext(long pageId, long userId,
9458                    long nodeId, int status, OrderByComparator orderByComparator)
9459                    throws NoSuchPageException, SystemException {
9460                    WikiPage wikiPage = findByPrimaryKey(pageId);
9461    
9462                    Session session = null;
9463    
9464                    try {
9465                            session = openSession();
9466    
9467                            WikiPage[] array = new WikiPageImpl[3];
9468    
9469                            array[0] = getByU_N_S_PrevAndNext(session, wikiPage, userId,
9470                                            nodeId, status, orderByComparator, true);
9471    
9472                            array[1] = wikiPage;
9473    
9474                            array[2] = getByU_N_S_PrevAndNext(session, wikiPage, userId,
9475                                            nodeId, status, orderByComparator, false);
9476    
9477                            return array;
9478                    }
9479                    catch (Exception e) {
9480                            throw processException(e);
9481                    }
9482                    finally {
9483                            closeSession(session);
9484                    }
9485            }
9486    
9487            protected WikiPage getByU_N_S_PrevAndNext(Session session,
9488                    WikiPage wikiPage, long userId, long nodeId, int status,
9489                    OrderByComparator orderByComparator, boolean previous) {
9490                    StringBundler query = null;
9491    
9492                    if (orderByComparator != null) {
9493                            query = new StringBundler(6 +
9494                                            (orderByComparator.getOrderByFields().length * 6));
9495                    }
9496                    else {
9497                            query = new StringBundler(3);
9498                    }
9499    
9500                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
9501    
9502                    query.append(_FINDER_COLUMN_U_N_S_USERID_2);
9503    
9504                    query.append(_FINDER_COLUMN_U_N_S_NODEID_2);
9505    
9506                    query.append(_FINDER_COLUMN_U_N_S_STATUS_2);
9507    
9508                    if (orderByComparator != null) {
9509                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9510    
9511                            if (orderByConditionFields.length > 0) {
9512                                    query.append(WHERE_AND);
9513                            }
9514    
9515                            for (int i = 0; i < orderByConditionFields.length; i++) {
9516                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9517                                    query.append(orderByConditionFields[i]);
9518    
9519                                    if ((i + 1) < orderByConditionFields.length) {
9520                                            if (orderByComparator.isAscending() ^ previous) {
9521                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9522                                            }
9523                                            else {
9524                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9525                                            }
9526                                    }
9527                                    else {
9528                                            if (orderByComparator.isAscending() ^ previous) {
9529                                                    query.append(WHERE_GREATER_THAN);
9530                                            }
9531                                            else {
9532                                                    query.append(WHERE_LESSER_THAN);
9533                                            }
9534                                    }
9535                            }
9536    
9537                            query.append(ORDER_BY_CLAUSE);
9538    
9539                            String[] orderByFields = orderByComparator.getOrderByFields();
9540    
9541                            for (int i = 0; i < orderByFields.length; i++) {
9542                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9543                                    query.append(orderByFields[i]);
9544    
9545                                    if ((i + 1) < orderByFields.length) {
9546                                            if (orderByComparator.isAscending() ^ previous) {
9547                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9548                                            }
9549                                            else {
9550                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9551                                            }
9552                                    }
9553                                    else {
9554                                            if (orderByComparator.isAscending() ^ previous) {
9555                                                    query.append(ORDER_BY_ASC);
9556                                            }
9557                                            else {
9558                                                    query.append(ORDER_BY_DESC);
9559                                            }
9560                                    }
9561                            }
9562                    }
9563                    else {
9564                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
9565                    }
9566    
9567                    String sql = query.toString();
9568    
9569                    Query q = session.createQuery(sql);
9570    
9571                    q.setFirstResult(0);
9572                    q.setMaxResults(2);
9573    
9574                    QueryPos qPos = QueryPos.getInstance(q);
9575    
9576                    qPos.add(userId);
9577    
9578                    qPos.add(nodeId);
9579    
9580                    qPos.add(status);
9581    
9582                    if (orderByComparator != null) {
9583                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
9584    
9585                            for (Object value : values) {
9586                                    qPos.add(value);
9587                            }
9588                    }
9589    
9590                    List<WikiPage> list = q.list();
9591    
9592                    if (list.size() == 2) {
9593                            return list.get(1);
9594                    }
9595                    else {
9596                            return null;
9597                    }
9598            }
9599    
9600            /**
9601             * Removes all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63; from the database.
9602             *
9603             * @param userId the user ID
9604             * @param nodeId the node ID
9605             * @param status the status
9606             * @throws SystemException if a system exception occurred
9607             */
9608            @Override
9609            public void removeByU_N_S(long userId, long nodeId, int status)
9610                    throws SystemException {
9611                    for (WikiPage wikiPage : findByU_N_S(userId, nodeId, status,
9612                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9613                            remove(wikiPage);
9614                    }
9615            }
9616    
9617            /**
9618             * Returns the number of wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
9619             *
9620             * @param userId the user ID
9621             * @param nodeId the node ID
9622             * @param status the status
9623             * @return the number of matching wiki pages
9624             * @throws SystemException if a system exception occurred
9625             */
9626            @Override
9627            public int countByU_N_S(long userId, long nodeId, int status)
9628                    throws SystemException {
9629                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_N_S;
9630    
9631                    Object[] finderArgs = new Object[] { userId, nodeId, status };
9632    
9633                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9634                                    this);
9635    
9636                    if (count == null) {
9637                            StringBundler query = new StringBundler(4);
9638    
9639                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
9640    
9641                            query.append(_FINDER_COLUMN_U_N_S_USERID_2);
9642    
9643                            query.append(_FINDER_COLUMN_U_N_S_NODEID_2);
9644    
9645                            query.append(_FINDER_COLUMN_U_N_S_STATUS_2);
9646    
9647                            String sql = query.toString();
9648    
9649                            Session session = null;
9650    
9651                            try {
9652                                    session = openSession();
9653    
9654                                    Query q = session.createQuery(sql);
9655    
9656                                    QueryPos qPos = QueryPos.getInstance(q);
9657    
9658                                    qPos.add(userId);
9659    
9660                                    qPos.add(nodeId);
9661    
9662                                    qPos.add(status);
9663    
9664                                    count = (Long)q.uniqueResult();
9665    
9666                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9667                            }
9668                            catch (Exception e) {
9669                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9670    
9671                                    throw processException(e);
9672                            }
9673                            finally {
9674                                    closeSession(session);
9675                            }
9676                    }
9677    
9678                    return count.intValue();
9679            }
9680    
9681            private static final String _FINDER_COLUMN_U_N_S_USERID_2 = "wikiPage.userId = ? AND ";
9682            private static final String _FINDER_COLUMN_U_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
9683            private static final String _FINDER_COLUMN_U_N_S_STATUS_2 = "wikiPage.status = ?";
9684            public static final FinderPath FINDER_PATH_FETCH_BY_N_T_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9685                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
9686                            FINDER_CLASS_NAME_ENTITY, "fetchByN_T_V",
9687                            new String[] {
9688                                    Long.class.getName(), String.class.getName(),
9689                                    Double.class.getName()
9690                            },
9691                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
9692                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
9693                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
9694            public static final FinderPath FINDER_PATH_COUNT_BY_N_T_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9695                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9696                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T_V",
9697                            new String[] {
9698                                    Long.class.getName(), String.class.getName(),
9699                                    Double.class.getName()
9700                            });
9701    
9702            /**
9703             * 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.
9704             *
9705             * @param nodeId the node ID
9706             * @param title the title
9707             * @param version the version
9708             * @return the matching wiki page
9709             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
9710             * @throws SystemException if a system exception occurred
9711             */
9712            @Override
9713            public WikiPage findByN_T_V(long nodeId, String title, double version)
9714                    throws NoSuchPageException, SystemException {
9715                    WikiPage wikiPage = fetchByN_T_V(nodeId, title, version);
9716    
9717                    if (wikiPage == null) {
9718                            StringBundler msg = new StringBundler(8);
9719    
9720                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9721    
9722                            msg.append("nodeId=");
9723                            msg.append(nodeId);
9724    
9725                            msg.append(", title=");
9726                            msg.append(title);
9727    
9728                            msg.append(", version=");
9729                            msg.append(version);
9730    
9731                            msg.append(StringPool.CLOSE_CURLY_BRACE);
9732    
9733                            if (_log.isWarnEnabled()) {
9734                                    _log.warn(msg.toString());
9735                            }
9736    
9737                            throw new NoSuchPageException(msg.toString());
9738                    }
9739    
9740                    return wikiPage;
9741            }
9742    
9743            /**
9744             * 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.
9745             *
9746             * @param nodeId the node ID
9747             * @param title the title
9748             * @param version the version
9749             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
9750             * @throws SystemException if a system exception occurred
9751             */
9752            @Override
9753            public WikiPage fetchByN_T_V(long nodeId, String title, double version)
9754                    throws SystemException {
9755                    return fetchByN_T_V(nodeId, title, version, true);
9756            }
9757    
9758            /**
9759             * 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.
9760             *
9761             * @param nodeId the node ID
9762             * @param title the title
9763             * @param version the version
9764             * @param retrieveFromCache whether to use the finder cache
9765             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
9766             * @throws SystemException if a system exception occurred
9767             */
9768            @Override
9769            public WikiPage fetchByN_T_V(long nodeId, String title, double version,
9770                    boolean retrieveFromCache) throws SystemException {
9771                    Object[] finderArgs = new Object[] { nodeId, title, version };
9772    
9773                    Object result = null;
9774    
9775                    if (retrieveFromCache) {
9776                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_T_V,
9777                                            finderArgs, this);
9778                    }
9779    
9780                    if (result instanceof WikiPage) {
9781                            WikiPage wikiPage = (WikiPage)result;
9782    
9783                            if ((nodeId != wikiPage.getNodeId()) ||
9784                                            !Validator.equals(title, wikiPage.getTitle()) ||
9785                                            (version != wikiPage.getVersion())) {
9786                                    result = null;
9787                            }
9788                    }
9789    
9790                    if (result == null) {
9791                            StringBundler query = new StringBundler(5);
9792    
9793                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
9794    
9795                            query.append(_FINDER_COLUMN_N_T_V_NODEID_2);
9796    
9797                            boolean bindTitle = false;
9798    
9799                            if (title == null) {
9800                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_1);
9801                            }
9802                            else if (title.equals(StringPool.BLANK)) {
9803                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_3);
9804                            }
9805                            else {
9806                                    bindTitle = true;
9807    
9808                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_2);
9809                            }
9810    
9811                            query.append(_FINDER_COLUMN_N_T_V_VERSION_2);
9812    
9813                            String sql = query.toString();
9814    
9815                            Session session = null;
9816    
9817                            try {
9818                                    session = openSession();
9819    
9820                                    Query q = session.createQuery(sql);
9821    
9822                                    QueryPos qPos = QueryPos.getInstance(q);
9823    
9824                                    qPos.add(nodeId);
9825    
9826                                    if (bindTitle) {
9827                                            qPos.add(title.toLowerCase());
9828                                    }
9829    
9830                                    qPos.add(version);
9831    
9832                                    List<WikiPage> list = q.list();
9833    
9834                                    if (list.isEmpty()) {
9835                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
9836                                                    finderArgs, list);
9837                                    }
9838                                    else {
9839                                            WikiPage wikiPage = list.get(0);
9840    
9841                                            result = wikiPage;
9842    
9843                                            cacheResult(wikiPage);
9844    
9845                                            if ((wikiPage.getNodeId() != nodeId) ||
9846                                                            (wikiPage.getTitle() == null) ||
9847                                                            !wikiPage.getTitle().equals(title) ||
9848                                                            (wikiPage.getVersion() != version)) {
9849                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
9850                                                            finderArgs, wikiPage);
9851                                            }
9852                                    }
9853                            }
9854                            catch (Exception e) {
9855                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V,
9856                                            finderArgs);
9857    
9858                                    throw processException(e);
9859                            }
9860                            finally {
9861                                    closeSession(session);
9862                            }
9863                    }
9864    
9865                    if (result instanceof List<?>) {
9866                            return null;
9867                    }
9868                    else {
9869                            return (WikiPage)result;
9870                    }
9871            }
9872    
9873            /**
9874             * Removes the wiki page where nodeId = &#63; and title = &#63; and version = &#63; from the database.
9875             *
9876             * @param nodeId the node ID
9877             * @param title the title
9878             * @param version the version
9879             * @return the wiki page that was removed
9880             * @throws SystemException if a system exception occurred
9881             */
9882            @Override
9883            public WikiPage removeByN_T_V(long nodeId, String title, double version)
9884                    throws NoSuchPageException, SystemException {
9885                    WikiPage wikiPage = findByN_T_V(nodeId, title, version);
9886    
9887                    return remove(wikiPage);
9888            }
9889    
9890            /**
9891             * Returns the number of wiki pages where nodeId = &#63; and title = &#63; and version = &#63;.
9892             *
9893             * @param nodeId the node ID
9894             * @param title the title
9895             * @param version the version
9896             * @return the number of matching wiki pages
9897             * @throws SystemException if a system exception occurred
9898             */
9899            @Override
9900            public int countByN_T_V(long nodeId, String title, double version)
9901                    throws SystemException {
9902                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T_V;
9903    
9904                    Object[] finderArgs = new Object[] { nodeId, title, version };
9905    
9906                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9907                                    this);
9908    
9909                    if (count == null) {
9910                            StringBundler query = new StringBundler(4);
9911    
9912                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
9913    
9914                            query.append(_FINDER_COLUMN_N_T_V_NODEID_2);
9915    
9916                            boolean bindTitle = false;
9917    
9918                            if (title == null) {
9919                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_1);
9920                            }
9921                            else if (title.equals(StringPool.BLANK)) {
9922                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_3);
9923                            }
9924                            else {
9925                                    bindTitle = true;
9926    
9927                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_2);
9928                            }
9929    
9930                            query.append(_FINDER_COLUMN_N_T_V_VERSION_2);
9931    
9932                            String sql = query.toString();
9933    
9934                            Session session = null;
9935    
9936                            try {
9937                                    session = openSession();
9938    
9939                                    Query q = session.createQuery(sql);
9940    
9941                                    QueryPos qPos = QueryPos.getInstance(q);
9942    
9943                                    qPos.add(nodeId);
9944    
9945                                    if (bindTitle) {
9946                                            qPos.add(title.toLowerCase());
9947                                    }
9948    
9949                                    qPos.add(version);
9950    
9951                                    count = (Long)q.uniqueResult();
9952    
9953                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9954                            }
9955                            catch (Exception e) {
9956                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9957    
9958                                    throw processException(e);
9959                            }
9960                            finally {
9961                                    closeSession(session);
9962                            }
9963                    }
9964    
9965                    return count.intValue();
9966            }
9967    
9968            private static final String _FINDER_COLUMN_N_T_V_NODEID_2 = "wikiPage.nodeId = ? AND ";
9969            private static final String _FINDER_COLUMN_N_T_V_TITLE_1 = "wikiPage.title IS NULL AND ";
9970            private static final String _FINDER_COLUMN_N_T_V_TITLE_2 = "lower(wikiPage.title) = ? AND ";
9971            private static final String _FINDER_COLUMN_N_T_V_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '') AND ";
9972            private static final String _FINDER_COLUMN_N_T_V_VERSION_2 = "wikiPage.version = ?";
9973            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9974                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
9975                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_T_H",
9976                            new String[] {
9977                                    Long.class.getName(), String.class.getName(),
9978                                    Boolean.class.getName(),
9979                                    
9980                            Integer.class.getName(), Integer.class.getName(),
9981                                    OrderByComparator.class.getName()
9982                            });
9983            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9984                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
9985                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_T_H",
9986                            new String[] {
9987                                    Long.class.getName(), String.class.getName(),
9988                                    Boolean.class.getName()
9989                            },
9990                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
9991                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
9992                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
9993                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
9994            public static final FinderPath FINDER_PATH_COUNT_BY_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9995                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9996                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T_H",
9997                            new String[] {
9998                                    Long.class.getName(), String.class.getName(),
9999                                    Boolean.class.getName()
10000                            });
10001    
10002            /**
10003             * Returns all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
10004             *
10005             * @param nodeId the node ID
10006             * @param title the title
10007             * @param head the head
10008             * @return the matching wiki pages
10009             * @throws SystemException if a system exception occurred
10010             */
10011            @Override
10012            public List<WikiPage> findByN_T_H(long nodeId, String title, boolean head)
10013                    throws SystemException {
10014                    return findByN_T_H(nodeId, title, head, QueryUtil.ALL_POS,
10015                            QueryUtil.ALL_POS, null);
10016            }
10017    
10018            /**
10019             * Returns a range of all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
10020             *
10021             * <p>
10022             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10023             * </p>
10024             *
10025             * @param nodeId the node ID
10026             * @param title the title
10027             * @param head the head
10028             * @param start the lower bound of the range of wiki pages
10029             * @param end the upper bound of the range of wiki pages (not inclusive)
10030             * @return the range of matching wiki pages
10031             * @throws SystemException if a system exception occurred
10032             */
10033            @Override
10034            public List<WikiPage> findByN_T_H(long nodeId, String title, boolean head,
10035                    int start, int end) throws SystemException {
10036                    return findByN_T_H(nodeId, title, head, start, end, null);
10037            }
10038    
10039            /**
10040             * Returns an ordered range of all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
10041             *
10042             * <p>
10043             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10044             * </p>
10045             *
10046             * @param nodeId the node ID
10047             * @param title the title
10048             * @param head the head
10049             * @param start the lower bound of the range of wiki pages
10050             * @param end the upper bound of the range of wiki pages (not inclusive)
10051             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10052             * @return the ordered range of matching wiki pages
10053             * @throws SystemException if a system exception occurred
10054             */
10055            @Override
10056            public List<WikiPage> findByN_T_H(long nodeId, String title, boolean head,
10057                    int start, int end, OrderByComparator orderByComparator)
10058                    throws SystemException {
10059                    boolean pagination = true;
10060                    FinderPath finderPath = null;
10061                    Object[] finderArgs = null;
10062    
10063                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10064                                    (orderByComparator == null)) {
10065                            pagination = false;
10066                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H;
10067                            finderArgs = new Object[] { nodeId, title, head };
10068                    }
10069                    else {
10070                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_H;
10071                            finderArgs = new Object[] {
10072                                            nodeId, title, head,
10073                                            
10074                                            start, end, orderByComparator
10075                                    };
10076                    }
10077    
10078                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
10079                                    finderArgs, this);
10080    
10081                    if ((list != null) && !list.isEmpty()) {
10082                            for (WikiPage wikiPage : list) {
10083                                    if ((nodeId != wikiPage.getNodeId()) ||
10084                                                    !Validator.equals(title, wikiPage.getTitle()) ||
10085                                                    (head != wikiPage.getHead())) {
10086                                            list = null;
10087    
10088                                            break;
10089                                    }
10090                            }
10091                    }
10092    
10093                    if (list == null) {
10094                            StringBundler query = null;
10095    
10096                            if (orderByComparator != null) {
10097                                    query = new StringBundler(5 +
10098                                                    (orderByComparator.getOrderByFields().length * 3));
10099                            }
10100                            else {
10101                                    query = new StringBundler(5);
10102                            }
10103    
10104                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
10105    
10106                            query.append(_FINDER_COLUMN_N_T_H_NODEID_2);
10107    
10108                            boolean bindTitle = false;
10109    
10110                            if (title == null) {
10111                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_1);
10112                            }
10113                            else if (title.equals(StringPool.BLANK)) {
10114                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_3);
10115                            }
10116                            else {
10117                                    bindTitle = true;
10118    
10119                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_2);
10120                            }
10121    
10122                            query.append(_FINDER_COLUMN_N_T_H_HEAD_2);
10123    
10124                            if (orderByComparator != null) {
10125                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10126                                            orderByComparator);
10127                            }
10128                            else
10129                             if (pagination) {
10130                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
10131                            }
10132    
10133                            String sql = query.toString();
10134    
10135                            Session session = null;
10136    
10137                            try {
10138                                    session = openSession();
10139    
10140                                    Query q = session.createQuery(sql);
10141    
10142                                    QueryPos qPos = QueryPos.getInstance(q);
10143    
10144                                    qPos.add(nodeId);
10145    
10146                                    if (bindTitle) {
10147                                            qPos.add(title.toLowerCase());
10148                                    }
10149    
10150                                    qPos.add(head);
10151    
10152                                    if (!pagination) {
10153                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
10154                                                            start, end, false);
10155    
10156                                            Collections.sort(list);
10157    
10158                                            list = new UnmodifiableList<WikiPage>(list);
10159                                    }
10160                                    else {
10161                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
10162                                                            start, end);
10163                                    }
10164    
10165                                    cacheResult(list);
10166    
10167                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10168                            }
10169                            catch (Exception e) {
10170                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10171    
10172                                    throw processException(e);
10173                            }
10174                            finally {
10175                                    closeSession(session);
10176                            }
10177                    }
10178    
10179                    return list;
10180            }
10181    
10182            /**
10183             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
10184             *
10185             * @param nodeId the node ID
10186             * @param title the title
10187             * @param head the head
10188             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10189             * @return the first matching wiki page
10190             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
10191             * @throws SystemException if a system exception occurred
10192             */
10193            @Override
10194            public WikiPage findByN_T_H_First(long nodeId, String title, boolean head,
10195                    OrderByComparator orderByComparator)
10196                    throws NoSuchPageException, SystemException {
10197                    WikiPage wikiPage = fetchByN_T_H_First(nodeId, title, head,
10198                                    orderByComparator);
10199    
10200                    if (wikiPage != null) {
10201                            return wikiPage;
10202                    }
10203    
10204                    StringBundler msg = new StringBundler(8);
10205    
10206                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10207    
10208                    msg.append("nodeId=");
10209                    msg.append(nodeId);
10210    
10211                    msg.append(", title=");
10212                    msg.append(title);
10213    
10214                    msg.append(", head=");
10215                    msg.append(head);
10216    
10217                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10218    
10219                    throw new NoSuchPageException(msg.toString());
10220            }
10221    
10222            /**
10223             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
10224             *
10225             * @param nodeId the node ID
10226             * @param title the title
10227             * @param head the head
10228             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10229             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
10230             * @throws SystemException if a system exception occurred
10231             */
10232            @Override
10233            public WikiPage fetchByN_T_H_First(long nodeId, String title, boolean head,
10234                    OrderByComparator orderByComparator) throws SystemException {
10235                    List<WikiPage> list = findByN_T_H(nodeId, title, head, 0, 1,
10236                                    orderByComparator);
10237    
10238                    if (!list.isEmpty()) {
10239                            return list.get(0);
10240                    }
10241    
10242                    return null;
10243            }
10244    
10245            /**
10246             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
10247             *
10248             * @param nodeId the node ID
10249             * @param title the title
10250             * @param head the head
10251             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10252             * @return the last matching wiki page
10253             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
10254             * @throws SystemException if a system exception occurred
10255             */
10256            @Override
10257            public WikiPage findByN_T_H_Last(long nodeId, String title, boolean head,
10258                    OrderByComparator orderByComparator)
10259                    throws NoSuchPageException, SystemException {
10260                    WikiPage wikiPage = fetchByN_T_H_Last(nodeId, title, head,
10261                                    orderByComparator);
10262    
10263                    if (wikiPage != null) {
10264                            return wikiPage;
10265                    }
10266    
10267                    StringBundler msg = new StringBundler(8);
10268    
10269                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10270    
10271                    msg.append("nodeId=");
10272                    msg.append(nodeId);
10273    
10274                    msg.append(", title=");
10275                    msg.append(title);
10276    
10277                    msg.append(", head=");
10278                    msg.append(head);
10279    
10280                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10281    
10282                    throw new NoSuchPageException(msg.toString());
10283            }
10284    
10285            /**
10286             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
10287             *
10288             * @param nodeId the node ID
10289             * @param title the title
10290             * @param head the head
10291             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10292             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
10293             * @throws SystemException if a system exception occurred
10294             */
10295            @Override
10296            public WikiPage fetchByN_T_H_Last(long nodeId, String title, boolean head,
10297                    OrderByComparator orderByComparator) throws SystemException {
10298                    int count = countByN_T_H(nodeId, title, head);
10299    
10300                    if (count == 0) {
10301                            return null;
10302                    }
10303    
10304                    List<WikiPage> list = findByN_T_H(nodeId, title, head, count - 1,
10305                                    count, orderByComparator);
10306    
10307                    if (!list.isEmpty()) {
10308                            return list.get(0);
10309                    }
10310    
10311                    return null;
10312            }
10313    
10314            /**
10315             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
10316             *
10317             * @param pageId the primary key of the current wiki page
10318             * @param nodeId the node ID
10319             * @param title the title
10320             * @param head the head
10321             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10322             * @return the previous, current, and next wiki page
10323             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
10324             * @throws SystemException if a system exception occurred
10325             */
10326            @Override
10327            public WikiPage[] findByN_T_H_PrevAndNext(long pageId, long nodeId,
10328                    String title, boolean head, OrderByComparator orderByComparator)
10329                    throws NoSuchPageException, SystemException {
10330                    WikiPage wikiPage = findByPrimaryKey(pageId);
10331    
10332                    Session session = null;
10333    
10334                    try {
10335                            session = openSession();
10336    
10337                            WikiPage[] array = new WikiPageImpl[3];
10338    
10339                            array[0] = getByN_T_H_PrevAndNext(session, wikiPage, nodeId, title,
10340                                            head, orderByComparator, true);
10341    
10342                            array[1] = wikiPage;
10343    
10344                            array[2] = getByN_T_H_PrevAndNext(session, wikiPage, nodeId, title,
10345                                            head, orderByComparator, false);
10346    
10347                            return array;
10348                    }
10349                    catch (Exception e) {
10350                            throw processException(e);
10351                    }
10352                    finally {
10353                            closeSession(session);
10354                    }
10355            }
10356    
10357            protected WikiPage getByN_T_H_PrevAndNext(Session session,
10358                    WikiPage wikiPage, long nodeId, String title, boolean head,
10359                    OrderByComparator orderByComparator, boolean previous) {
10360                    StringBundler query = null;
10361    
10362                    if (orderByComparator != null) {
10363                            query = new StringBundler(6 +
10364                                            (orderByComparator.getOrderByFields().length * 6));
10365                    }
10366                    else {
10367                            query = new StringBundler(3);
10368                    }
10369    
10370                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
10371    
10372                    query.append(_FINDER_COLUMN_N_T_H_NODEID_2);
10373    
10374                    boolean bindTitle = false;
10375    
10376                    if (title == null) {
10377                            query.append(_FINDER_COLUMN_N_T_H_TITLE_1);
10378                    }
10379                    else if (title.equals(StringPool.BLANK)) {
10380                            query.append(_FINDER_COLUMN_N_T_H_TITLE_3);
10381                    }
10382                    else {
10383                            bindTitle = true;
10384    
10385                            query.append(_FINDER_COLUMN_N_T_H_TITLE_2);
10386                    }
10387    
10388                    query.append(_FINDER_COLUMN_N_T_H_HEAD_2);
10389    
10390                    if (orderByComparator != null) {
10391                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10392    
10393                            if (orderByConditionFields.length > 0) {
10394                                    query.append(WHERE_AND);
10395                            }
10396    
10397                            for (int i = 0; i < orderByConditionFields.length; i++) {
10398                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10399                                    query.append(orderByConditionFields[i]);
10400    
10401                                    if ((i + 1) < orderByConditionFields.length) {
10402                                            if (orderByComparator.isAscending() ^ previous) {
10403                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10404                                            }
10405                                            else {
10406                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10407                                            }
10408                                    }
10409                                    else {
10410                                            if (orderByComparator.isAscending() ^ previous) {
10411                                                    query.append(WHERE_GREATER_THAN);
10412                                            }
10413                                            else {
10414                                                    query.append(WHERE_LESSER_THAN);
10415                                            }
10416                                    }
10417                            }
10418    
10419                            query.append(ORDER_BY_CLAUSE);
10420    
10421                            String[] orderByFields = orderByComparator.getOrderByFields();
10422    
10423                            for (int i = 0; i < orderByFields.length; i++) {
10424                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10425                                    query.append(orderByFields[i]);
10426    
10427                                    if ((i + 1) < orderByFields.length) {
10428                                            if (orderByComparator.isAscending() ^ previous) {
10429                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10430                                            }
10431                                            else {
10432                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10433                                            }
10434                                    }
10435                                    else {
10436                                            if (orderByComparator.isAscending() ^ previous) {
10437                                                    query.append(ORDER_BY_ASC);
10438                                            }
10439                                            else {
10440                                                    query.append(ORDER_BY_DESC);
10441                                            }
10442                                    }
10443                            }
10444                    }
10445                    else {
10446                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
10447                    }
10448    
10449                    String sql = query.toString();
10450    
10451                    Query q = session.createQuery(sql);
10452    
10453                    q.setFirstResult(0);
10454                    q.setMaxResults(2);
10455    
10456                    QueryPos qPos = QueryPos.getInstance(q);
10457    
10458                    qPos.add(nodeId);
10459    
10460                    if (bindTitle) {
10461                            qPos.add(title.toLowerCase());
10462                    }
10463    
10464                    qPos.add(head);
10465    
10466                    if (orderByComparator != null) {
10467                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
10468    
10469                            for (Object value : values) {
10470                                    qPos.add(value);
10471                            }
10472                    }
10473    
10474                    List<WikiPage> list = q.list();
10475    
10476                    if (list.size() == 2) {
10477                            return list.get(1);
10478                    }
10479                    else {
10480                            return null;
10481                    }
10482            }
10483    
10484            /**
10485             * Removes all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63; from the database.
10486             *
10487             * @param nodeId the node ID
10488             * @param title the title
10489             * @param head the head
10490             * @throws SystemException if a system exception occurred
10491             */
10492            @Override
10493            public void removeByN_T_H(long nodeId, String title, boolean head)
10494                    throws SystemException {
10495                    for (WikiPage wikiPage : findByN_T_H(nodeId, title, head,
10496                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10497                            remove(wikiPage);
10498                    }
10499            }
10500    
10501            /**
10502             * Returns the number of wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
10503             *
10504             * @param nodeId the node ID
10505             * @param title the title
10506             * @param head the head
10507             * @return the number of matching wiki pages
10508             * @throws SystemException if a system exception occurred
10509             */
10510            @Override
10511            public int countByN_T_H(long nodeId, String title, boolean head)
10512                    throws SystemException {
10513                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T_H;
10514    
10515                    Object[] finderArgs = new Object[] { nodeId, title, head };
10516    
10517                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10518                                    this);
10519    
10520                    if (count == null) {
10521                            StringBundler query = new StringBundler(4);
10522    
10523                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
10524    
10525                            query.append(_FINDER_COLUMN_N_T_H_NODEID_2);
10526    
10527                            boolean bindTitle = false;
10528    
10529                            if (title == null) {
10530                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_1);
10531                            }
10532                            else if (title.equals(StringPool.BLANK)) {
10533                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_3);
10534                            }
10535                            else {
10536                                    bindTitle = true;
10537    
10538                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_2);
10539                            }
10540    
10541                            query.append(_FINDER_COLUMN_N_T_H_HEAD_2);
10542    
10543                            String sql = query.toString();
10544    
10545                            Session session = null;
10546    
10547                            try {
10548                                    session = openSession();
10549    
10550                                    Query q = session.createQuery(sql);
10551    
10552                                    QueryPos qPos = QueryPos.getInstance(q);
10553    
10554                                    qPos.add(nodeId);
10555    
10556                                    if (bindTitle) {
10557                                            qPos.add(title.toLowerCase());
10558                                    }
10559    
10560                                    qPos.add(head);
10561    
10562                                    count = (Long)q.uniqueResult();
10563    
10564                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10565                            }
10566                            catch (Exception e) {
10567                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10568    
10569                                    throw processException(e);
10570                            }
10571                            finally {
10572                                    closeSession(session);
10573                            }
10574                    }
10575    
10576                    return count.intValue();
10577            }
10578    
10579            private static final String _FINDER_COLUMN_N_T_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
10580            private static final String _FINDER_COLUMN_N_T_H_TITLE_1 = "wikiPage.title IS NULL AND ";
10581            private static final String _FINDER_COLUMN_N_T_H_TITLE_2 = "lower(wikiPage.title) = ? AND ";
10582            private static final String _FINDER_COLUMN_N_T_H_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '') AND ";
10583            private static final String _FINDER_COLUMN_N_T_H_HEAD_2 = "wikiPage.head = ?";
10584            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10585                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
10586                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_T_S",
10587                            new String[] {
10588                                    Long.class.getName(), String.class.getName(),
10589                                    Integer.class.getName(),
10590                                    
10591                            Integer.class.getName(), Integer.class.getName(),
10592                                    OrderByComparator.class.getName()
10593                            });
10594            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10595                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
10596                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_T_S",
10597                            new String[] {
10598                                    Long.class.getName(), String.class.getName(),
10599                                    Integer.class.getName()
10600                            },
10601                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
10602                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
10603                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
10604                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
10605            public static final FinderPath FINDER_PATH_COUNT_BY_N_T_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10606                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10607                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T_S",
10608                            new String[] {
10609                                    Long.class.getName(), String.class.getName(),
10610                                    Integer.class.getName()
10611                            });
10612    
10613            /**
10614             * Returns all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
10615             *
10616             * @param nodeId the node ID
10617             * @param title the title
10618             * @param status the status
10619             * @return the matching wiki pages
10620             * @throws SystemException if a system exception occurred
10621             */
10622            @Override
10623            public List<WikiPage> findByN_T_S(long nodeId, String title, int status)
10624                    throws SystemException {
10625                    return findByN_T_S(nodeId, title, status, QueryUtil.ALL_POS,
10626                            QueryUtil.ALL_POS, null);
10627            }
10628    
10629            /**
10630             * Returns a range of all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
10631             *
10632             * <p>
10633             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10634             * </p>
10635             *
10636             * @param nodeId the node ID
10637             * @param title the title
10638             * @param status the status
10639             * @param start the lower bound of the range of wiki pages
10640             * @param end the upper bound of the range of wiki pages (not inclusive)
10641             * @return the range of matching wiki pages
10642             * @throws SystemException if a system exception occurred
10643             */
10644            @Override
10645            public List<WikiPage> findByN_T_S(long nodeId, String title, int status,
10646                    int start, int end) throws SystemException {
10647                    return findByN_T_S(nodeId, title, status, start, end, null);
10648            }
10649    
10650            /**
10651             * Returns an ordered range of all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
10652             *
10653             * <p>
10654             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10655             * </p>
10656             *
10657             * @param nodeId the node ID
10658             * @param title the title
10659             * @param status the status
10660             * @param start the lower bound of the range of wiki pages
10661             * @param end the upper bound of the range of wiki pages (not inclusive)
10662             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10663             * @return the ordered range of matching wiki pages
10664             * @throws SystemException if a system exception occurred
10665             */
10666            @Override
10667            public List<WikiPage> findByN_T_S(long nodeId, String title, int status,
10668                    int start, int end, OrderByComparator orderByComparator)
10669                    throws SystemException {
10670                    boolean pagination = true;
10671                    FinderPath finderPath = null;
10672                    Object[] finderArgs = null;
10673    
10674                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10675                                    (orderByComparator == null)) {
10676                            pagination = false;
10677                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S;
10678                            finderArgs = new Object[] { nodeId, title, status };
10679                    }
10680                    else {
10681                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_S;
10682                            finderArgs = new Object[] {
10683                                            nodeId, title, status,
10684                                            
10685                                            start, end, orderByComparator
10686                                    };
10687                    }
10688    
10689                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
10690                                    finderArgs, this);
10691    
10692                    if ((list != null) && !list.isEmpty()) {
10693                            for (WikiPage wikiPage : list) {
10694                                    if ((nodeId != wikiPage.getNodeId()) ||
10695                                                    !Validator.equals(title, wikiPage.getTitle()) ||
10696                                                    (status != wikiPage.getStatus())) {
10697                                            list = null;
10698    
10699                                            break;
10700                                    }
10701                            }
10702                    }
10703    
10704                    if (list == null) {
10705                            StringBundler query = null;
10706    
10707                            if (orderByComparator != null) {
10708                                    query = new StringBundler(5 +
10709                                                    (orderByComparator.getOrderByFields().length * 3));
10710                            }
10711                            else {
10712                                    query = new StringBundler(5);
10713                            }
10714    
10715                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
10716    
10717                            query.append(_FINDER_COLUMN_N_T_S_NODEID_2);
10718    
10719                            boolean bindTitle = false;
10720    
10721                            if (title == null) {
10722                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_1);
10723                            }
10724                            else if (title.equals(StringPool.BLANK)) {
10725                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_3);
10726                            }
10727                            else {
10728                                    bindTitle = true;
10729    
10730                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_2);
10731                            }
10732    
10733                            query.append(_FINDER_COLUMN_N_T_S_STATUS_2);
10734    
10735                            if (orderByComparator != null) {
10736                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10737                                            orderByComparator);
10738                            }
10739                            else
10740                             if (pagination) {
10741                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
10742                            }
10743    
10744                            String sql = query.toString();
10745    
10746                            Session session = null;
10747    
10748                            try {
10749                                    session = openSession();
10750    
10751                                    Query q = session.createQuery(sql);
10752    
10753                                    QueryPos qPos = QueryPos.getInstance(q);
10754    
10755                                    qPos.add(nodeId);
10756    
10757                                    if (bindTitle) {
10758                                            qPos.add(title.toLowerCase());
10759                                    }
10760    
10761                                    qPos.add(status);
10762    
10763                                    if (!pagination) {
10764                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
10765                                                            start, end, false);
10766    
10767                                            Collections.sort(list);
10768    
10769                                            list = new UnmodifiableList<WikiPage>(list);
10770                                    }
10771                                    else {
10772                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
10773                                                            start, end);
10774                                    }
10775    
10776                                    cacheResult(list);
10777    
10778                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10779                            }
10780                            catch (Exception e) {
10781                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10782    
10783                                    throw processException(e);
10784                            }
10785                            finally {
10786                                    closeSession(session);
10787                            }
10788                    }
10789    
10790                    return list;
10791            }
10792    
10793            /**
10794             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
10795             *
10796             * @param nodeId the node ID
10797             * @param title the title
10798             * @param status the status
10799             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10800             * @return the first matching wiki page
10801             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
10802             * @throws SystemException if a system exception occurred
10803             */
10804            @Override
10805            public WikiPage findByN_T_S_First(long nodeId, String title, int status,
10806                    OrderByComparator orderByComparator)
10807                    throws NoSuchPageException, SystemException {
10808                    WikiPage wikiPage = fetchByN_T_S_First(nodeId, title, status,
10809                                    orderByComparator);
10810    
10811                    if (wikiPage != null) {
10812                            return wikiPage;
10813                    }
10814    
10815                    StringBundler msg = new StringBundler(8);
10816    
10817                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10818    
10819                    msg.append("nodeId=");
10820                    msg.append(nodeId);
10821    
10822                    msg.append(", title=");
10823                    msg.append(title);
10824    
10825                    msg.append(", status=");
10826                    msg.append(status);
10827    
10828                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10829    
10830                    throw new NoSuchPageException(msg.toString());
10831            }
10832    
10833            /**
10834             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
10835             *
10836             * @param nodeId the node ID
10837             * @param title the title
10838             * @param status the status
10839             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10840             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
10841             * @throws SystemException if a system exception occurred
10842             */
10843            @Override
10844            public WikiPage fetchByN_T_S_First(long nodeId, String title, int status,
10845                    OrderByComparator orderByComparator) throws SystemException {
10846                    List<WikiPage> list = findByN_T_S(nodeId, title, status, 0, 1,
10847                                    orderByComparator);
10848    
10849                    if (!list.isEmpty()) {
10850                            return list.get(0);
10851                    }
10852    
10853                    return null;
10854            }
10855    
10856            /**
10857             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
10858             *
10859             * @param nodeId the node ID
10860             * @param title the title
10861             * @param status the status
10862             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10863             * @return the last matching wiki page
10864             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
10865             * @throws SystemException if a system exception occurred
10866             */
10867            @Override
10868            public WikiPage findByN_T_S_Last(long nodeId, String title, int status,
10869                    OrderByComparator orderByComparator)
10870                    throws NoSuchPageException, SystemException {
10871                    WikiPage wikiPage = fetchByN_T_S_Last(nodeId, title, status,
10872                                    orderByComparator);
10873    
10874                    if (wikiPage != null) {
10875                            return wikiPage;
10876                    }
10877    
10878                    StringBundler msg = new StringBundler(8);
10879    
10880                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10881    
10882                    msg.append("nodeId=");
10883                    msg.append(nodeId);
10884    
10885                    msg.append(", title=");
10886                    msg.append(title);
10887    
10888                    msg.append(", status=");
10889                    msg.append(status);
10890    
10891                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10892    
10893                    throw new NoSuchPageException(msg.toString());
10894            }
10895    
10896            /**
10897             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
10898             *
10899             * @param nodeId the node ID
10900             * @param title the title
10901             * @param status the status
10902             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10903             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
10904             * @throws SystemException if a system exception occurred
10905             */
10906            @Override
10907            public WikiPage fetchByN_T_S_Last(long nodeId, String title, int status,
10908                    OrderByComparator orderByComparator) throws SystemException {
10909                    int count = countByN_T_S(nodeId, title, status);
10910    
10911                    if (count == 0) {
10912                            return null;
10913                    }
10914    
10915                    List<WikiPage> list = findByN_T_S(nodeId, title, status, count - 1,
10916                                    count, orderByComparator);
10917    
10918                    if (!list.isEmpty()) {
10919                            return list.get(0);
10920                    }
10921    
10922                    return null;
10923            }
10924    
10925            /**
10926             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
10927             *
10928             * @param pageId the primary key of the current wiki page
10929             * @param nodeId the node ID
10930             * @param title the title
10931             * @param status the status
10932             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10933             * @return the previous, current, and next wiki page
10934             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
10935             * @throws SystemException if a system exception occurred
10936             */
10937            @Override
10938            public WikiPage[] findByN_T_S_PrevAndNext(long pageId, long nodeId,
10939                    String title, int status, OrderByComparator orderByComparator)
10940                    throws NoSuchPageException, SystemException {
10941                    WikiPage wikiPage = findByPrimaryKey(pageId);
10942    
10943                    Session session = null;
10944    
10945                    try {
10946                            session = openSession();
10947    
10948                            WikiPage[] array = new WikiPageImpl[3];
10949    
10950                            array[0] = getByN_T_S_PrevAndNext(session, wikiPage, nodeId, title,
10951                                            status, orderByComparator, true);
10952    
10953                            array[1] = wikiPage;
10954    
10955                            array[2] = getByN_T_S_PrevAndNext(session, wikiPage, nodeId, title,
10956                                            status, orderByComparator, false);
10957    
10958                            return array;
10959                    }
10960                    catch (Exception e) {
10961                            throw processException(e);
10962                    }
10963                    finally {
10964                            closeSession(session);
10965                    }
10966            }
10967    
10968            protected WikiPage getByN_T_S_PrevAndNext(Session session,
10969                    WikiPage wikiPage, long nodeId, String title, int status,
10970                    OrderByComparator orderByComparator, boolean previous) {
10971                    StringBundler query = null;
10972    
10973                    if (orderByComparator != null) {
10974                            query = new StringBundler(6 +
10975                                            (orderByComparator.getOrderByFields().length * 6));
10976                    }
10977                    else {
10978                            query = new StringBundler(3);
10979                    }
10980    
10981                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
10982    
10983                    query.append(_FINDER_COLUMN_N_T_S_NODEID_2);
10984    
10985                    boolean bindTitle = false;
10986    
10987                    if (title == null) {
10988                            query.append(_FINDER_COLUMN_N_T_S_TITLE_1);
10989                    }
10990                    else if (title.equals(StringPool.BLANK)) {
10991                            query.append(_FINDER_COLUMN_N_T_S_TITLE_3);
10992                    }
10993                    else {
10994                            bindTitle = true;
10995    
10996                            query.append(_FINDER_COLUMN_N_T_S_TITLE_2);
10997                    }
10998    
10999                    query.append(_FINDER_COLUMN_N_T_S_STATUS_2);
11000    
11001                    if (orderByComparator != null) {
11002                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11003    
11004                            if (orderByConditionFields.length > 0) {
11005                                    query.append(WHERE_AND);
11006                            }
11007    
11008                            for (int i = 0; i < orderByConditionFields.length; i++) {
11009                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11010                                    query.append(orderByConditionFields[i]);
11011    
11012                                    if ((i + 1) < orderByConditionFields.length) {
11013                                            if (orderByComparator.isAscending() ^ previous) {
11014                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11015                                            }
11016                                            else {
11017                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11018                                            }
11019                                    }
11020                                    else {
11021                                            if (orderByComparator.isAscending() ^ previous) {
11022                                                    query.append(WHERE_GREATER_THAN);
11023                                            }
11024                                            else {
11025                                                    query.append(WHERE_LESSER_THAN);
11026                                            }
11027                                    }
11028                            }
11029    
11030                            query.append(ORDER_BY_CLAUSE);
11031    
11032                            String[] orderByFields = orderByComparator.getOrderByFields();
11033    
11034                            for (int i = 0; i < orderByFields.length; i++) {
11035                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11036                                    query.append(orderByFields[i]);
11037    
11038                                    if ((i + 1) < orderByFields.length) {
11039                                            if (orderByComparator.isAscending() ^ previous) {
11040                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11041                                            }
11042                                            else {
11043                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11044                                            }
11045                                    }
11046                                    else {
11047                                            if (orderByComparator.isAscending() ^ previous) {
11048                                                    query.append(ORDER_BY_ASC);
11049                                            }
11050                                            else {
11051                                                    query.append(ORDER_BY_DESC);
11052                                            }
11053                                    }
11054                            }
11055                    }
11056                    else {
11057                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
11058                    }
11059    
11060                    String sql = query.toString();
11061    
11062                    Query q = session.createQuery(sql);
11063    
11064                    q.setFirstResult(0);
11065                    q.setMaxResults(2);
11066    
11067                    QueryPos qPos = QueryPos.getInstance(q);
11068    
11069                    qPos.add(nodeId);
11070    
11071                    if (bindTitle) {
11072                            qPos.add(title.toLowerCase());
11073                    }
11074    
11075                    qPos.add(status);
11076    
11077                    if (orderByComparator != null) {
11078                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
11079    
11080                            for (Object value : values) {
11081                                    qPos.add(value);
11082                            }
11083                    }
11084    
11085                    List<WikiPage> list = q.list();
11086    
11087                    if (list.size() == 2) {
11088                            return list.get(1);
11089                    }
11090                    else {
11091                            return null;
11092                    }
11093            }
11094    
11095            /**
11096             * Removes all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63; from the database.
11097             *
11098             * @param nodeId the node ID
11099             * @param title the title
11100             * @param status the status
11101             * @throws SystemException if a system exception occurred
11102             */
11103            @Override
11104            public void removeByN_T_S(long nodeId, String title, int status)
11105                    throws SystemException {
11106                    for (WikiPage wikiPage : findByN_T_S(nodeId, title, status,
11107                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11108                            remove(wikiPage);
11109                    }
11110            }
11111    
11112            /**
11113             * Returns the number of wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
11114             *
11115             * @param nodeId the node ID
11116             * @param title the title
11117             * @param status the status
11118             * @return the number of matching wiki pages
11119             * @throws SystemException if a system exception occurred
11120             */
11121            @Override
11122            public int countByN_T_S(long nodeId, String title, int status)
11123                    throws SystemException {
11124                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T_S;
11125    
11126                    Object[] finderArgs = new Object[] { nodeId, title, status };
11127    
11128                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11129                                    this);
11130    
11131                    if (count == null) {
11132                            StringBundler query = new StringBundler(4);
11133    
11134                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
11135    
11136                            query.append(_FINDER_COLUMN_N_T_S_NODEID_2);
11137    
11138                            boolean bindTitle = false;
11139    
11140                            if (title == null) {
11141                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_1);
11142                            }
11143                            else if (title.equals(StringPool.BLANK)) {
11144                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_3);
11145                            }
11146                            else {
11147                                    bindTitle = true;
11148    
11149                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_2);
11150                            }
11151    
11152                            query.append(_FINDER_COLUMN_N_T_S_STATUS_2);
11153    
11154                            String sql = query.toString();
11155    
11156                            Session session = null;
11157    
11158                            try {
11159                                    session = openSession();
11160    
11161                                    Query q = session.createQuery(sql);
11162    
11163                                    QueryPos qPos = QueryPos.getInstance(q);
11164    
11165                                    qPos.add(nodeId);
11166    
11167                                    if (bindTitle) {
11168                                            qPos.add(title.toLowerCase());
11169                                    }
11170    
11171                                    qPos.add(status);
11172    
11173                                    count = (Long)q.uniqueResult();
11174    
11175                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
11176                            }
11177                            catch (Exception e) {
11178                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11179    
11180                                    throw processException(e);
11181                            }
11182                            finally {
11183                                    closeSession(session);
11184                            }
11185                    }
11186    
11187                    return count.intValue();
11188            }
11189    
11190            private static final String _FINDER_COLUMN_N_T_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
11191            private static final String _FINDER_COLUMN_N_T_S_TITLE_1 = "wikiPage.title IS NULL AND ";
11192            private static final String _FINDER_COLUMN_N_T_S_TITLE_2 = "lower(wikiPage.title) = ? AND ";
11193            private static final String _FINDER_COLUMN_N_T_S_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '') AND ";
11194            private static final String _FINDER_COLUMN_N_T_S_STATUS_2 = "wikiPage.status = ?";
11195            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11196                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
11197                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_P",
11198                            new String[] {
11199                                    Long.class.getName(), Boolean.class.getName(),
11200                                    String.class.getName(),
11201                                    
11202                            Integer.class.getName(), Integer.class.getName(),
11203                                    OrderByComparator.class.getName()
11204                            });
11205            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11206                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
11207                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_P",
11208                            new String[] {
11209                                    Long.class.getName(), Boolean.class.getName(),
11210                                    String.class.getName()
11211                            },
11212                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
11213                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
11214                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
11215                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
11216                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
11217            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11218                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11219                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_P",
11220                            new String[] {
11221                                    Long.class.getName(), Boolean.class.getName(),
11222                                    String.class.getName()
11223                            });
11224    
11225            /**
11226             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11227             *
11228             * @param nodeId the node ID
11229             * @param head the head
11230             * @param parentTitle the parent title
11231             * @return the matching wiki pages
11232             * @throws SystemException if a system exception occurred
11233             */
11234            @Override
11235            public List<WikiPage> findByN_H_P(long nodeId, boolean head,
11236                    String parentTitle) throws SystemException {
11237                    return findByN_H_P(nodeId, head, parentTitle, QueryUtil.ALL_POS,
11238                            QueryUtil.ALL_POS, null);
11239            }
11240    
11241            /**
11242             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11243             *
11244             * <p>
11245             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11246             * </p>
11247             *
11248             * @param nodeId the node ID
11249             * @param head the head
11250             * @param parentTitle the parent title
11251             * @param start the lower bound of the range of wiki pages
11252             * @param end the upper bound of the range of wiki pages (not inclusive)
11253             * @return the range of matching wiki pages
11254             * @throws SystemException if a system exception occurred
11255             */
11256            @Override
11257            public List<WikiPage> findByN_H_P(long nodeId, boolean head,
11258                    String parentTitle, int start, int end) throws SystemException {
11259                    return findByN_H_P(nodeId, head, parentTitle, start, end, null);
11260            }
11261    
11262            /**
11263             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11264             *
11265             * <p>
11266             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11267             * </p>
11268             *
11269             * @param nodeId the node ID
11270             * @param head the head
11271             * @param parentTitle the parent title
11272             * @param start the lower bound of the range of wiki pages
11273             * @param end the upper bound of the range of wiki pages (not inclusive)
11274             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11275             * @return the ordered range of matching wiki pages
11276             * @throws SystemException if a system exception occurred
11277             */
11278            @Override
11279            public List<WikiPage> findByN_H_P(long nodeId, boolean head,
11280                    String parentTitle, int start, int end,
11281                    OrderByComparator orderByComparator) throws SystemException {
11282                    boolean pagination = true;
11283                    FinderPath finderPath = null;
11284                    Object[] finderArgs = null;
11285    
11286                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11287                                    (orderByComparator == null)) {
11288                            pagination = false;
11289                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P;
11290                            finderArgs = new Object[] { nodeId, head, parentTitle };
11291                    }
11292                    else {
11293                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P;
11294                            finderArgs = new Object[] {
11295                                            nodeId, head, parentTitle,
11296                                            
11297                                            start, end, orderByComparator
11298                                    };
11299                    }
11300    
11301                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
11302                                    finderArgs, this);
11303    
11304                    if ((list != null) && !list.isEmpty()) {
11305                            for (WikiPage wikiPage : list) {
11306                                    if ((nodeId != wikiPage.getNodeId()) ||
11307                                                    (head != wikiPage.getHead()) ||
11308                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle())) {
11309                                            list = null;
11310    
11311                                            break;
11312                                    }
11313                            }
11314                    }
11315    
11316                    if (list == null) {
11317                            StringBundler query = null;
11318    
11319                            if (orderByComparator != null) {
11320                                    query = new StringBundler(5 +
11321                                                    (orderByComparator.getOrderByFields().length * 3));
11322                            }
11323                            else {
11324                                    query = new StringBundler(5);
11325                            }
11326    
11327                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
11328    
11329                            query.append(_FINDER_COLUMN_N_H_P_NODEID_2);
11330    
11331                            query.append(_FINDER_COLUMN_N_H_P_HEAD_2);
11332    
11333                            boolean bindParentTitle = false;
11334    
11335                            if (parentTitle == null) {
11336                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_1);
11337                            }
11338                            else if (parentTitle.equals(StringPool.BLANK)) {
11339                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_3);
11340                            }
11341                            else {
11342                                    bindParentTitle = true;
11343    
11344                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_2);
11345                            }
11346    
11347                            if (orderByComparator != null) {
11348                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11349                                            orderByComparator);
11350                            }
11351                            else
11352                             if (pagination) {
11353                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
11354                            }
11355    
11356                            String sql = query.toString();
11357    
11358                            Session session = null;
11359    
11360                            try {
11361                                    session = openSession();
11362    
11363                                    Query q = session.createQuery(sql);
11364    
11365                                    QueryPos qPos = QueryPos.getInstance(q);
11366    
11367                                    qPos.add(nodeId);
11368    
11369                                    qPos.add(head);
11370    
11371                                    if (bindParentTitle) {
11372                                            qPos.add(parentTitle.toLowerCase());
11373                                    }
11374    
11375                                    if (!pagination) {
11376                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11377                                                            start, end, false);
11378    
11379                                            Collections.sort(list);
11380    
11381                                            list = new UnmodifiableList<WikiPage>(list);
11382                                    }
11383                                    else {
11384                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11385                                                            start, end);
11386                                    }
11387    
11388                                    cacheResult(list);
11389    
11390                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11391                            }
11392                            catch (Exception e) {
11393                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11394    
11395                                    throw processException(e);
11396                            }
11397                            finally {
11398                                    closeSession(session);
11399                            }
11400                    }
11401    
11402                    return list;
11403            }
11404    
11405            /**
11406             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11407             *
11408             * @param nodeId the node ID
11409             * @param head the head
11410             * @param parentTitle the parent title
11411             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11412             * @return the first matching wiki page
11413             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
11414             * @throws SystemException if a system exception occurred
11415             */
11416            @Override
11417            public WikiPage findByN_H_P_First(long nodeId, boolean head,
11418                    String parentTitle, OrderByComparator orderByComparator)
11419                    throws NoSuchPageException, SystemException {
11420                    WikiPage wikiPage = fetchByN_H_P_First(nodeId, head, parentTitle,
11421                                    orderByComparator);
11422    
11423                    if (wikiPage != null) {
11424                            return wikiPage;
11425                    }
11426    
11427                    StringBundler msg = new StringBundler(8);
11428    
11429                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11430    
11431                    msg.append("nodeId=");
11432                    msg.append(nodeId);
11433    
11434                    msg.append(", head=");
11435                    msg.append(head);
11436    
11437                    msg.append(", parentTitle=");
11438                    msg.append(parentTitle);
11439    
11440                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11441    
11442                    throw new NoSuchPageException(msg.toString());
11443            }
11444    
11445            /**
11446             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11447             *
11448             * @param nodeId the node ID
11449             * @param head the head
11450             * @param parentTitle the parent title
11451             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11452             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
11453             * @throws SystemException if a system exception occurred
11454             */
11455            @Override
11456            public WikiPage fetchByN_H_P_First(long nodeId, boolean head,
11457                    String parentTitle, OrderByComparator orderByComparator)
11458                    throws SystemException {
11459                    List<WikiPage> list = findByN_H_P(nodeId, head, parentTitle, 0, 1,
11460                                    orderByComparator);
11461    
11462                    if (!list.isEmpty()) {
11463                            return list.get(0);
11464                    }
11465    
11466                    return null;
11467            }
11468    
11469            /**
11470             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11471             *
11472             * @param nodeId the node ID
11473             * @param head the head
11474             * @param parentTitle the parent title
11475             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11476             * @return the last matching wiki page
11477             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
11478             * @throws SystemException if a system exception occurred
11479             */
11480            @Override
11481            public WikiPage findByN_H_P_Last(long nodeId, boolean head,
11482                    String parentTitle, OrderByComparator orderByComparator)
11483                    throws NoSuchPageException, SystemException {
11484                    WikiPage wikiPage = fetchByN_H_P_Last(nodeId, head, parentTitle,
11485                                    orderByComparator);
11486    
11487                    if (wikiPage != null) {
11488                            return wikiPage;
11489                    }
11490    
11491                    StringBundler msg = new StringBundler(8);
11492    
11493                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11494    
11495                    msg.append("nodeId=");
11496                    msg.append(nodeId);
11497    
11498                    msg.append(", head=");
11499                    msg.append(head);
11500    
11501                    msg.append(", parentTitle=");
11502                    msg.append(parentTitle);
11503    
11504                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11505    
11506                    throw new NoSuchPageException(msg.toString());
11507            }
11508    
11509            /**
11510             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11511             *
11512             * @param nodeId the node ID
11513             * @param head the head
11514             * @param parentTitle the parent title
11515             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11516             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
11517             * @throws SystemException if a system exception occurred
11518             */
11519            @Override
11520            public WikiPage fetchByN_H_P_Last(long nodeId, boolean head,
11521                    String parentTitle, OrderByComparator orderByComparator)
11522                    throws SystemException {
11523                    int count = countByN_H_P(nodeId, head, parentTitle);
11524    
11525                    if (count == 0) {
11526                            return null;
11527                    }
11528    
11529                    List<WikiPage> list = findByN_H_P(nodeId, head, parentTitle, count - 1,
11530                                    count, orderByComparator);
11531    
11532                    if (!list.isEmpty()) {
11533                            return list.get(0);
11534                    }
11535    
11536                    return null;
11537            }
11538    
11539            /**
11540             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11541             *
11542             * @param pageId the primary key of the current wiki page
11543             * @param nodeId the node ID
11544             * @param head the head
11545             * @param parentTitle the parent title
11546             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11547             * @return the previous, current, and next wiki page
11548             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
11549             * @throws SystemException if a system exception occurred
11550             */
11551            @Override
11552            public WikiPage[] findByN_H_P_PrevAndNext(long pageId, long nodeId,
11553                    boolean head, String parentTitle, OrderByComparator orderByComparator)
11554                    throws NoSuchPageException, SystemException {
11555                    WikiPage wikiPage = findByPrimaryKey(pageId);
11556    
11557                    Session session = null;
11558    
11559                    try {
11560                            session = openSession();
11561    
11562                            WikiPage[] array = new WikiPageImpl[3];
11563    
11564                            array[0] = getByN_H_P_PrevAndNext(session, wikiPage, nodeId, head,
11565                                            parentTitle, orderByComparator, true);
11566    
11567                            array[1] = wikiPage;
11568    
11569                            array[2] = getByN_H_P_PrevAndNext(session, wikiPage, nodeId, head,
11570                                            parentTitle, orderByComparator, false);
11571    
11572                            return array;
11573                    }
11574                    catch (Exception e) {
11575                            throw processException(e);
11576                    }
11577                    finally {
11578                            closeSession(session);
11579                    }
11580            }
11581    
11582            protected WikiPage getByN_H_P_PrevAndNext(Session session,
11583                    WikiPage wikiPage, long nodeId, boolean head, String parentTitle,
11584                    OrderByComparator orderByComparator, boolean previous) {
11585                    StringBundler query = null;
11586    
11587                    if (orderByComparator != null) {
11588                            query = new StringBundler(6 +
11589                                            (orderByComparator.getOrderByFields().length * 6));
11590                    }
11591                    else {
11592                            query = new StringBundler(3);
11593                    }
11594    
11595                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
11596    
11597                    query.append(_FINDER_COLUMN_N_H_P_NODEID_2);
11598    
11599                    query.append(_FINDER_COLUMN_N_H_P_HEAD_2);
11600    
11601                    boolean bindParentTitle = false;
11602    
11603                    if (parentTitle == null) {
11604                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_1);
11605                    }
11606                    else if (parentTitle.equals(StringPool.BLANK)) {
11607                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_3);
11608                    }
11609                    else {
11610                            bindParentTitle = true;
11611    
11612                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_2);
11613                    }
11614    
11615                    if (orderByComparator != null) {
11616                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11617    
11618                            if (orderByConditionFields.length > 0) {
11619                                    query.append(WHERE_AND);
11620                            }
11621    
11622                            for (int i = 0; i < orderByConditionFields.length; i++) {
11623                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11624                                    query.append(orderByConditionFields[i]);
11625    
11626                                    if ((i + 1) < orderByConditionFields.length) {
11627                                            if (orderByComparator.isAscending() ^ previous) {
11628                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11629                                            }
11630                                            else {
11631                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11632                                            }
11633                                    }
11634                                    else {
11635                                            if (orderByComparator.isAscending() ^ previous) {
11636                                                    query.append(WHERE_GREATER_THAN);
11637                                            }
11638                                            else {
11639                                                    query.append(WHERE_LESSER_THAN);
11640                                            }
11641                                    }
11642                            }
11643    
11644                            query.append(ORDER_BY_CLAUSE);
11645    
11646                            String[] orderByFields = orderByComparator.getOrderByFields();
11647    
11648                            for (int i = 0; i < orderByFields.length; i++) {
11649                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11650                                    query.append(orderByFields[i]);
11651    
11652                                    if ((i + 1) < orderByFields.length) {
11653                                            if (orderByComparator.isAscending() ^ previous) {
11654                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11655                                            }
11656                                            else {
11657                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11658                                            }
11659                                    }
11660                                    else {
11661                                            if (orderByComparator.isAscending() ^ previous) {
11662                                                    query.append(ORDER_BY_ASC);
11663                                            }
11664                                            else {
11665                                                    query.append(ORDER_BY_DESC);
11666                                            }
11667                                    }
11668                            }
11669                    }
11670                    else {
11671                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
11672                    }
11673    
11674                    String sql = query.toString();
11675    
11676                    Query q = session.createQuery(sql);
11677    
11678                    q.setFirstResult(0);
11679                    q.setMaxResults(2);
11680    
11681                    QueryPos qPos = QueryPos.getInstance(q);
11682    
11683                    qPos.add(nodeId);
11684    
11685                    qPos.add(head);
11686    
11687                    if (bindParentTitle) {
11688                            qPos.add(parentTitle.toLowerCase());
11689                    }
11690    
11691                    if (orderByComparator != null) {
11692                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
11693    
11694                            for (Object value : values) {
11695                                    qPos.add(value);
11696                            }
11697                    }
11698    
11699                    List<WikiPage> list = q.list();
11700    
11701                    if (list.size() == 2) {
11702                            return list.get(1);
11703                    }
11704                    else {
11705                            return null;
11706                    }
11707            }
11708    
11709            /**
11710             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; from the database.
11711             *
11712             * @param nodeId the node ID
11713             * @param head the head
11714             * @param parentTitle the parent title
11715             * @throws SystemException if a system exception occurred
11716             */
11717            @Override
11718            public void removeByN_H_P(long nodeId, boolean head, String parentTitle)
11719                    throws SystemException {
11720                    for (WikiPage wikiPage : findByN_H_P(nodeId, head, parentTitle,
11721                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11722                            remove(wikiPage);
11723                    }
11724            }
11725    
11726            /**
11727             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11728             *
11729             * @param nodeId the node ID
11730             * @param head the head
11731             * @param parentTitle the parent title
11732             * @return the number of matching wiki pages
11733             * @throws SystemException if a system exception occurred
11734             */
11735            @Override
11736            public int countByN_H_P(long nodeId, boolean head, String parentTitle)
11737                    throws SystemException {
11738                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_P;
11739    
11740                    Object[] finderArgs = new Object[] { nodeId, head, parentTitle };
11741    
11742                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11743                                    this);
11744    
11745                    if (count == null) {
11746                            StringBundler query = new StringBundler(4);
11747    
11748                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
11749    
11750                            query.append(_FINDER_COLUMN_N_H_P_NODEID_2);
11751    
11752                            query.append(_FINDER_COLUMN_N_H_P_HEAD_2);
11753    
11754                            boolean bindParentTitle = false;
11755    
11756                            if (parentTitle == null) {
11757                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_1);
11758                            }
11759                            else if (parentTitle.equals(StringPool.BLANK)) {
11760                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_3);
11761                            }
11762                            else {
11763                                    bindParentTitle = true;
11764    
11765                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_2);
11766                            }
11767    
11768                            String sql = query.toString();
11769    
11770                            Session session = null;
11771    
11772                            try {
11773                                    session = openSession();
11774    
11775                                    Query q = session.createQuery(sql);
11776    
11777                                    QueryPos qPos = QueryPos.getInstance(q);
11778    
11779                                    qPos.add(nodeId);
11780    
11781                                    qPos.add(head);
11782    
11783                                    if (bindParentTitle) {
11784                                            qPos.add(parentTitle.toLowerCase());
11785                                    }
11786    
11787                                    count = (Long)q.uniqueResult();
11788    
11789                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
11790                            }
11791                            catch (Exception e) {
11792                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11793    
11794                                    throw processException(e);
11795                            }
11796                            finally {
11797                                    closeSession(session);
11798                            }
11799                    }
11800    
11801                    return count.intValue();
11802            }
11803    
11804            private static final String _FINDER_COLUMN_N_H_P_NODEID_2 = "wikiPage.nodeId = ? AND ";
11805            private static final String _FINDER_COLUMN_N_H_P_HEAD_2 = "wikiPage.head = ? AND ";
11806            private static final String _FINDER_COLUMN_N_H_P_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL";
11807            private static final String _FINDER_COLUMN_N_H_P_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ?";
11808            private static final String _FINDER_COLUMN_N_H_P_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '')";
11809            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11810                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
11811                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_S",
11812                            new String[] {
11813                                    Long.class.getName(), Boolean.class.getName(),
11814                                    Integer.class.getName(),
11815                                    
11816                            Integer.class.getName(), Integer.class.getName(),
11817                                    OrderByComparator.class.getName()
11818                            });
11819            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11820                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
11821                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_S",
11822                            new String[] {
11823                                    Long.class.getName(), Boolean.class.getName(),
11824                                    Integer.class.getName()
11825                            },
11826                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
11827                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
11828                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
11829                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
11830                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
11831            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11832                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11833                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_S",
11834                            new String[] {
11835                                    Long.class.getName(), Boolean.class.getName(),
11836                                    Integer.class.getName()
11837                            });
11838    
11839            /**
11840             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
11841             *
11842             * @param nodeId the node ID
11843             * @param head the head
11844             * @param status the status
11845             * @return the matching wiki pages
11846             * @throws SystemException if a system exception occurred
11847             */
11848            @Override
11849            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status)
11850                    throws SystemException {
11851                    return findByN_H_S(nodeId, head, status, QueryUtil.ALL_POS,
11852                            QueryUtil.ALL_POS, null);
11853            }
11854    
11855            /**
11856             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
11857             *
11858             * <p>
11859             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11860             * </p>
11861             *
11862             * @param nodeId the node ID
11863             * @param head the head
11864             * @param status the status
11865             * @param start the lower bound of the range of wiki pages
11866             * @param end the upper bound of the range of wiki pages (not inclusive)
11867             * @return the range of matching wiki pages
11868             * @throws SystemException if a system exception occurred
11869             */
11870            @Override
11871            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status,
11872                    int start, int end) throws SystemException {
11873                    return findByN_H_S(nodeId, head, status, start, end, null);
11874            }
11875    
11876            /**
11877             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
11878             *
11879             * <p>
11880             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11881             * </p>
11882             *
11883             * @param nodeId the node ID
11884             * @param head the head
11885             * @param status the status
11886             * @param start the lower bound of the range of wiki pages
11887             * @param end the upper bound of the range of wiki pages (not inclusive)
11888             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11889             * @return the ordered range of matching wiki pages
11890             * @throws SystemException if a system exception occurred
11891             */
11892            @Override
11893            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status,
11894                    int start, int end, OrderByComparator orderByComparator)
11895                    throws SystemException {
11896                    boolean pagination = true;
11897                    FinderPath finderPath = null;
11898                    Object[] finderArgs = null;
11899    
11900                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11901                                    (orderByComparator == null)) {
11902                            pagination = false;
11903                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S;
11904                            finderArgs = new Object[] { nodeId, head, status };
11905                    }
11906                    else {
11907                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_S;
11908                            finderArgs = new Object[] {
11909                                            nodeId, head, status,
11910                                            
11911                                            start, end, orderByComparator
11912                                    };
11913                    }
11914    
11915                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
11916                                    finderArgs, this);
11917    
11918                    if ((list != null) && !list.isEmpty()) {
11919                            for (WikiPage wikiPage : list) {
11920                                    if ((nodeId != wikiPage.getNodeId()) ||
11921                                                    (head != wikiPage.getHead()) ||
11922                                                    (status != wikiPage.getStatus())) {
11923                                            list = null;
11924    
11925                                            break;
11926                                    }
11927                            }
11928                    }
11929    
11930                    if (list == null) {
11931                            StringBundler query = null;
11932    
11933                            if (orderByComparator != null) {
11934                                    query = new StringBundler(5 +
11935                                                    (orderByComparator.getOrderByFields().length * 3));
11936                            }
11937                            else {
11938                                    query = new StringBundler(5);
11939                            }
11940    
11941                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
11942    
11943                            query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
11944    
11945                            query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
11946    
11947                            query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
11948    
11949                            if (orderByComparator != null) {
11950                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11951                                            orderByComparator);
11952                            }
11953                            else
11954                             if (pagination) {
11955                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
11956                            }
11957    
11958                            String sql = query.toString();
11959    
11960                            Session session = null;
11961    
11962                            try {
11963                                    session = openSession();
11964    
11965                                    Query q = session.createQuery(sql);
11966    
11967                                    QueryPos qPos = QueryPos.getInstance(q);
11968    
11969                                    qPos.add(nodeId);
11970    
11971                                    qPos.add(head);
11972    
11973                                    qPos.add(status);
11974    
11975                                    if (!pagination) {
11976                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11977                                                            start, end, false);
11978    
11979                                            Collections.sort(list);
11980    
11981                                            list = new UnmodifiableList<WikiPage>(list);
11982                                    }
11983                                    else {
11984                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11985                                                            start, end);
11986                                    }
11987    
11988                                    cacheResult(list);
11989    
11990                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11991                            }
11992                            catch (Exception e) {
11993                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11994    
11995                                    throw processException(e);
11996                            }
11997                            finally {
11998                                    closeSession(session);
11999                            }
12000                    }
12001    
12002                    return list;
12003            }
12004    
12005            /**
12006             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
12007             *
12008             * @param nodeId the node ID
12009             * @param head the head
12010             * @param status the status
12011             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12012             * @return the first matching wiki page
12013             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
12014             * @throws SystemException if a system exception occurred
12015             */
12016            @Override
12017            public WikiPage findByN_H_S_First(long nodeId, boolean head, int status,
12018                    OrderByComparator orderByComparator)
12019                    throws NoSuchPageException, SystemException {
12020                    WikiPage wikiPage = fetchByN_H_S_First(nodeId, head, status,
12021                                    orderByComparator);
12022    
12023                    if (wikiPage != null) {
12024                            return wikiPage;
12025                    }
12026    
12027                    StringBundler msg = new StringBundler(8);
12028    
12029                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12030    
12031                    msg.append("nodeId=");
12032                    msg.append(nodeId);
12033    
12034                    msg.append(", head=");
12035                    msg.append(head);
12036    
12037                    msg.append(", status=");
12038                    msg.append(status);
12039    
12040                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12041    
12042                    throw new NoSuchPageException(msg.toString());
12043            }
12044    
12045            /**
12046             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
12047             *
12048             * @param nodeId the node ID
12049             * @param head the head
12050             * @param status the status
12051             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12052             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
12053             * @throws SystemException if a system exception occurred
12054             */
12055            @Override
12056            public WikiPage fetchByN_H_S_First(long nodeId, boolean head, int status,
12057                    OrderByComparator orderByComparator) throws SystemException {
12058                    List<WikiPage> list = findByN_H_S(nodeId, head, status, 0, 1,
12059                                    orderByComparator);
12060    
12061                    if (!list.isEmpty()) {
12062                            return list.get(0);
12063                    }
12064    
12065                    return null;
12066            }
12067    
12068            /**
12069             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
12070             *
12071             * @param nodeId the node ID
12072             * @param head the head
12073             * @param status the status
12074             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12075             * @return the last matching wiki page
12076             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
12077             * @throws SystemException if a system exception occurred
12078             */
12079            @Override
12080            public WikiPage findByN_H_S_Last(long nodeId, boolean head, int status,
12081                    OrderByComparator orderByComparator)
12082                    throws NoSuchPageException, SystemException {
12083                    WikiPage wikiPage = fetchByN_H_S_Last(nodeId, head, status,
12084                                    orderByComparator);
12085    
12086                    if (wikiPage != null) {
12087                            return wikiPage;
12088                    }
12089    
12090                    StringBundler msg = new StringBundler(8);
12091    
12092                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12093    
12094                    msg.append("nodeId=");
12095                    msg.append(nodeId);
12096    
12097                    msg.append(", head=");
12098                    msg.append(head);
12099    
12100                    msg.append(", status=");
12101                    msg.append(status);
12102    
12103                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12104    
12105                    throw new NoSuchPageException(msg.toString());
12106            }
12107    
12108            /**
12109             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
12110             *
12111             * @param nodeId the node ID
12112             * @param head the head
12113             * @param status the status
12114             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12115             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
12116             * @throws SystemException if a system exception occurred
12117             */
12118            @Override
12119            public WikiPage fetchByN_H_S_Last(long nodeId, boolean head, int status,
12120                    OrderByComparator orderByComparator) throws SystemException {
12121                    int count = countByN_H_S(nodeId, head, status);
12122    
12123                    if (count == 0) {
12124                            return null;
12125                    }
12126    
12127                    List<WikiPage> list = findByN_H_S(nodeId, head, status, count - 1,
12128                                    count, orderByComparator);
12129    
12130                    if (!list.isEmpty()) {
12131                            return list.get(0);
12132                    }
12133    
12134                    return null;
12135            }
12136    
12137            /**
12138             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
12139             *
12140             * @param pageId the primary key of the current wiki page
12141             * @param nodeId the node ID
12142             * @param head the head
12143             * @param status the status
12144             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12145             * @return the previous, current, and next wiki page
12146             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
12147             * @throws SystemException if a system exception occurred
12148             */
12149            @Override
12150            public WikiPage[] findByN_H_S_PrevAndNext(long pageId, long nodeId,
12151                    boolean head, int status, OrderByComparator orderByComparator)
12152                    throws NoSuchPageException, SystemException {
12153                    WikiPage wikiPage = findByPrimaryKey(pageId);
12154    
12155                    Session session = null;
12156    
12157                    try {
12158                            session = openSession();
12159    
12160                            WikiPage[] array = new WikiPageImpl[3];
12161    
12162                            array[0] = getByN_H_S_PrevAndNext(session, wikiPage, nodeId, head,
12163                                            status, orderByComparator, true);
12164    
12165                            array[1] = wikiPage;
12166    
12167                            array[2] = getByN_H_S_PrevAndNext(session, wikiPage, nodeId, head,
12168                                            status, orderByComparator, false);
12169    
12170                            return array;
12171                    }
12172                    catch (Exception e) {
12173                            throw processException(e);
12174                    }
12175                    finally {
12176                            closeSession(session);
12177                    }
12178            }
12179    
12180            protected WikiPage getByN_H_S_PrevAndNext(Session session,
12181                    WikiPage wikiPage, long nodeId, boolean head, int status,
12182                    OrderByComparator orderByComparator, boolean previous) {
12183                    StringBundler query = null;
12184    
12185                    if (orderByComparator != null) {
12186                            query = new StringBundler(6 +
12187                                            (orderByComparator.getOrderByFields().length * 6));
12188                    }
12189                    else {
12190                            query = new StringBundler(3);
12191                    }
12192    
12193                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
12194    
12195                    query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
12196    
12197                    query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
12198    
12199                    query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
12200    
12201                    if (orderByComparator != null) {
12202                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12203    
12204                            if (orderByConditionFields.length > 0) {
12205                                    query.append(WHERE_AND);
12206                            }
12207    
12208                            for (int i = 0; i < orderByConditionFields.length; i++) {
12209                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12210                                    query.append(orderByConditionFields[i]);
12211    
12212                                    if ((i + 1) < orderByConditionFields.length) {
12213                                            if (orderByComparator.isAscending() ^ previous) {
12214                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12215                                            }
12216                                            else {
12217                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12218                                            }
12219                                    }
12220                                    else {
12221                                            if (orderByComparator.isAscending() ^ previous) {
12222                                                    query.append(WHERE_GREATER_THAN);
12223                                            }
12224                                            else {
12225                                                    query.append(WHERE_LESSER_THAN);
12226                                            }
12227                                    }
12228                            }
12229    
12230                            query.append(ORDER_BY_CLAUSE);
12231    
12232                            String[] orderByFields = orderByComparator.getOrderByFields();
12233    
12234                            for (int i = 0; i < orderByFields.length; i++) {
12235                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12236                                    query.append(orderByFields[i]);
12237    
12238                                    if ((i + 1) < orderByFields.length) {
12239                                            if (orderByComparator.isAscending() ^ previous) {
12240                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12241                                            }
12242                                            else {
12243                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12244                                            }
12245                                    }
12246                                    else {
12247                                            if (orderByComparator.isAscending() ^ previous) {
12248                                                    query.append(ORDER_BY_ASC);
12249                                            }
12250                                            else {
12251                                                    query.append(ORDER_BY_DESC);
12252                                            }
12253                                    }
12254                            }
12255                    }
12256                    else {
12257                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12258                    }
12259    
12260                    String sql = query.toString();
12261    
12262                    Query q = session.createQuery(sql);
12263    
12264                    q.setFirstResult(0);
12265                    q.setMaxResults(2);
12266    
12267                    QueryPos qPos = QueryPos.getInstance(q);
12268    
12269                    qPos.add(nodeId);
12270    
12271                    qPos.add(head);
12272    
12273                    qPos.add(status);
12274    
12275                    if (orderByComparator != null) {
12276                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
12277    
12278                            for (Object value : values) {
12279                                    qPos.add(value);
12280                            }
12281                    }
12282    
12283                    List<WikiPage> list = q.list();
12284    
12285                    if (list.size() == 2) {
12286                            return list.get(1);
12287                    }
12288                    else {
12289                            return null;
12290                    }
12291            }
12292    
12293            /**
12294             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63; from the database.
12295             *
12296             * @param nodeId the node ID
12297             * @param head the head
12298             * @param status the status
12299             * @throws SystemException if a system exception occurred
12300             */
12301            @Override
12302            public void removeByN_H_S(long nodeId, boolean head, int status)
12303                    throws SystemException {
12304                    for (WikiPage wikiPage : findByN_H_S(nodeId, head, status,
12305                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12306                            remove(wikiPage);
12307                    }
12308            }
12309    
12310            /**
12311             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
12312             *
12313             * @param nodeId the node ID
12314             * @param head the head
12315             * @param status the status
12316             * @return the number of matching wiki pages
12317             * @throws SystemException if a system exception occurred
12318             */
12319            @Override
12320            public int countByN_H_S(long nodeId, boolean head, int status)
12321                    throws SystemException {
12322                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_S;
12323    
12324                    Object[] finderArgs = new Object[] { nodeId, head, status };
12325    
12326                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12327                                    this);
12328    
12329                    if (count == null) {
12330                            StringBundler query = new StringBundler(4);
12331    
12332                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
12333    
12334                            query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
12335    
12336                            query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
12337    
12338                            query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
12339    
12340                            String sql = query.toString();
12341    
12342                            Session session = null;
12343    
12344                            try {
12345                                    session = openSession();
12346    
12347                                    Query q = session.createQuery(sql);
12348    
12349                                    QueryPos qPos = QueryPos.getInstance(q);
12350    
12351                                    qPos.add(nodeId);
12352    
12353                                    qPos.add(head);
12354    
12355                                    qPos.add(status);
12356    
12357                                    count = (Long)q.uniqueResult();
12358    
12359                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
12360                            }
12361                            catch (Exception e) {
12362                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12363    
12364                                    throw processException(e);
12365                            }
12366                            finally {
12367                                    closeSession(session);
12368                            }
12369                    }
12370    
12371                    return count.intValue();
12372            }
12373    
12374            private static final String _FINDER_COLUMN_N_H_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
12375            private static final String _FINDER_COLUMN_N_H_S_HEAD_2 = "wikiPage.head = ? AND ";
12376            private static final String _FINDER_COLUMN_N_H_S_STATUS_2 = "wikiPage.status = ?";
12377            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12378                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
12379                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_N_S",
12380                            new String[] {
12381                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
12382                                    Integer.class.getName(),
12383                                    
12384                            Integer.class.getName(), Integer.class.getName(),
12385                                    OrderByComparator.class.getName()
12386                            });
12387            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S =
12388                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12389                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
12390                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_N_S",
12391                            new String[] {
12392                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
12393                                    Integer.class.getName()
12394                            },
12395                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
12396                            WikiPageModelImpl.USERID_COLUMN_BITMASK |
12397                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
12398                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
12399                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
12400                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
12401            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12402                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12403                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_N_S",
12404                            new String[] {
12405                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
12406                                    Integer.class.getName()
12407                            });
12408    
12409            /**
12410             * Returns all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12411             *
12412             * @param groupId the group ID
12413             * @param userId the user ID
12414             * @param nodeId the node ID
12415             * @param status the status
12416             * @return the matching wiki pages
12417             * @throws SystemException if a system exception occurred
12418             */
12419            @Override
12420            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
12421                    int status) throws SystemException {
12422                    return findByG_U_N_S(groupId, userId, nodeId, status,
12423                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12424            }
12425    
12426            /**
12427             * Returns a range of all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12428             *
12429             * <p>
12430             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12431             * </p>
12432             *
12433             * @param groupId the group ID
12434             * @param userId the user ID
12435             * @param nodeId the node ID
12436             * @param status the status
12437             * @param start the lower bound of the range of wiki pages
12438             * @param end the upper bound of the range of wiki pages (not inclusive)
12439             * @return the range of matching wiki pages
12440             * @throws SystemException if a system exception occurred
12441             */
12442            @Override
12443            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
12444                    int status, int start, int end) throws SystemException {
12445                    return findByG_U_N_S(groupId, userId, nodeId, status, start, end, null);
12446            }
12447    
12448            /**
12449             * Returns an ordered range of all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12450             *
12451             * <p>
12452             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12453             * </p>
12454             *
12455             * @param groupId the group ID
12456             * @param userId the user ID
12457             * @param nodeId the node ID
12458             * @param status the status
12459             * @param start the lower bound of the range of wiki pages
12460             * @param end the upper bound of the range of wiki pages (not inclusive)
12461             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12462             * @return the ordered range of matching wiki pages
12463             * @throws SystemException if a system exception occurred
12464             */
12465            @Override
12466            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
12467                    int status, int start, int end, OrderByComparator orderByComparator)
12468                    throws SystemException {
12469                    boolean pagination = true;
12470                    FinderPath finderPath = null;
12471                    Object[] finderArgs = null;
12472    
12473                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12474                                    (orderByComparator == null)) {
12475                            pagination = false;
12476                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S;
12477                            finderArgs = new Object[] { groupId, userId, nodeId, status };
12478                    }
12479                    else {
12480                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_N_S;
12481                            finderArgs = new Object[] {
12482                                            groupId, userId, nodeId, status,
12483                                            
12484                                            start, end, orderByComparator
12485                                    };
12486                    }
12487    
12488                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
12489                                    finderArgs, this);
12490    
12491                    if ((list != null) && !list.isEmpty()) {
12492                            for (WikiPage wikiPage : list) {
12493                                    if ((groupId != wikiPage.getGroupId()) ||
12494                                                    (userId != wikiPage.getUserId()) ||
12495                                                    (nodeId != wikiPage.getNodeId()) ||
12496                                                    (status != wikiPage.getStatus())) {
12497                                            list = null;
12498    
12499                                            break;
12500                                    }
12501                            }
12502                    }
12503    
12504                    if (list == null) {
12505                            StringBundler query = null;
12506    
12507                            if (orderByComparator != null) {
12508                                    query = new StringBundler(6 +
12509                                                    (orderByComparator.getOrderByFields().length * 3));
12510                            }
12511                            else {
12512                                    query = new StringBundler(6);
12513                            }
12514    
12515                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
12516    
12517                            query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
12518    
12519                            query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
12520    
12521                            query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
12522    
12523                            query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
12524    
12525                            if (orderByComparator != null) {
12526                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12527                                            orderByComparator);
12528                            }
12529                            else
12530                             if (pagination) {
12531                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12532                            }
12533    
12534                            String sql = query.toString();
12535    
12536                            Session session = null;
12537    
12538                            try {
12539                                    session = openSession();
12540    
12541                                    Query q = session.createQuery(sql);
12542    
12543                                    QueryPos qPos = QueryPos.getInstance(q);
12544    
12545                                    qPos.add(groupId);
12546    
12547                                    qPos.add(userId);
12548    
12549                                    qPos.add(nodeId);
12550    
12551                                    qPos.add(status);
12552    
12553                                    if (!pagination) {
12554                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
12555                                                            start, end, false);
12556    
12557                                            Collections.sort(list);
12558    
12559                                            list = new UnmodifiableList<WikiPage>(list);
12560                                    }
12561                                    else {
12562                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
12563                                                            start, end);
12564                                    }
12565    
12566                                    cacheResult(list);
12567    
12568                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
12569                            }
12570                            catch (Exception e) {
12571                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12572    
12573                                    throw processException(e);
12574                            }
12575                            finally {
12576                                    closeSession(session);
12577                            }
12578                    }
12579    
12580                    return list;
12581            }
12582    
12583            /**
12584             * Returns the first wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12585             *
12586             * @param groupId the group ID
12587             * @param userId the user ID
12588             * @param nodeId the node ID
12589             * @param status the status
12590             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12591             * @return the first matching wiki page
12592             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
12593             * @throws SystemException if a system exception occurred
12594             */
12595            @Override
12596            public WikiPage findByG_U_N_S_First(long groupId, long userId, long nodeId,
12597                    int status, OrderByComparator orderByComparator)
12598                    throws NoSuchPageException, SystemException {
12599                    WikiPage wikiPage = fetchByG_U_N_S_First(groupId, userId, nodeId,
12600                                    status, orderByComparator);
12601    
12602                    if (wikiPage != null) {
12603                            return wikiPage;
12604                    }
12605    
12606                    StringBundler msg = new StringBundler(10);
12607    
12608                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12609    
12610                    msg.append("groupId=");
12611                    msg.append(groupId);
12612    
12613                    msg.append(", userId=");
12614                    msg.append(userId);
12615    
12616                    msg.append(", nodeId=");
12617                    msg.append(nodeId);
12618    
12619                    msg.append(", status=");
12620                    msg.append(status);
12621    
12622                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12623    
12624                    throw new NoSuchPageException(msg.toString());
12625            }
12626    
12627            /**
12628             * Returns the first wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12629             *
12630             * @param groupId the group ID
12631             * @param userId the user ID
12632             * @param nodeId the node ID
12633             * @param status the status
12634             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12635             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
12636             * @throws SystemException if a system exception occurred
12637             */
12638            @Override
12639            public WikiPage fetchByG_U_N_S_First(long groupId, long userId,
12640                    long nodeId, int status, OrderByComparator orderByComparator)
12641                    throws SystemException {
12642                    List<WikiPage> list = findByG_U_N_S(groupId, userId, nodeId, status, 0,
12643                                    1, orderByComparator);
12644    
12645                    if (!list.isEmpty()) {
12646                            return list.get(0);
12647                    }
12648    
12649                    return null;
12650            }
12651    
12652            /**
12653             * Returns the last wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12654             *
12655             * @param groupId the group ID
12656             * @param userId the user ID
12657             * @param nodeId the node ID
12658             * @param status the status
12659             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12660             * @return the last matching wiki page
12661             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
12662             * @throws SystemException if a system exception occurred
12663             */
12664            @Override
12665            public WikiPage findByG_U_N_S_Last(long groupId, long userId, long nodeId,
12666                    int status, OrderByComparator orderByComparator)
12667                    throws NoSuchPageException, SystemException {
12668                    WikiPage wikiPage = fetchByG_U_N_S_Last(groupId, userId, nodeId,
12669                                    status, orderByComparator);
12670    
12671                    if (wikiPage != null) {
12672                            return wikiPage;
12673                    }
12674    
12675                    StringBundler msg = new StringBundler(10);
12676    
12677                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12678    
12679                    msg.append("groupId=");
12680                    msg.append(groupId);
12681    
12682                    msg.append(", userId=");
12683                    msg.append(userId);
12684    
12685                    msg.append(", nodeId=");
12686                    msg.append(nodeId);
12687    
12688                    msg.append(", status=");
12689                    msg.append(status);
12690    
12691                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12692    
12693                    throw new NoSuchPageException(msg.toString());
12694            }
12695    
12696            /**
12697             * Returns the last wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12698             *
12699             * @param groupId the group ID
12700             * @param userId the user ID
12701             * @param nodeId the node ID
12702             * @param status the status
12703             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12704             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
12705             * @throws SystemException if a system exception occurred
12706             */
12707            @Override
12708            public WikiPage fetchByG_U_N_S_Last(long groupId, long userId, long nodeId,
12709                    int status, OrderByComparator orderByComparator)
12710                    throws SystemException {
12711                    int count = countByG_U_N_S(groupId, userId, nodeId, status);
12712    
12713                    if (count == 0) {
12714                            return null;
12715                    }
12716    
12717                    List<WikiPage> list = findByG_U_N_S(groupId, userId, nodeId, status,
12718                                    count - 1, count, orderByComparator);
12719    
12720                    if (!list.isEmpty()) {
12721                            return list.get(0);
12722                    }
12723    
12724                    return null;
12725            }
12726    
12727            /**
12728             * 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;.
12729             *
12730             * @param pageId the primary key of the current wiki page
12731             * @param groupId the group ID
12732             * @param userId the user ID
12733             * @param nodeId the node ID
12734             * @param status the status
12735             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12736             * @return the previous, current, and next wiki page
12737             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
12738             * @throws SystemException if a system exception occurred
12739             */
12740            @Override
12741            public WikiPage[] findByG_U_N_S_PrevAndNext(long pageId, long groupId,
12742                    long userId, long nodeId, int status,
12743                    OrderByComparator orderByComparator)
12744                    throws NoSuchPageException, SystemException {
12745                    WikiPage wikiPage = findByPrimaryKey(pageId);
12746    
12747                    Session session = null;
12748    
12749                    try {
12750                            session = openSession();
12751    
12752                            WikiPage[] array = new WikiPageImpl[3];
12753    
12754                            array[0] = getByG_U_N_S_PrevAndNext(session, wikiPage, groupId,
12755                                            userId, nodeId, status, orderByComparator, true);
12756    
12757                            array[1] = wikiPage;
12758    
12759                            array[2] = getByG_U_N_S_PrevAndNext(session, wikiPage, groupId,
12760                                            userId, nodeId, status, orderByComparator, false);
12761    
12762                            return array;
12763                    }
12764                    catch (Exception e) {
12765                            throw processException(e);
12766                    }
12767                    finally {
12768                            closeSession(session);
12769                    }
12770            }
12771    
12772            protected WikiPage getByG_U_N_S_PrevAndNext(Session session,
12773                    WikiPage wikiPage, long groupId, long userId, long nodeId, int status,
12774                    OrderByComparator orderByComparator, boolean previous) {
12775                    StringBundler query = null;
12776    
12777                    if (orderByComparator != null) {
12778                            query = new StringBundler(6 +
12779                                            (orderByComparator.getOrderByFields().length * 6));
12780                    }
12781                    else {
12782                            query = new StringBundler(3);
12783                    }
12784    
12785                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
12786    
12787                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
12788    
12789                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
12790    
12791                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
12792    
12793                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
12794    
12795                    if (orderByComparator != null) {
12796                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12797    
12798                            if (orderByConditionFields.length > 0) {
12799                                    query.append(WHERE_AND);
12800                            }
12801    
12802                            for (int i = 0; i < orderByConditionFields.length; i++) {
12803                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12804                                    query.append(orderByConditionFields[i]);
12805    
12806                                    if ((i + 1) < orderByConditionFields.length) {
12807                                            if (orderByComparator.isAscending() ^ previous) {
12808                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12809                                            }
12810                                            else {
12811                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12812                                            }
12813                                    }
12814                                    else {
12815                                            if (orderByComparator.isAscending() ^ previous) {
12816                                                    query.append(WHERE_GREATER_THAN);
12817                                            }
12818                                            else {
12819                                                    query.append(WHERE_LESSER_THAN);
12820                                            }
12821                                    }
12822                            }
12823    
12824                            query.append(ORDER_BY_CLAUSE);
12825    
12826                            String[] orderByFields = orderByComparator.getOrderByFields();
12827    
12828                            for (int i = 0; i < orderByFields.length; i++) {
12829                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12830                                    query.append(orderByFields[i]);
12831    
12832                                    if ((i + 1) < orderByFields.length) {
12833                                            if (orderByComparator.isAscending() ^ previous) {
12834                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12835                                            }
12836                                            else {
12837                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12838                                            }
12839                                    }
12840                                    else {
12841                                            if (orderByComparator.isAscending() ^ previous) {
12842                                                    query.append(ORDER_BY_ASC);
12843                                            }
12844                                            else {
12845                                                    query.append(ORDER_BY_DESC);
12846                                            }
12847                                    }
12848                            }
12849                    }
12850                    else {
12851                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12852                    }
12853    
12854                    String sql = query.toString();
12855    
12856                    Query q = session.createQuery(sql);
12857    
12858                    q.setFirstResult(0);
12859                    q.setMaxResults(2);
12860    
12861                    QueryPos qPos = QueryPos.getInstance(q);
12862    
12863                    qPos.add(groupId);
12864    
12865                    qPos.add(userId);
12866    
12867                    qPos.add(nodeId);
12868    
12869                    qPos.add(status);
12870    
12871                    if (orderByComparator != null) {
12872                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
12873    
12874                            for (Object value : values) {
12875                                    qPos.add(value);
12876                            }
12877                    }
12878    
12879                    List<WikiPage> list = q.list();
12880    
12881                    if (list.size() == 2) {
12882                            return list.get(1);
12883                    }
12884                    else {
12885                            return null;
12886                    }
12887            }
12888    
12889            /**
12890             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12891             *
12892             * @param groupId the group ID
12893             * @param userId the user ID
12894             * @param nodeId the node ID
12895             * @param status the status
12896             * @return the matching wiki pages that the user has permission to view
12897             * @throws SystemException if a system exception occurred
12898             */
12899            @Override
12900            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
12901                    long nodeId, int status) throws SystemException {
12902                    return filterFindByG_U_N_S(groupId, userId, nodeId, status,
12903                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12904            }
12905    
12906            /**
12907             * 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;.
12908             *
12909             * <p>
12910             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12911             * </p>
12912             *
12913             * @param groupId the group ID
12914             * @param userId the user ID
12915             * @param nodeId the node ID
12916             * @param status the status
12917             * @param start the lower bound of the range of wiki pages
12918             * @param end the upper bound of the range of wiki pages (not inclusive)
12919             * @return the range of matching wiki pages that the user has permission to view
12920             * @throws SystemException if a system exception occurred
12921             */
12922            @Override
12923            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
12924                    long nodeId, int status, int start, int end) throws SystemException {
12925                    return filterFindByG_U_N_S(groupId, userId, nodeId, status, start, end,
12926                            null);
12927            }
12928    
12929            /**
12930             * 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;.
12931             *
12932             * <p>
12933             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12934             * </p>
12935             *
12936             * @param groupId the group ID
12937             * @param userId the user ID
12938             * @param nodeId the node ID
12939             * @param status the status
12940             * @param start the lower bound of the range of wiki pages
12941             * @param end the upper bound of the range of wiki pages (not inclusive)
12942             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12943             * @return the ordered range of matching wiki pages that the user has permission to view
12944             * @throws SystemException if a system exception occurred
12945             */
12946            @Override
12947            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
12948                    long nodeId, int status, int start, int end,
12949                    OrderByComparator orderByComparator) throws SystemException {
12950                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12951                            return findByG_U_N_S(groupId, userId, nodeId, status, start, end,
12952                                    orderByComparator);
12953                    }
12954    
12955                    StringBundler query = null;
12956    
12957                    if (orderByComparator != null) {
12958                            query = new StringBundler(6 +
12959                                            (orderByComparator.getOrderByFields().length * 3));
12960                    }
12961                    else {
12962                            query = new StringBundler(6);
12963                    }
12964    
12965                    if (getDB().isSupportsInlineDistinct()) {
12966                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
12967                    }
12968                    else {
12969                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
12970                    }
12971    
12972                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
12973    
12974                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
12975    
12976                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
12977    
12978                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
12979    
12980                    if (!getDB().isSupportsInlineDistinct()) {
12981                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
12982                    }
12983    
12984                    if (orderByComparator != null) {
12985                            if (getDB().isSupportsInlineDistinct()) {
12986                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12987                                            orderByComparator, true);
12988                            }
12989                            else {
12990                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12991                                            orderByComparator, true);
12992                            }
12993                    }
12994                    else {
12995                            if (getDB().isSupportsInlineDistinct()) {
12996                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12997                            }
12998                            else {
12999                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
13000                            }
13001                    }
13002    
13003                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13004                                    WikiPage.class.getName(),
13005                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13006    
13007                    Session session = null;
13008    
13009                    try {
13010                            session = openSession();
13011    
13012                            SQLQuery q = session.createSQLQuery(sql);
13013    
13014                            if (getDB().isSupportsInlineDistinct()) {
13015                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
13016                            }
13017                            else {
13018                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
13019                            }
13020    
13021                            QueryPos qPos = QueryPos.getInstance(q);
13022    
13023                            qPos.add(groupId);
13024    
13025                            qPos.add(userId);
13026    
13027                            qPos.add(nodeId);
13028    
13029                            qPos.add(status);
13030    
13031                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
13032                    }
13033                    catch (Exception e) {
13034                            throw processException(e);
13035                    }
13036                    finally {
13037                            closeSession(session);
13038                    }
13039            }
13040    
13041            /**
13042             * 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;.
13043             *
13044             * @param pageId the primary key of the current wiki page
13045             * @param groupId the group ID
13046             * @param userId the user ID
13047             * @param nodeId the node ID
13048             * @param status the status
13049             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13050             * @return the previous, current, and next wiki page
13051             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
13052             * @throws SystemException if a system exception occurred
13053             */
13054            @Override
13055            public WikiPage[] filterFindByG_U_N_S_PrevAndNext(long pageId,
13056                    long groupId, long userId, long nodeId, int status,
13057                    OrderByComparator orderByComparator)
13058                    throws NoSuchPageException, SystemException {
13059                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13060                            return findByG_U_N_S_PrevAndNext(pageId, groupId, userId, nodeId,
13061                                    status, orderByComparator);
13062                    }
13063    
13064                    WikiPage wikiPage = findByPrimaryKey(pageId);
13065    
13066                    Session session = null;
13067    
13068                    try {
13069                            session = openSession();
13070    
13071                            WikiPage[] array = new WikiPageImpl[3];
13072    
13073                            array[0] = filterGetByG_U_N_S_PrevAndNext(session, wikiPage,
13074                                            groupId, userId, nodeId, status, orderByComparator, true);
13075    
13076                            array[1] = wikiPage;
13077    
13078                            array[2] = filterGetByG_U_N_S_PrevAndNext(session, wikiPage,
13079                                            groupId, userId, nodeId, status, orderByComparator, false);
13080    
13081                            return array;
13082                    }
13083                    catch (Exception e) {
13084                            throw processException(e);
13085                    }
13086                    finally {
13087                            closeSession(session);
13088                    }
13089            }
13090    
13091            protected WikiPage filterGetByG_U_N_S_PrevAndNext(Session session,
13092                    WikiPage wikiPage, long groupId, long userId, long nodeId, int status,
13093                    OrderByComparator orderByComparator, boolean previous) {
13094                    StringBundler query = null;
13095    
13096                    if (orderByComparator != null) {
13097                            query = new StringBundler(6 +
13098                                            (orderByComparator.getOrderByFields().length * 6));
13099                    }
13100                    else {
13101                            query = new StringBundler(3);
13102                    }
13103    
13104                    if (getDB().isSupportsInlineDistinct()) {
13105                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
13106                    }
13107                    else {
13108                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
13109                    }
13110    
13111                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
13112    
13113                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
13114    
13115                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
13116    
13117                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
13118    
13119                    if (!getDB().isSupportsInlineDistinct()) {
13120                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
13121                    }
13122    
13123                    if (orderByComparator != null) {
13124                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13125    
13126                            if (orderByConditionFields.length > 0) {
13127                                    query.append(WHERE_AND);
13128                            }
13129    
13130                            for (int i = 0; i < orderByConditionFields.length; i++) {
13131                                    if (getDB().isSupportsInlineDistinct()) {
13132                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13133                                    }
13134                                    else {
13135                                            query.append(_ORDER_BY_ENTITY_TABLE);
13136                                    }
13137    
13138                                    query.append(orderByConditionFields[i]);
13139    
13140                                    if ((i + 1) < orderByConditionFields.length) {
13141                                            if (orderByComparator.isAscending() ^ previous) {
13142                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13143                                            }
13144                                            else {
13145                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13146                                            }
13147                                    }
13148                                    else {
13149                                            if (orderByComparator.isAscending() ^ previous) {
13150                                                    query.append(WHERE_GREATER_THAN);
13151                                            }
13152                                            else {
13153                                                    query.append(WHERE_LESSER_THAN);
13154                                            }
13155                                    }
13156                            }
13157    
13158                            query.append(ORDER_BY_CLAUSE);
13159    
13160                            String[] orderByFields = orderByComparator.getOrderByFields();
13161    
13162                            for (int i = 0; i < orderByFields.length; i++) {
13163                                    if (getDB().isSupportsInlineDistinct()) {
13164                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13165                                    }
13166                                    else {
13167                                            query.append(_ORDER_BY_ENTITY_TABLE);
13168                                    }
13169    
13170                                    query.append(orderByFields[i]);
13171    
13172                                    if ((i + 1) < orderByFields.length) {
13173                                            if (orderByComparator.isAscending() ^ previous) {
13174                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13175                                            }
13176                                            else {
13177                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13178                                            }
13179                                    }
13180                                    else {
13181                                            if (orderByComparator.isAscending() ^ previous) {
13182                                                    query.append(ORDER_BY_ASC);
13183                                            }
13184                                            else {
13185                                                    query.append(ORDER_BY_DESC);
13186                                            }
13187                                    }
13188                            }
13189                    }
13190                    else {
13191                            if (getDB().isSupportsInlineDistinct()) {
13192                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13193                            }
13194                            else {
13195                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
13196                            }
13197                    }
13198    
13199                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13200                                    WikiPage.class.getName(),
13201                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13202    
13203                    SQLQuery q = session.createSQLQuery(sql);
13204    
13205                    q.setFirstResult(0);
13206                    q.setMaxResults(2);
13207    
13208                    if (getDB().isSupportsInlineDistinct()) {
13209                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
13210                    }
13211                    else {
13212                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
13213                    }
13214    
13215                    QueryPos qPos = QueryPos.getInstance(q);
13216    
13217                    qPos.add(groupId);
13218    
13219                    qPos.add(userId);
13220    
13221                    qPos.add(nodeId);
13222    
13223                    qPos.add(status);
13224    
13225                    if (orderByComparator != null) {
13226                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
13227    
13228                            for (Object value : values) {
13229                                    qPos.add(value);
13230                            }
13231                    }
13232    
13233                    List<WikiPage> list = q.list();
13234    
13235                    if (list.size() == 2) {
13236                            return list.get(1);
13237                    }
13238                    else {
13239                            return null;
13240                    }
13241            }
13242    
13243            /**
13244             * Removes all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63; from the database.
13245             *
13246             * @param groupId the group ID
13247             * @param userId the user ID
13248             * @param nodeId the node ID
13249             * @param status the status
13250             * @throws SystemException if a system exception occurred
13251             */
13252            @Override
13253            public void removeByG_U_N_S(long groupId, long userId, long nodeId,
13254                    int status) throws SystemException {
13255                    for (WikiPage wikiPage : findByG_U_N_S(groupId, userId, nodeId, status,
13256                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13257                            remove(wikiPage);
13258                    }
13259            }
13260    
13261            /**
13262             * Returns the number of wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
13263             *
13264             * @param groupId the group ID
13265             * @param userId the user ID
13266             * @param nodeId the node ID
13267             * @param status the status
13268             * @return the number of matching wiki pages
13269             * @throws SystemException if a system exception occurred
13270             */
13271            @Override
13272            public int countByG_U_N_S(long groupId, long userId, long nodeId, int status)
13273                    throws SystemException {
13274                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_N_S;
13275    
13276                    Object[] finderArgs = new Object[] { groupId, userId, nodeId, status };
13277    
13278                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
13279                                    this);
13280    
13281                    if (count == null) {
13282                            StringBundler query = new StringBundler(5);
13283    
13284                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
13285    
13286                            query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
13287    
13288                            query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
13289    
13290                            query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
13291    
13292                            query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
13293    
13294                            String sql = query.toString();
13295    
13296                            Session session = null;
13297    
13298                            try {
13299                                    session = openSession();
13300    
13301                                    Query q = session.createQuery(sql);
13302    
13303                                    QueryPos qPos = QueryPos.getInstance(q);
13304    
13305                                    qPos.add(groupId);
13306    
13307                                    qPos.add(userId);
13308    
13309                                    qPos.add(nodeId);
13310    
13311                                    qPos.add(status);
13312    
13313                                    count = (Long)q.uniqueResult();
13314    
13315                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
13316                            }
13317                            catch (Exception e) {
13318                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13319    
13320                                    throw processException(e);
13321                            }
13322                            finally {
13323                                    closeSession(session);
13324                            }
13325                    }
13326    
13327                    return count.intValue();
13328            }
13329    
13330            /**
13331             * 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;.
13332             *
13333             * @param groupId the group ID
13334             * @param userId the user ID
13335             * @param nodeId the node ID
13336             * @param status the status
13337             * @return the number of matching wiki pages that the user has permission to view
13338             * @throws SystemException if a system exception occurred
13339             */
13340            @Override
13341            public int filterCountByG_U_N_S(long groupId, long userId, long nodeId,
13342                    int status) throws SystemException {
13343                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13344                            return countByG_U_N_S(groupId, userId, nodeId, status);
13345                    }
13346    
13347                    StringBundler query = new StringBundler(5);
13348    
13349                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
13350    
13351                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
13352    
13353                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
13354    
13355                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
13356    
13357                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
13358    
13359                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13360                                    WikiPage.class.getName(),
13361                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13362    
13363                    Session session = null;
13364    
13365                    try {
13366                            session = openSession();
13367    
13368                            SQLQuery q = session.createSQLQuery(sql);
13369    
13370                            q.addScalar(COUNT_COLUMN_NAME,
13371                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
13372    
13373                            QueryPos qPos = QueryPos.getInstance(q);
13374    
13375                            qPos.add(groupId);
13376    
13377                            qPos.add(userId);
13378    
13379                            qPos.add(nodeId);
13380    
13381                            qPos.add(status);
13382    
13383                            Long count = (Long)q.uniqueResult();
13384    
13385                            return count.intValue();
13386                    }
13387                    catch (Exception e) {
13388                            throw processException(e);
13389                    }
13390                    finally {
13391                            closeSession(session);
13392                    }
13393            }
13394    
13395            private static final String _FINDER_COLUMN_G_U_N_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
13396            private static final String _FINDER_COLUMN_G_U_N_S_USERID_2 = "wikiPage.userId = ? AND ";
13397            private static final String _FINDER_COLUMN_G_U_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
13398            private static final String _FINDER_COLUMN_G_U_N_S_STATUS_2 = "wikiPage.status = ?";
13399            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13400                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
13401                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_T_H",
13402                            new String[] {
13403                                    Long.class.getName(), Long.class.getName(),
13404                                    String.class.getName(), Boolean.class.getName(),
13405                                    
13406                            Integer.class.getName(), Integer.class.getName(),
13407                                    OrderByComparator.class.getName()
13408                            });
13409            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H =
13410                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13411                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
13412                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_T_H",
13413                            new String[] {
13414                                    Long.class.getName(), Long.class.getName(),
13415                                    String.class.getName(), Boolean.class.getName()
13416                            },
13417                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
13418                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
13419                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
13420                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
13421                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
13422            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13423                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13424                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_T_H",
13425                            new String[] {
13426                                    Long.class.getName(), Long.class.getName(),
13427                                    String.class.getName(), Boolean.class.getName()
13428                            });
13429    
13430            /**
13431             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13432             *
13433             * @param groupId the group ID
13434             * @param nodeId the node ID
13435             * @param title the title
13436             * @param head the head
13437             * @return the matching wiki pages
13438             * @throws SystemException if a system exception occurred
13439             */
13440            @Override
13441            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
13442                    String title, boolean head) throws SystemException {
13443                    return findByG_N_T_H(groupId, nodeId, title, head, QueryUtil.ALL_POS,
13444                            QueryUtil.ALL_POS, null);
13445            }
13446    
13447            /**
13448             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13449             *
13450             * <p>
13451             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13452             * </p>
13453             *
13454             * @param groupId the group ID
13455             * @param nodeId the node ID
13456             * @param title the title
13457             * @param head the head
13458             * @param start the lower bound of the range of wiki pages
13459             * @param end the upper bound of the range of wiki pages (not inclusive)
13460             * @return the range of matching wiki pages
13461             * @throws SystemException if a system exception occurred
13462             */
13463            @Override
13464            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
13465                    String title, boolean head, int start, int end)
13466                    throws SystemException {
13467                    return findByG_N_T_H(groupId, nodeId, title, head, start, end, null);
13468            }
13469    
13470            /**
13471             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13472             *
13473             * <p>
13474             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13475             * </p>
13476             *
13477             * @param groupId the group ID
13478             * @param nodeId the node ID
13479             * @param title the title
13480             * @param head the head
13481             * @param start the lower bound of the range of wiki pages
13482             * @param end the upper bound of the range of wiki pages (not inclusive)
13483             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13484             * @return the ordered range of matching wiki pages
13485             * @throws SystemException if a system exception occurred
13486             */
13487            @Override
13488            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
13489                    String title, boolean head, int start, int end,
13490                    OrderByComparator orderByComparator) throws SystemException {
13491                    boolean pagination = true;
13492                    FinderPath finderPath = null;
13493                    Object[] finderArgs = null;
13494    
13495                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13496                                    (orderByComparator == null)) {
13497                            pagination = false;
13498                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H;
13499                            finderArgs = new Object[] { groupId, nodeId, title, head };
13500                    }
13501                    else {
13502                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T_H;
13503                            finderArgs = new Object[] {
13504                                            groupId, nodeId, title, head,
13505                                            
13506                                            start, end, orderByComparator
13507                                    };
13508                    }
13509    
13510                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
13511                                    finderArgs, this);
13512    
13513                    if ((list != null) && !list.isEmpty()) {
13514                            for (WikiPage wikiPage : list) {
13515                                    if ((groupId != wikiPage.getGroupId()) ||
13516                                                    (nodeId != wikiPage.getNodeId()) ||
13517                                                    !Validator.equals(title, wikiPage.getTitle()) ||
13518                                                    (head != wikiPage.getHead())) {
13519                                            list = null;
13520    
13521                                            break;
13522                                    }
13523                            }
13524                    }
13525    
13526                    if (list == null) {
13527                            StringBundler query = null;
13528    
13529                            if (orderByComparator != null) {
13530                                    query = new StringBundler(6 +
13531                                                    (orderByComparator.getOrderByFields().length * 3));
13532                            }
13533                            else {
13534                                    query = new StringBundler(6);
13535                            }
13536    
13537                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
13538    
13539                            query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
13540    
13541                            query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
13542    
13543                            boolean bindTitle = false;
13544    
13545                            if (title == null) {
13546                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
13547                            }
13548                            else if (title.equals(StringPool.BLANK)) {
13549                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
13550                            }
13551                            else {
13552                                    bindTitle = true;
13553    
13554                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
13555                            }
13556    
13557                            query.append(_FINDER_COLUMN_G_N_T_H_HEAD_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(nodeId);
13582    
13583                                    if (bindTitle) {
13584                                            qPos.add(title.toLowerCase());
13585                                    }
13586    
13587                                    qPos.add(head);
13588    
13589                                    if (!pagination) {
13590                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13591                                                            start, end, false);
13592    
13593                                            Collections.sort(list);
13594    
13595                                            list = new UnmodifiableList<WikiPage>(list);
13596                                    }
13597                                    else {
13598                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13599                                                            start, end);
13600                                    }
13601    
13602                                    cacheResult(list);
13603    
13604                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13605                            }
13606                            catch (Exception e) {
13607                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13608    
13609                                    throw processException(e);
13610                            }
13611                            finally {
13612                                    closeSession(session);
13613                            }
13614                    }
13615    
13616                    return list;
13617            }
13618    
13619            /**
13620             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13621             *
13622             * @param groupId the group ID
13623             * @param nodeId the node ID
13624             * @param title the title
13625             * @param head the head
13626             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13627             * @return the first matching wiki page
13628             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13629             * @throws SystemException if a system exception occurred
13630             */
13631            @Override
13632            public WikiPage findByG_N_T_H_First(long groupId, long nodeId,
13633                    String title, boolean head, OrderByComparator orderByComparator)
13634                    throws NoSuchPageException, SystemException {
13635                    WikiPage wikiPage = fetchByG_N_T_H_First(groupId, nodeId, title, head,
13636                                    orderByComparator);
13637    
13638                    if (wikiPage != null) {
13639                            return wikiPage;
13640                    }
13641    
13642                    StringBundler msg = new StringBundler(10);
13643    
13644                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13645    
13646                    msg.append("groupId=");
13647                    msg.append(groupId);
13648    
13649                    msg.append(", nodeId=");
13650                    msg.append(nodeId);
13651    
13652                    msg.append(", title=");
13653                    msg.append(title);
13654    
13655                    msg.append(", head=");
13656                    msg.append(head);
13657    
13658                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13659    
13660                    throw new NoSuchPageException(msg.toString());
13661            }
13662    
13663            /**
13664             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13665             *
13666             * @param groupId the group ID
13667             * @param nodeId the node ID
13668             * @param title the title
13669             * @param head the head
13670             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13671             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
13672             * @throws SystemException if a system exception occurred
13673             */
13674            @Override
13675            public WikiPage fetchByG_N_T_H_First(long groupId, long nodeId,
13676                    String title, boolean head, OrderByComparator orderByComparator)
13677                    throws SystemException {
13678                    List<WikiPage> list = findByG_N_T_H(groupId, nodeId, title, head, 0, 1,
13679                                    orderByComparator);
13680    
13681                    if (!list.isEmpty()) {
13682                            return list.get(0);
13683                    }
13684    
13685                    return null;
13686            }
13687    
13688            /**
13689             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13690             *
13691             * @param groupId the group ID
13692             * @param nodeId the node ID
13693             * @param title the title
13694             * @param head the head
13695             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13696             * @return the last matching wiki page
13697             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13698             * @throws SystemException if a system exception occurred
13699             */
13700            @Override
13701            public WikiPage findByG_N_T_H_Last(long groupId, long nodeId, String title,
13702                    boolean head, OrderByComparator orderByComparator)
13703                    throws NoSuchPageException, SystemException {
13704                    WikiPage wikiPage = fetchByG_N_T_H_Last(groupId, nodeId, title, head,
13705                                    orderByComparator);
13706    
13707                    if (wikiPage != null) {
13708                            return wikiPage;
13709                    }
13710    
13711                    StringBundler msg = new StringBundler(10);
13712    
13713                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13714    
13715                    msg.append("groupId=");
13716                    msg.append(groupId);
13717    
13718                    msg.append(", nodeId=");
13719                    msg.append(nodeId);
13720    
13721                    msg.append(", title=");
13722                    msg.append(title);
13723    
13724                    msg.append(", head=");
13725                    msg.append(head);
13726    
13727                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13728    
13729                    throw new NoSuchPageException(msg.toString());
13730            }
13731    
13732            /**
13733             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13734             *
13735             * @param groupId the group ID
13736             * @param nodeId the node ID
13737             * @param title the title
13738             * @param head the head
13739             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13740             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
13741             * @throws SystemException if a system exception occurred
13742             */
13743            @Override
13744            public WikiPage fetchByG_N_T_H_Last(long groupId, long nodeId,
13745                    String title, boolean head, OrderByComparator orderByComparator)
13746                    throws SystemException {
13747                    int count = countByG_N_T_H(groupId, nodeId, title, head);
13748    
13749                    if (count == 0) {
13750                            return null;
13751                    }
13752    
13753                    List<WikiPage> list = findByG_N_T_H(groupId, nodeId, title, head,
13754                                    count - 1, count, orderByComparator);
13755    
13756                    if (!list.isEmpty()) {
13757                            return list.get(0);
13758                    }
13759    
13760                    return null;
13761            }
13762    
13763            /**
13764             * 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;.
13765             *
13766             * @param pageId the primary key of the current wiki page
13767             * @param groupId the group ID
13768             * @param nodeId the node ID
13769             * @param title the title
13770             * @param head the head
13771             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13772             * @return the previous, current, and next wiki page
13773             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
13774             * @throws SystemException if a system exception occurred
13775             */
13776            @Override
13777            public WikiPage[] findByG_N_T_H_PrevAndNext(long pageId, long groupId,
13778                    long nodeId, String title, boolean head,
13779                    OrderByComparator orderByComparator)
13780                    throws NoSuchPageException, SystemException {
13781                    WikiPage wikiPage = findByPrimaryKey(pageId);
13782    
13783                    Session session = null;
13784    
13785                    try {
13786                            session = openSession();
13787    
13788                            WikiPage[] array = new WikiPageImpl[3];
13789    
13790                            array[0] = getByG_N_T_H_PrevAndNext(session, wikiPage, groupId,
13791                                            nodeId, title, head, orderByComparator, true);
13792    
13793                            array[1] = wikiPage;
13794    
13795                            array[2] = getByG_N_T_H_PrevAndNext(session, wikiPage, groupId,
13796                                            nodeId, title, head, orderByComparator, false);
13797    
13798                            return array;
13799                    }
13800                    catch (Exception e) {
13801                            throw processException(e);
13802                    }
13803                    finally {
13804                            closeSession(session);
13805                    }
13806            }
13807    
13808            protected WikiPage getByG_N_T_H_PrevAndNext(Session session,
13809                    WikiPage wikiPage, long groupId, long nodeId, String title,
13810                    boolean head, OrderByComparator orderByComparator, boolean previous) {
13811                    StringBundler query = null;
13812    
13813                    if (orderByComparator != null) {
13814                            query = new StringBundler(6 +
13815                                            (orderByComparator.getOrderByFields().length * 6));
13816                    }
13817                    else {
13818                            query = new StringBundler(3);
13819                    }
13820    
13821                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
13822    
13823                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
13824    
13825                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
13826    
13827                    boolean bindTitle = false;
13828    
13829                    if (title == null) {
13830                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
13831                    }
13832                    else if (title.equals(StringPool.BLANK)) {
13833                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
13834                    }
13835                    else {
13836                            bindTitle = true;
13837    
13838                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
13839                    }
13840    
13841                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
13842    
13843                    if (orderByComparator != null) {
13844                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13845    
13846                            if (orderByConditionFields.length > 0) {
13847                                    query.append(WHERE_AND);
13848                            }
13849    
13850                            for (int i = 0; i < orderByConditionFields.length; i++) {
13851                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13852                                    query.append(orderByConditionFields[i]);
13853    
13854                                    if ((i + 1) < orderByConditionFields.length) {
13855                                            if (orderByComparator.isAscending() ^ previous) {
13856                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13857                                            }
13858                                            else {
13859                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13860                                            }
13861                                    }
13862                                    else {
13863                                            if (orderByComparator.isAscending() ^ previous) {
13864                                                    query.append(WHERE_GREATER_THAN);
13865                                            }
13866                                            else {
13867                                                    query.append(WHERE_LESSER_THAN);
13868                                            }
13869                                    }
13870                            }
13871    
13872                            query.append(ORDER_BY_CLAUSE);
13873    
13874                            String[] orderByFields = orderByComparator.getOrderByFields();
13875    
13876                            for (int i = 0; i < orderByFields.length; i++) {
13877                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13878                                    query.append(orderByFields[i]);
13879    
13880                                    if ((i + 1) < orderByFields.length) {
13881                                            if (orderByComparator.isAscending() ^ previous) {
13882                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13883                                            }
13884                                            else {
13885                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13886                                            }
13887                                    }
13888                                    else {
13889                                            if (orderByComparator.isAscending() ^ previous) {
13890                                                    query.append(ORDER_BY_ASC);
13891                                            }
13892                                            else {
13893                                                    query.append(ORDER_BY_DESC);
13894                                            }
13895                                    }
13896                            }
13897                    }
13898                    else {
13899                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13900                    }
13901    
13902                    String sql = query.toString();
13903    
13904                    Query q = session.createQuery(sql);
13905    
13906                    q.setFirstResult(0);
13907                    q.setMaxResults(2);
13908    
13909                    QueryPos qPos = QueryPos.getInstance(q);
13910    
13911                    qPos.add(groupId);
13912    
13913                    qPos.add(nodeId);
13914    
13915                    if (bindTitle) {
13916                            qPos.add(title.toLowerCase());
13917                    }
13918    
13919                    qPos.add(head);
13920    
13921                    if (orderByComparator != null) {
13922                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
13923    
13924                            for (Object value : values) {
13925                                    qPos.add(value);
13926                            }
13927                    }
13928    
13929                    List<WikiPage> list = q.list();
13930    
13931                    if (list.size() == 2) {
13932                            return list.get(1);
13933                    }
13934                    else {
13935                            return null;
13936                    }
13937            }
13938    
13939            /**
13940             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13941             *
13942             * @param groupId the group ID
13943             * @param nodeId the node ID
13944             * @param title the title
13945             * @param head the head
13946             * @return the matching wiki pages that the user has permission to view
13947             * @throws SystemException if a system exception occurred
13948             */
13949            @Override
13950            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
13951                    String title, boolean head) throws SystemException {
13952                    return filterFindByG_N_T_H(groupId, nodeId, title, head,
13953                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13954            }
13955    
13956            /**
13957             * 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;.
13958             *
13959             * <p>
13960             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13961             * </p>
13962             *
13963             * @param groupId the group ID
13964             * @param nodeId the node ID
13965             * @param title the title
13966             * @param head the head
13967             * @param start the lower bound of the range of wiki pages
13968             * @param end the upper bound of the range of wiki pages (not inclusive)
13969             * @return the range of matching wiki pages that the user has permission to view
13970             * @throws SystemException if a system exception occurred
13971             */
13972            @Override
13973            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
13974                    String title, boolean head, int start, int end)
13975                    throws SystemException {
13976                    return filterFindByG_N_T_H(groupId, nodeId, title, head, start, end,
13977                            null);
13978            }
13979    
13980            /**
13981             * 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;.
13982             *
13983             * <p>
13984             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13985             * </p>
13986             *
13987             * @param groupId the group ID
13988             * @param nodeId the node ID
13989             * @param title the title
13990             * @param head the head
13991             * @param start the lower bound of the range of wiki pages
13992             * @param end the upper bound of the range of wiki pages (not inclusive)
13993             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13994             * @return the ordered range of matching wiki pages that the user has permission to view
13995             * @throws SystemException if a system exception occurred
13996             */
13997            @Override
13998            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
13999                    String title, boolean head, int start, int end,
14000                    OrderByComparator orderByComparator) throws SystemException {
14001                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14002                            return findByG_N_T_H(groupId, nodeId, title, head, start, end,
14003                                    orderByComparator);
14004                    }
14005    
14006                    StringBundler query = null;
14007    
14008                    if (orderByComparator != null) {
14009                            query = new StringBundler(6 +
14010                                            (orderByComparator.getOrderByFields().length * 3));
14011                    }
14012                    else {
14013                            query = new StringBundler(6);
14014                    }
14015    
14016                    if (getDB().isSupportsInlineDistinct()) {
14017                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
14018                    }
14019                    else {
14020                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
14021                    }
14022    
14023                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
14024    
14025                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
14026    
14027                    boolean bindTitle = false;
14028    
14029                    if (title == null) {
14030                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
14031                    }
14032                    else if (title.equals(StringPool.BLANK)) {
14033                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
14034                    }
14035                    else {
14036                            bindTitle = true;
14037    
14038                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
14039                    }
14040    
14041                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
14042    
14043                    if (!getDB().isSupportsInlineDistinct()) {
14044                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
14045                    }
14046    
14047                    if (orderByComparator != null) {
14048                            if (getDB().isSupportsInlineDistinct()) {
14049                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14050                                            orderByComparator, true);
14051                            }
14052                            else {
14053                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
14054                                            orderByComparator, true);
14055                            }
14056                    }
14057                    else {
14058                            if (getDB().isSupportsInlineDistinct()) {
14059                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14060                            }
14061                            else {
14062                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
14063                            }
14064                    }
14065    
14066                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14067                                    WikiPage.class.getName(),
14068                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14069    
14070                    Session session = null;
14071    
14072                    try {
14073                            session = openSession();
14074    
14075                            SQLQuery q = session.createSQLQuery(sql);
14076    
14077                            if (getDB().isSupportsInlineDistinct()) {
14078                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
14079                            }
14080                            else {
14081                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
14082                            }
14083    
14084                            QueryPos qPos = QueryPos.getInstance(q);
14085    
14086                            qPos.add(groupId);
14087    
14088                            qPos.add(nodeId);
14089    
14090                            if (bindTitle) {
14091                                    qPos.add(title.toLowerCase());
14092                            }
14093    
14094                            qPos.add(head);
14095    
14096                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
14097                    }
14098                    catch (Exception e) {
14099                            throw processException(e);
14100                    }
14101                    finally {
14102                            closeSession(session);
14103                    }
14104            }
14105    
14106            /**
14107             * 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;.
14108             *
14109             * @param pageId the primary key of the current wiki page
14110             * @param groupId the group ID
14111             * @param nodeId the node ID
14112             * @param title the title
14113             * @param head the head
14114             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14115             * @return the previous, current, and next wiki page
14116             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
14117             * @throws SystemException if a system exception occurred
14118             */
14119            @Override
14120            public WikiPage[] filterFindByG_N_T_H_PrevAndNext(long pageId,
14121                    long groupId, long nodeId, String title, boolean head,
14122                    OrderByComparator orderByComparator)
14123                    throws NoSuchPageException, SystemException {
14124                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14125                            return findByG_N_T_H_PrevAndNext(pageId, groupId, nodeId, title,
14126                                    head, orderByComparator);
14127                    }
14128    
14129                    WikiPage wikiPage = findByPrimaryKey(pageId);
14130    
14131                    Session session = null;
14132    
14133                    try {
14134                            session = openSession();
14135    
14136                            WikiPage[] array = new WikiPageImpl[3];
14137    
14138                            array[0] = filterGetByG_N_T_H_PrevAndNext(session, wikiPage,
14139                                            groupId, nodeId, title, head, orderByComparator, true);
14140    
14141                            array[1] = wikiPage;
14142    
14143                            array[2] = filterGetByG_N_T_H_PrevAndNext(session, wikiPage,
14144                                            groupId, nodeId, title, head, orderByComparator, false);
14145    
14146                            return array;
14147                    }
14148                    catch (Exception e) {
14149                            throw processException(e);
14150                    }
14151                    finally {
14152                            closeSession(session);
14153                    }
14154            }
14155    
14156            protected WikiPage filterGetByG_N_T_H_PrevAndNext(Session session,
14157                    WikiPage wikiPage, long groupId, long nodeId, String title,
14158                    boolean head, OrderByComparator orderByComparator, boolean previous) {
14159                    StringBundler query = null;
14160    
14161                    if (orderByComparator != null) {
14162                            query = new StringBundler(6 +
14163                                            (orderByComparator.getOrderByFields().length * 6));
14164                    }
14165                    else {
14166                            query = new StringBundler(3);
14167                    }
14168    
14169                    if (getDB().isSupportsInlineDistinct()) {
14170                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
14171                    }
14172                    else {
14173                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
14174                    }
14175    
14176                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
14177    
14178                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
14179    
14180                    boolean bindTitle = false;
14181    
14182                    if (title == null) {
14183                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
14184                    }
14185                    else if (title.equals(StringPool.BLANK)) {
14186                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
14187                    }
14188                    else {
14189                            bindTitle = true;
14190    
14191                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
14192                    }
14193    
14194                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
14195    
14196                    if (!getDB().isSupportsInlineDistinct()) {
14197                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
14198                    }
14199    
14200                    if (orderByComparator != null) {
14201                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14202    
14203                            if (orderByConditionFields.length > 0) {
14204                                    query.append(WHERE_AND);
14205                            }
14206    
14207                            for (int i = 0; i < orderByConditionFields.length; i++) {
14208                                    if (getDB().isSupportsInlineDistinct()) {
14209                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14210                                    }
14211                                    else {
14212                                            query.append(_ORDER_BY_ENTITY_TABLE);
14213                                    }
14214    
14215                                    query.append(orderByConditionFields[i]);
14216    
14217                                    if ((i + 1) < orderByConditionFields.length) {
14218                                            if (orderByComparator.isAscending() ^ previous) {
14219                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14220                                            }
14221                                            else {
14222                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14223                                            }
14224                                    }
14225                                    else {
14226                                            if (orderByComparator.isAscending() ^ previous) {
14227                                                    query.append(WHERE_GREATER_THAN);
14228                                            }
14229                                            else {
14230                                                    query.append(WHERE_LESSER_THAN);
14231                                            }
14232                                    }
14233                            }
14234    
14235                            query.append(ORDER_BY_CLAUSE);
14236    
14237                            String[] orderByFields = orderByComparator.getOrderByFields();
14238    
14239                            for (int i = 0; i < orderByFields.length; i++) {
14240                                    if (getDB().isSupportsInlineDistinct()) {
14241                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14242                                    }
14243                                    else {
14244                                            query.append(_ORDER_BY_ENTITY_TABLE);
14245                                    }
14246    
14247                                    query.append(orderByFields[i]);
14248    
14249                                    if ((i + 1) < orderByFields.length) {
14250                                            if (orderByComparator.isAscending() ^ previous) {
14251                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14252                                            }
14253                                            else {
14254                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14255                                            }
14256                                    }
14257                                    else {
14258                                            if (orderByComparator.isAscending() ^ previous) {
14259                                                    query.append(ORDER_BY_ASC);
14260                                            }
14261                                            else {
14262                                                    query.append(ORDER_BY_DESC);
14263                                            }
14264                                    }
14265                            }
14266                    }
14267                    else {
14268                            if (getDB().isSupportsInlineDistinct()) {
14269                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14270                            }
14271                            else {
14272                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
14273                            }
14274                    }
14275    
14276                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14277                                    WikiPage.class.getName(),
14278                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14279    
14280                    SQLQuery q = session.createSQLQuery(sql);
14281    
14282                    q.setFirstResult(0);
14283                    q.setMaxResults(2);
14284    
14285                    if (getDB().isSupportsInlineDistinct()) {
14286                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
14287                    }
14288                    else {
14289                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
14290                    }
14291    
14292                    QueryPos qPos = QueryPos.getInstance(q);
14293    
14294                    qPos.add(groupId);
14295    
14296                    qPos.add(nodeId);
14297    
14298                    if (bindTitle) {
14299                            qPos.add(title.toLowerCase());
14300                    }
14301    
14302                    qPos.add(head);
14303    
14304                    if (orderByComparator != null) {
14305                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
14306    
14307                            for (Object value : values) {
14308                                    qPos.add(value);
14309                            }
14310                    }
14311    
14312                    List<WikiPage> list = q.list();
14313    
14314                    if (list.size() == 2) {
14315                            return list.get(1);
14316                    }
14317                    else {
14318                            return null;
14319                    }
14320            }
14321    
14322            /**
14323             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63; from the database.
14324             *
14325             * @param groupId the group ID
14326             * @param nodeId the node ID
14327             * @param title the title
14328             * @param head the head
14329             * @throws SystemException if a system exception occurred
14330             */
14331            @Override
14332            public void removeByG_N_T_H(long groupId, long nodeId, String title,
14333                    boolean head) throws SystemException {
14334                    for (WikiPage wikiPage : findByG_N_T_H(groupId, nodeId, title, head,
14335                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14336                            remove(wikiPage);
14337                    }
14338            }
14339    
14340            /**
14341             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
14342             *
14343             * @param groupId the group ID
14344             * @param nodeId the node ID
14345             * @param title the title
14346             * @param head the head
14347             * @return the number of matching wiki pages
14348             * @throws SystemException if a system exception occurred
14349             */
14350            @Override
14351            public int countByG_N_T_H(long groupId, long nodeId, String title,
14352                    boolean head) throws SystemException {
14353                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_T_H;
14354    
14355                    Object[] finderArgs = new Object[] { groupId, nodeId, title, head };
14356    
14357                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14358                                    this);
14359    
14360                    if (count == null) {
14361                            StringBundler query = new StringBundler(5);
14362    
14363                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
14364    
14365                            query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
14366    
14367                            query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
14368    
14369                            boolean bindTitle = false;
14370    
14371                            if (title == null) {
14372                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
14373                            }
14374                            else if (title.equals(StringPool.BLANK)) {
14375                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
14376                            }
14377                            else {
14378                                    bindTitle = true;
14379    
14380                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
14381                            }
14382    
14383                            query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
14384    
14385                            String sql = query.toString();
14386    
14387                            Session session = null;
14388    
14389                            try {
14390                                    session = openSession();
14391    
14392                                    Query q = session.createQuery(sql);
14393    
14394                                    QueryPos qPos = QueryPos.getInstance(q);
14395    
14396                                    qPos.add(groupId);
14397    
14398                                    qPos.add(nodeId);
14399    
14400                                    if (bindTitle) {
14401                                            qPos.add(title.toLowerCase());
14402                                    }
14403    
14404                                    qPos.add(head);
14405    
14406                                    count = (Long)q.uniqueResult();
14407    
14408                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14409                            }
14410                            catch (Exception e) {
14411                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14412    
14413                                    throw processException(e);
14414                            }
14415                            finally {
14416                                    closeSession(session);
14417                            }
14418                    }
14419    
14420                    return count.intValue();
14421            }
14422    
14423            /**
14424             * 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;.
14425             *
14426             * @param groupId the group ID
14427             * @param nodeId the node ID
14428             * @param title the title
14429             * @param head the head
14430             * @return the number of matching wiki pages that the user has permission to view
14431             * @throws SystemException if a system exception occurred
14432             */
14433            @Override
14434            public int filterCountByG_N_T_H(long groupId, long nodeId, String title,
14435                    boolean head) throws SystemException {
14436                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14437                            return countByG_N_T_H(groupId, nodeId, title, head);
14438                    }
14439    
14440                    StringBundler query = new StringBundler(5);
14441    
14442                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
14443    
14444                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
14445    
14446                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
14447    
14448                    boolean bindTitle = false;
14449    
14450                    if (title == null) {
14451                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
14452                    }
14453                    else if (title.equals(StringPool.BLANK)) {
14454                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
14455                    }
14456                    else {
14457                            bindTitle = true;
14458    
14459                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
14460                    }
14461    
14462                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
14463    
14464                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14465                                    WikiPage.class.getName(),
14466                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14467    
14468                    Session session = null;
14469    
14470                    try {
14471                            session = openSession();
14472    
14473                            SQLQuery q = session.createSQLQuery(sql);
14474    
14475                            q.addScalar(COUNT_COLUMN_NAME,
14476                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
14477    
14478                            QueryPos qPos = QueryPos.getInstance(q);
14479    
14480                            qPos.add(groupId);
14481    
14482                            qPos.add(nodeId);
14483    
14484                            if (bindTitle) {
14485                                    qPos.add(title.toLowerCase());
14486                            }
14487    
14488                            qPos.add(head);
14489    
14490                            Long count = (Long)q.uniqueResult();
14491    
14492                            return count.intValue();
14493                    }
14494                    catch (Exception e) {
14495                            throw processException(e);
14496                    }
14497                    finally {
14498                            closeSession(session);
14499                    }
14500            }
14501    
14502            private static final String _FINDER_COLUMN_G_N_T_H_GROUPID_2 = "wikiPage.groupId = ? AND ";
14503            private static final String _FINDER_COLUMN_G_N_T_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
14504            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_1 = "wikiPage.title IS NULL AND ";
14505            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_2 = "lower(wikiPage.title) = ? AND ";
14506            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '') AND ";
14507            private static final String _FINDER_COLUMN_G_N_T_H_HEAD_2 = "wikiPage.head = ?";
14508            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14509                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
14510                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H_S",
14511                            new String[] {
14512                                    Long.class.getName(), Long.class.getName(),
14513                                    Boolean.class.getName(), Integer.class.getName(),
14514                                    
14515                            Integer.class.getName(), Integer.class.getName(),
14516                                    OrderByComparator.class.getName()
14517                            });
14518            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S =
14519                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14520                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
14521                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H_S",
14522                            new String[] {
14523                                    Long.class.getName(), Long.class.getName(),
14524                                    Boolean.class.getName(), Integer.class.getName()
14525                            },
14526                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
14527                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
14528                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
14529                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
14530                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
14531                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
14532            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14533                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14534                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H_S",
14535                            new String[] {
14536                                    Long.class.getName(), Long.class.getName(),
14537                                    Boolean.class.getName(), Integer.class.getName()
14538                            });
14539    
14540            /**
14541             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14542             *
14543             * @param groupId the group ID
14544             * @param nodeId the node ID
14545             * @param head the head
14546             * @param status the status
14547             * @return the matching wiki pages
14548             * @throws SystemException if a system exception occurred
14549             */
14550            @Override
14551            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
14552                    boolean head, int status) throws SystemException {
14553                    return findByG_N_H_S(groupId, nodeId, head, status, QueryUtil.ALL_POS,
14554                            QueryUtil.ALL_POS, null);
14555            }
14556    
14557            /**
14558             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14559             *
14560             * <p>
14561             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14562             * </p>
14563             *
14564             * @param groupId the group ID
14565             * @param nodeId the node ID
14566             * @param head the head
14567             * @param status the status
14568             * @param start the lower bound of the range of wiki pages
14569             * @param end the upper bound of the range of wiki pages (not inclusive)
14570             * @return the range of matching wiki pages
14571             * @throws SystemException if a system exception occurred
14572             */
14573            @Override
14574            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
14575                    boolean head, int status, int start, int end) throws SystemException {
14576                    return findByG_N_H_S(groupId, nodeId, head, status, start, end, null);
14577            }
14578    
14579            /**
14580             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14581             *
14582             * <p>
14583             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14584             * </p>
14585             *
14586             * @param groupId the group ID
14587             * @param nodeId the node ID
14588             * @param head the head
14589             * @param status the status
14590             * @param start the lower bound of the range of wiki pages
14591             * @param end the upper bound of the range of wiki pages (not inclusive)
14592             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14593             * @return the ordered range of matching wiki pages
14594             * @throws SystemException if a system exception occurred
14595             */
14596            @Override
14597            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
14598                    boolean head, int status, int start, int end,
14599                    OrderByComparator orderByComparator) throws SystemException {
14600                    boolean pagination = true;
14601                    FinderPath finderPath = null;
14602                    Object[] finderArgs = null;
14603    
14604                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14605                                    (orderByComparator == null)) {
14606                            pagination = false;
14607                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S;
14608                            finderArgs = new Object[] { groupId, nodeId, head, status };
14609                    }
14610                    else {
14611                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_S;
14612                            finderArgs = new Object[] {
14613                                            groupId, nodeId, head, status,
14614                                            
14615                                            start, end, orderByComparator
14616                                    };
14617                    }
14618    
14619                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
14620                                    finderArgs, this);
14621    
14622                    if ((list != null) && !list.isEmpty()) {
14623                            for (WikiPage wikiPage : list) {
14624                                    if ((groupId != wikiPage.getGroupId()) ||
14625                                                    (nodeId != wikiPage.getNodeId()) ||
14626                                                    (head != wikiPage.getHead()) ||
14627                                                    (status != wikiPage.getStatus())) {
14628                                            list = null;
14629    
14630                                            break;
14631                                    }
14632                            }
14633                    }
14634    
14635                    if (list == null) {
14636                            StringBundler query = null;
14637    
14638                            if (orderByComparator != null) {
14639                                    query = new StringBundler(6 +
14640                                                    (orderByComparator.getOrderByFields().length * 3));
14641                            }
14642                            else {
14643                                    query = new StringBundler(6);
14644                            }
14645    
14646                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
14647    
14648                            query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
14649    
14650                            query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
14651    
14652                            query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
14653    
14654                            query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
14655    
14656                            if (orderByComparator != null) {
14657                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14658                                            orderByComparator);
14659                            }
14660                            else
14661                             if (pagination) {
14662                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14663                            }
14664    
14665                            String sql = query.toString();
14666    
14667                            Session session = null;
14668    
14669                            try {
14670                                    session = openSession();
14671    
14672                                    Query q = session.createQuery(sql);
14673    
14674                                    QueryPos qPos = QueryPos.getInstance(q);
14675    
14676                                    qPos.add(groupId);
14677    
14678                                    qPos.add(nodeId);
14679    
14680                                    qPos.add(head);
14681    
14682                                    qPos.add(status);
14683    
14684                                    if (!pagination) {
14685                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
14686                                                            start, end, false);
14687    
14688                                            Collections.sort(list);
14689    
14690                                            list = new UnmodifiableList<WikiPage>(list);
14691                                    }
14692                                    else {
14693                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
14694                                                            start, end);
14695                                    }
14696    
14697                                    cacheResult(list);
14698    
14699                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
14700                            }
14701                            catch (Exception e) {
14702                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14703    
14704                                    throw processException(e);
14705                            }
14706                            finally {
14707                                    closeSession(session);
14708                            }
14709                    }
14710    
14711                    return list;
14712            }
14713    
14714            /**
14715             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14716             *
14717             * @param groupId the group ID
14718             * @param nodeId the node ID
14719             * @param head the head
14720             * @param status the status
14721             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14722             * @return the first matching wiki page
14723             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
14724             * @throws SystemException if a system exception occurred
14725             */
14726            @Override
14727            public WikiPage findByG_N_H_S_First(long groupId, long nodeId,
14728                    boolean head, int status, OrderByComparator orderByComparator)
14729                    throws NoSuchPageException, SystemException {
14730                    WikiPage wikiPage = fetchByG_N_H_S_First(groupId, nodeId, head, status,
14731                                    orderByComparator);
14732    
14733                    if (wikiPage != null) {
14734                            return wikiPage;
14735                    }
14736    
14737                    StringBundler msg = new StringBundler(10);
14738    
14739                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14740    
14741                    msg.append("groupId=");
14742                    msg.append(groupId);
14743    
14744                    msg.append(", nodeId=");
14745                    msg.append(nodeId);
14746    
14747                    msg.append(", head=");
14748                    msg.append(head);
14749    
14750                    msg.append(", status=");
14751                    msg.append(status);
14752    
14753                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14754    
14755                    throw new NoSuchPageException(msg.toString());
14756            }
14757    
14758            /**
14759             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14760             *
14761             * @param groupId the group ID
14762             * @param nodeId the node ID
14763             * @param head the head
14764             * @param status the status
14765             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14766             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
14767             * @throws SystemException if a system exception occurred
14768             */
14769            @Override
14770            public WikiPage fetchByG_N_H_S_First(long groupId, long nodeId,
14771                    boolean head, int status, OrderByComparator orderByComparator)
14772                    throws SystemException {
14773                    List<WikiPage> list = findByG_N_H_S(groupId, nodeId, head, status, 0,
14774                                    1, orderByComparator);
14775    
14776                    if (!list.isEmpty()) {
14777                            return list.get(0);
14778                    }
14779    
14780                    return null;
14781            }
14782    
14783            /**
14784             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14785             *
14786             * @param groupId the group ID
14787             * @param nodeId the node ID
14788             * @param head the head
14789             * @param status the status
14790             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14791             * @return the last matching wiki page
14792             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
14793             * @throws SystemException if a system exception occurred
14794             */
14795            @Override
14796            public WikiPage findByG_N_H_S_Last(long groupId, long nodeId, boolean head,
14797                    int status, OrderByComparator orderByComparator)
14798                    throws NoSuchPageException, SystemException {
14799                    WikiPage wikiPage = fetchByG_N_H_S_Last(groupId, nodeId, head, status,
14800                                    orderByComparator);
14801    
14802                    if (wikiPage != null) {
14803                            return wikiPage;
14804                    }
14805    
14806                    StringBundler msg = new StringBundler(10);
14807    
14808                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14809    
14810                    msg.append("groupId=");
14811                    msg.append(groupId);
14812    
14813                    msg.append(", nodeId=");
14814                    msg.append(nodeId);
14815    
14816                    msg.append(", head=");
14817                    msg.append(head);
14818    
14819                    msg.append(", status=");
14820                    msg.append(status);
14821    
14822                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14823    
14824                    throw new NoSuchPageException(msg.toString());
14825            }
14826    
14827            /**
14828             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14829             *
14830             * @param groupId the group ID
14831             * @param nodeId the node ID
14832             * @param head the head
14833             * @param status the status
14834             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14835             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
14836             * @throws SystemException if a system exception occurred
14837             */
14838            @Override
14839            public WikiPage fetchByG_N_H_S_Last(long groupId, long nodeId,
14840                    boolean head, int status, OrderByComparator orderByComparator)
14841                    throws SystemException {
14842                    int count = countByG_N_H_S(groupId, nodeId, head, status);
14843    
14844                    if (count == 0) {
14845                            return null;
14846                    }
14847    
14848                    List<WikiPage> list = findByG_N_H_S(groupId, nodeId, head, status,
14849                                    count - 1, count, orderByComparator);
14850    
14851                    if (!list.isEmpty()) {
14852                            return list.get(0);
14853                    }
14854    
14855                    return null;
14856            }
14857    
14858            /**
14859             * 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;.
14860             *
14861             * @param pageId the primary key of the current wiki page
14862             * @param groupId the group ID
14863             * @param nodeId the node ID
14864             * @param head the head
14865             * @param status the status
14866             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14867             * @return the previous, current, and next wiki page
14868             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
14869             * @throws SystemException if a system exception occurred
14870             */
14871            @Override
14872            public WikiPage[] findByG_N_H_S_PrevAndNext(long pageId, long groupId,
14873                    long nodeId, boolean head, int status,
14874                    OrderByComparator orderByComparator)
14875                    throws NoSuchPageException, SystemException {
14876                    WikiPage wikiPage = findByPrimaryKey(pageId);
14877    
14878                    Session session = null;
14879    
14880                    try {
14881                            session = openSession();
14882    
14883                            WikiPage[] array = new WikiPageImpl[3];
14884    
14885                            array[0] = getByG_N_H_S_PrevAndNext(session, wikiPage, groupId,
14886                                            nodeId, head, status, orderByComparator, true);
14887    
14888                            array[1] = wikiPage;
14889    
14890                            array[2] = getByG_N_H_S_PrevAndNext(session, wikiPage, groupId,
14891                                            nodeId, head, status, orderByComparator, false);
14892    
14893                            return array;
14894                    }
14895                    catch (Exception e) {
14896                            throw processException(e);
14897                    }
14898                    finally {
14899                            closeSession(session);
14900                    }
14901            }
14902    
14903            protected WikiPage getByG_N_H_S_PrevAndNext(Session session,
14904                    WikiPage wikiPage, long groupId, long nodeId, boolean head, int status,
14905                    OrderByComparator orderByComparator, boolean previous) {
14906                    StringBundler query = null;
14907    
14908                    if (orderByComparator != null) {
14909                            query = new StringBundler(6 +
14910                                            (orderByComparator.getOrderByFields().length * 6));
14911                    }
14912                    else {
14913                            query = new StringBundler(3);
14914                    }
14915    
14916                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
14917    
14918                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
14919    
14920                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
14921    
14922                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
14923    
14924                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
14925    
14926                    if (orderByComparator != null) {
14927                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14928    
14929                            if (orderByConditionFields.length > 0) {
14930                                    query.append(WHERE_AND);
14931                            }
14932    
14933                            for (int i = 0; i < orderByConditionFields.length; i++) {
14934                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14935                                    query.append(orderByConditionFields[i]);
14936    
14937                                    if ((i + 1) < orderByConditionFields.length) {
14938                                            if (orderByComparator.isAscending() ^ previous) {
14939                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14940                                            }
14941                                            else {
14942                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14943                                            }
14944                                    }
14945                                    else {
14946                                            if (orderByComparator.isAscending() ^ previous) {
14947                                                    query.append(WHERE_GREATER_THAN);
14948                                            }
14949                                            else {
14950                                                    query.append(WHERE_LESSER_THAN);
14951                                            }
14952                                    }
14953                            }
14954    
14955                            query.append(ORDER_BY_CLAUSE);
14956    
14957                            String[] orderByFields = orderByComparator.getOrderByFields();
14958    
14959                            for (int i = 0; i < orderByFields.length; i++) {
14960                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14961                                    query.append(orderByFields[i]);
14962    
14963                                    if ((i + 1) < orderByFields.length) {
14964                                            if (orderByComparator.isAscending() ^ previous) {
14965                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14966                                            }
14967                                            else {
14968                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14969                                            }
14970                                    }
14971                                    else {
14972                                            if (orderByComparator.isAscending() ^ previous) {
14973                                                    query.append(ORDER_BY_ASC);
14974                                            }
14975                                            else {
14976                                                    query.append(ORDER_BY_DESC);
14977                                            }
14978                                    }
14979                            }
14980                    }
14981                    else {
14982                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14983                    }
14984    
14985                    String sql = query.toString();
14986    
14987                    Query q = session.createQuery(sql);
14988    
14989                    q.setFirstResult(0);
14990                    q.setMaxResults(2);
14991    
14992                    QueryPos qPos = QueryPos.getInstance(q);
14993    
14994                    qPos.add(groupId);
14995    
14996                    qPos.add(nodeId);
14997    
14998                    qPos.add(head);
14999    
15000                    qPos.add(status);
15001    
15002                    if (orderByComparator != null) {
15003                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
15004    
15005                            for (Object value : values) {
15006                                    qPos.add(value);
15007                            }
15008                    }
15009    
15010                    List<WikiPage> list = q.list();
15011    
15012                    if (list.size() == 2) {
15013                            return list.get(1);
15014                    }
15015                    else {
15016                            return null;
15017                    }
15018            }
15019    
15020            /**
15021             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
15022             *
15023             * @param groupId the group ID
15024             * @param nodeId the node ID
15025             * @param head the head
15026             * @param status the status
15027             * @return the matching wiki pages that the user has permission to view
15028             * @throws SystemException if a system exception occurred
15029             */
15030            @Override
15031            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
15032                    boolean head, int status) throws SystemException {
15033                    return filterFindByG_N_H_S(groupId, nodeId, head, status,
15034                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15035            }
15036    
15037            /**
15038             * 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;.
15039             *
15040             * <p>
15041             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15042             * </p>
15043             *
15044             * @param groupId the group ID
15045             * @param nodeId the node ID
15046             * @param head the head
15047             * @param status the status
15048             * @param start the lower bound of the range of wiki pages
15049             * @param end the upper bound of the range of wiki pages (not inclusive)
15050             * @return the range of matching wiki pages that the user has permission to view
15051             * @throws SystemException if a system exception occurred
15052             */
15053            @Override
15054            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
15055                    boolean head, int status, int start, int end) throws SystemException {
15056                    return filterFindByG_N_H_S(groupId, nodeId, head, status, start, end,
15057                            null);
15058            }
15059    
15060            /**
15061             * 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;.
15062             *
15063             * <p>
15064             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15065             * </p>
15066             *
15067             * @param groupId the group ID
15068             * @param nodeId the node ID
15069             * @param head the head
15070             * @param status the status
15071             * @param start the lower bound of the range of wiki pages
15072             * @param end the upper bound of the range of wiki pages (not inclusive)
15073             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15074             * @return the ordered range of matching wiki pages that the user has permission to view
15075             * @throws SystemException if a system exception occurred
15076             */
15077            @Override
15078            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
15079                    boolean head, int status, int start, int end,
15080                    OrderByComparator orderByComparator) throws SystemException {
15081                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15082                            return findByG_N_H_S(groupId, nodeId, head, status, start, end,
15083                                    orderByComparator);
15084                    }
15085    
15086                    StringBundler query = null;
15087    
15088                    if (orderByComparator != null) {
15089                            query = new StringBundler(6 +
15090                                            (orderByComparator.getOrderByFields().length * 3));
15091                    }
15092                    else {
15093                            query = new StringBundler(6);
15094                    }
15095    
15096                    if (getDB().isSupportsInlineDistinct()) {
15097                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
15098                    }
15099                    else {
15100                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
15101                    }
15102    
15103                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
15104    
15105                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
15106    
15107                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
15108    
15109                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
15110    
15111                    if (!getDB().isSupportsInlineDistinct()) {
15112                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
15113                    }
15114    
15115                    if (orderByComparator != null) {
15116                            if (getDB().isSupportsInlineDistinct()) {
15117                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15118                                            orderByComparator, true);
15119                            }
15120                            else {
15121                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
15122                                            orderByComparator, true);
15123                            }
15124                    }
15125                    else {
15126                            if (getDB().isSupportsInlineDistinct()) {
15127                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15128                            }
15129                            else {
15130                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
15131                            }
15132                    }
15133    
15134                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15135                                    WikiPage.class.getName(),
15136                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15137    
15138                    Session session = null;
15139    
15140                    try {
15141                            session = openSession();
15142    
15143                            SQLQuery q = session.createSQLQuery(sql);
15144    
15145                            if (getDB().isSupportsInlineDistinct()) {
15146                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
15147                            }
15148                            else {
15149                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
15150                            }
15151    
15152                            QueryPos qPos = QueryPos.getInstance(q);
15153    
15154                            qPos.add(groupId);
15155    
15156                            qPos.add(nodeId);
15157    
15158                            qPos.add(head);
15159    
15160                            qPos.add(status);
15161    
15162                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
15163                    }
15164                    catch (Exception e) {
15165                            throw processException(e);
15166                    }
15167                    finally {
15168                            closeSession(session);
15169                    }
15170            }
15171    
15172            /**
15173             * 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;.
15174             *
15175             * @param pageId the primary key of the current wiki page
15176             * @param groupId the group ID
15177             * @param nodeId the node ID
15178             * @param head the head
15179             * @param status the status
15180             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15181             * @return the previous, current, and next wiki page
15182             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
15183             * @throws SystemException if a system exception occurred
15184             */
15185            @Override
15186            public WikiPage[] filterFindByG_N_H_S_PrevAndNext(long pageId,
15187                    long groupId, long nodeId, boolean head, int status,
15188                    OrderByComparator orderByComparator)
15189                    throws NoSuchPageException, SystemException {
15190                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15191                            return findByG_N_H_S_PrevAndNext(pageId, groupId, nodeId, head,
15192                                    status, orderByComparator);
15193                    }
15194    
15195                    WikiPage wikiPage = findByPrimaryKey(pageId);
15196    
15197                    Session session = null;
15198    
15199                    try {
15200                            session = openSession();
15201    
15202                            WikiPage[] array = new WikiPageImpl[3];
15203    
15204                            array[0] = filterGetByG_N_H_S_PrevAndNext(session, wikiPage,
15205                                            groupId, nodeId, head, status, orderByComparator, true);
15206    
15207                            array[1] = wikiPage;
15208    
15209                            array[2] = filterGetByG_N_H_S_PrevAndNext(session, wikiPage,
15210                                            groupId, nodeId, head, status, orderByComparator, false);
15211    
15212                            return array;
15213                    }
15214                    catch (Exception e) {
15215                            throw processException(e);
15216                    }
15217                    finally {
15218                            closeSession(session);
15219                    }
15220            }
15221    
15222            protected WikiPage filterGetByG_N_H_S_PrevAndNext(Session session,
15223                    WikiPage wikiPage, long groupId, long nodeId, boolean head, int status,
15224                    OrderByComparator orderByComparator, boolean previous) {
15225                    StringBundler query = null;
15226    
15227                    if (orderByComparator != null) {
15228                            query = new StringBundler(6 +
15229                                            (orderByComparator.getOrderByFields().length * 6));
15230                    }
15231                    else {
15232                            query = new StringBundler(3);
15233                    }
15234    
15235                    if (getDB().isSupportsInlineDistinct()) {
15236                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
15237                    }
15238                    else {
15239                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
15240                    }
15241    
15242                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
15243    
15244                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
15245    
15246                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
15247    
15248                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
15249    
15250                    if (!getDB().isSupportsInlineDistinct()) {
15251                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
15252                    }
15253    
15254                    if (orderByComparator != null) {
15255                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15256    
15257                            if (orderByConditionFields.length > 0) {
15258                                    query.append(WHERE_AND);
15259                            }
15260    
15261                            for (int i = 0; i < orderByConditionFields.length; i++) {
15262                                    if (getDB().isSupportsInlineDistinct()) {
15263                                            query.append(_ORDER_BY_ENTITY_ALIAS);
15264                                    }
15265                                    else {
15266                                            query.append(_ORDER_BY_ENTITY_TABLE);
15267                                    }
15268    
15269                                    query.append(orderByConditionFields[i]);
15270    
15271                                    if ((i + 1) < orderByConditionFields.length) {
15272                                            if (orderByComparator.isAscending() ^ previous) {
15273                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15274                                            }
15275                                            else {
15276                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15277                                            }
15278                                    }
15279                                    else {
15280                                            if (orderByComparator.isAscending() ^ previous) {
15281                                                    query.append(WHERE_GREATER_THAN);
15282                                            }
15283                                            else {
15284                                                    query.append(WHERE_LESSER_THAN);
15285                                            }
15286                                    }
15287                            }
15288    
15289                            query.append(ORDER_BY_CLAUSE);
15290    
15291                            String[] orderByFields = orderByComparator.getOrderByFields();
15292    
15293                            for (int i = 0; i < orderByFields.length; i++) {
15294                                    if (getDB().isSupportsInlineDistinct()) {
15295                                            query.append(_ORDER_BY_ENTITY_ALIAS);
15296                                    }
15297                                    else {
15298                                            query.append(_ORDER_BY_ENTITY_TABLE);
15299                                    }
15300    
15301                                    query.append(orderByFields[i]);
15302    
15303                                    if ((i + 1) < orderByFields.length) {
15304                                            if (orderByComparator.isAscending() ^ previous) {
15305                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15306                                            }
15307                                            else {
15308                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15309                                            }
15310                                    }
15311                                    else {
15312                                            if (orderByComparator.isAscending() ^ previous) {
15313                                                    query.append(ORDER_BY_ASC);
15314                                            }
15315                                            else {
15316                                                    query.append(ORDER_BY_DESC);
15317                                            }
15318                                    }
15319                            }
15320                    }
15321                    else {
15322                            if (getDB().isSupportsInlineDistinct()) {
15323                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15324                            }
15325                            else {
15326                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
15327                            }
15328                    }
15329    
15330                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15331                                    WikiPage.class.getName(),
15332                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15333    
15334                    SQLQuery q = session.createSQLQuery(sql);
15335    
15336                    q.setFirstResult(0);
15337                    q.setMaxResults(2);
15338    
15339                    if (getDB().isSupportsInlineDistinct()) {
15340                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
15341                    }
15342                    else {
15343                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
15344                    }
15345    
15346                    QueryPos qPos = QueryPos.getInstance(q);
15347    
15348                    qPos.add(groupId);
15349    
15350                    qPos.add(nodeId);
15351    
15352                    qPos.add(head);
15353    
15354                    qPos.add(status);
15355    
15356                    if (orderByComparator != null) {
15357                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
15358    
15359                            for (Object value : values) {
15360                                    qPos.add(value);
15361                            }
15362                    }
15363    
15364                    List<WikiPage> list = q.list();
15365    
15366                    if (list.size() == 2) {
15367                            return list.get(1);
15368                    }
15369                    else {
15370                            return null;
15371                    }
15372            }
15373    
15374            /**
15375             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63; from the database.
15376             *
15377             * @param groupId the group ID
15378             * @param nodeId the node ID
15379             * @param head the head
15380             * @param status the status
15381             * @throws SystemException if a system exception occurred
15382             */
15383            @Override
15384            public void removeByG_N_H_S(long groupId, long nodeId, boolean head,
15385                    int status) throws SystemException {
15386                    for (WikiPage wikiPage : findByG_N_H_S(groupId, nodeId, head, status,
15387                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15388                            remove(wikiPage);
15389                    }
15390            }
15391    
15392            /**
15393             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
15394             *
15395             * @param groupId the group ID
15396             * @param nodeId the node ID
15397             * @param head the head
15398             * @param status the status
15399             * @return the number of matching wiki pages
15400             * @throws SystemException if a system exception occurred
15401             */
15402            @Override
15403            public int countByG_N_H_S(long groupId, long nodeId, boolean head,
15404                    int status) throws SystemException {
15405                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H_S;
15406    
15407                    Object[] finderArgs = new Object[] { groupId, nodeId, head, status };
15408    
15409                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15410                                    this);
15411    
15412                    if (count == null) {
15413                            StringBundler query = new StringBundler(5);
15414    
15415                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
15416    
15417                            query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
15418    
15419                            query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
15420    
15421                            query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
15422    
15423                            query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
15424    
15425                            String sql = query.toString();
15426    
15427                            Session session = null;
15428    
15429                            try {
15430                                    session = openSession();
15431    
15432                                    Query q = session.createQuery(sql);
15433    
15434                                    QueryPos qPos = QueryPos.getInstance(q);
15435    
15436                                    qPos.add(groupId);
15437    
15438                                    qPos.add(nodeId);
15439    
15440                                    qPos.add(head);
15441    
15442                                    qPos.add(status);
15443    
15444                                    count = (Long)q.uniqueResult();
15445    
15446                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15447                            }
15448                            catch (Exception e) {
15449                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15450    
15451                                    throw processException(e);
15452                            }
15453                            finally {
15454                                    closeSession(session);
15455                            }
15456                    }
15457    
15458                    return count.intValue();
15459            }
15460    
15461            /**
15462             * 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;.
15463             *
15464             * @param groupId the group ID
15465             * @param nodeId the node ID
15466             * @param head the head
15467             * @param status the status
15468             * @return the number of matching wiki pages that the user has permission to view
15469             * @throws SystemException if a system exception occurred
15470             */
15471            @Override
15472            public int filterCountByG_N_H_S(long groupId, long nodeId, boolean head,
15473                    int status) throws SystemException {
15474                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15475                            return countByG_N_H_S(groupId, nodeId, head, status);
15476                    }
15477    
15478                    StringBundler query = new StringBundler(5);
15479    
15480                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
15481    
15482                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
15483    
15484                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
15485    
15486                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
15487    
15488                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
15489    
15490                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15491                                    WikiPage.class.getName(),
15492                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15493    
15494                    Session session = null;
15495    
15496                    try {
15497                            session = openSession();
15498    
15499                            SQLQuery q = session.createSQLQuery(sql);
15500    
15501                            q.addScalar(COUNT_COLUMN_NAME,
15502                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
15503    
15504                            QueryPos qPos = QueryPos.getInstance(q);
15505    
15506                            qPos.add(groupId);
15507    
15508                            qPos.add(nodeId);
15509    
15510                            qPos.add(head);
15511    
15512                            qPos.add(status);
15513    
15514                            Long count = (Long)q.uniqueResult();
15515    
15516                            return count.intValue();
15517                    }
15518                    catch (Exception e) {
15519                            throw processException(e);
15520                    }
15521                    finally {
15522                            closeSession(session);
15523                    }
15524            }
15525    
15526            private static final String _FINDER_COLUMN_G_N_H_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
15527            private static final String _FINDER_COLUMN_G_N_H_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
15528            private static final String _FINDER_COLUMN_G_N_H_S_HEAD_2 = "wikiPage.head = ? AND ";
15529            private static final String _FINDER_COLUMN_G_N_H_S_STATUS_2 = "wikiPage.status = ?";
15530            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15531                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
15532                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_P_S",
15533                            new String[] {
15534                                    Long.class.getName(), Boolean.class.getName(),
15535                                    String.class.getName(), Integer.class.getName(),
15536                                    
15537                            Integer.class.getName(), Integer.class.getName(),
15538                                    OrderByComparator.class.getName()
15539                            });
15540            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S =
15541                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15542                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
15543                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_P_S",
15544                            new String[] {
15545                                    Long.class.getName(), Boolean.class.getName(),
15546                                    String.class.getName(), Integer.class.getName()
15547                            },
15548                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
15549                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
15550                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
15551                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
15552                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
15553                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
15554            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15555                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15556                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_P_S",
15557                            new String[] {
15558                                    Long.class.getName(), Boolean.class.getName(),
15559                                    String.class.getName(), Integer.class.getName()
15560                            });
15561    
15562            /**
15563             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15564             *
15565             * @param nodeId the node ID
15566             * @param head the head
15567             * @param parentTitle the parent title
15568             * @param status the status
15569             * @return the matching wiki pages
15570             * @throws SystemException if a system exception occurred
15571             */
15572            @Override
15573            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
15574                    String parentTitle, int status) throws SystemException {
15575                    return findByN_H_P_S(nodeId, head, parentTitle, status,
15576                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15577            }
15578    
15579            /**
15580             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15581             *
15582             * <p>
15583             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15584             * </p>
15585             *
15586             * @param nodeId the node ID
15587             * @param head the head
15588             * @param parentTitle the parent title
15589             * @param status the status
15590             * @param start the lower bound of the range of wiki pages
15591             * @param end the upper bound of the range of wiki pages (not inclusive)
15592             * @return the range of matching wiki pages
15593             * @throws SystemException if a system exception occurred
15594             */
15595            @Override
15596            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
15597                    String parentTitle, int status, int start, int end)
15598                    throws SystemException {
15599                    return findByN_H_P_S(nodeId, head, parentTitle, status, start, end, null);
15600            }
15601    
15602            /**
15603             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15604             *
15605             * <p>
15606             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15607             * </p>
15608             *
15609             * @param nodeId the node ID
15610             * @param head the head
15611             * @param parentTitle the parent title
15612             * @param status the status
15613             * @param start the lower bound of the range of wiki pages
15614             * @param end the upper bound of the range of wiki pages (not inclusive)
15615             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15616             * @return the ordered range of matching wiki pages
15617             * @throws SystemException if a system exception occurred
15618             */
15619            @Override
15620            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
15621                    String parentTitle, int status, int start, int end,
15622                    OrderByComparator orderByComparator) throws SystemException {
15623                    boolean pagination = true;
15624                    FinderPath finderPath = null;
15625                    Object[] finderArgs = null;
15626    
15627                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15628                                    (orderByComparator == null)) {
15629                            pagination = false;
15630                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S;
15631                            finderArgs = new Object[] { nodeId, head, parentTitle, status };
15632                    }
15633                    else {
15634                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_S;
15635                            finderArgs = new Object[] {
15636                                            nodeId, head, parentTitle, status,
15637                                            
15638                                            start, end, orderByComparator
15639                                    };
15640                    }
15641    
15642                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
15643                                    finderArgs, this);
15644    
15645                    if ((list != null) && !list.isEmpty()) {
15646                            for (WikiPage wikiPage : list) {
15647                                    if ((nodeId != wikiPage.getNodeId()) ||
15648                                                    (head != wikiPage.getHead()) ||
15649                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle()) ||
15650                                                    (status != wikiPage.getStatus())) {
15651                                            list = null;
15652    
15653                                            break;
15654                                    }
15655                            }
15656                    }
15657    
15658                    if (list == null) {
15659                            StringBundler query = null;
15660    
15661                            if (orderByComparator != null) {
15662                                    query = new StringBundler(6 +
15663                                                    (orderByComparator.getOrderByFields().length * 3));
15664                            }
15665                            else {
15666                                    query = new StringBundler(6);
15667                            }
15668    
15669                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
15670    
15671                            query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
15672    
15673                            query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
15674    
15675                            boolean bindParentTitle = false;
15676    
15677                            if (parentTitle == null) {
15678                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
15679                            }
15680                            else if (parentTitle.equals(StringPool.BLANK)) {
15681                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
15682                            }
15683                            else {
15684                                    bindParentTitle = true;
15685    
15686                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
15687                            }
15688    
15689                            query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
15690    
15691                            if (orderByComparator != null) {
15692                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15693                                            orderByComparator);
15694                            }
15695                            else
15696                             if (pagination) {
15697                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15698                            }
15699    
15700                            String sql = query.toString();
15701    
15702                            Session session = null;
15703    
15704                            try {
15705                                    session = openSession();
15706    
15707                                    Query q = session.createQuery(sql);
15708    
15709                                    QueryPos qPos = QueryPos.getInstance(q);
15710    
15711                                    qPos.add(nodeId);
15712    
15713                                    qPos.add(head);
15714    
15715                                    if (bindParentTitle) {
15716                                            qPos.add(parentTitle.toLowerCase());
15717                                    }
15718    
15719                                    qPos.add(status);
15720    
15721                                    if (!pagination) {
15722                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
15723                                                            start, end, false);
15724    
15725                                            Collections.sort(list);
15726    
15727                                            list = new UnmodifiableList<WikiPage>(list);
15728                                    }
15729                                    else {
15730                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
15731                                                            start, end);
15732                                    }
15733    
15734                                    cacheResult(list);
15735    
15736                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15737                            }
15738                            catch (Exception e) {
15739                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15740    
15741                                    throw processException(e);
15742                            }
15743                            finally {
15744                                    closeSession(session);
15745                            }
15746                    }
15747    
15748                    return list;
15749            }
15750    
15751            /**
15752             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15753             *
15754             * @param nodeId the node ID
15755             * @param head the head
15756             * @param parentTitle the parent title
15757             * @param status the status
15758             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15759             * @return the first matching wiki page
15760             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
15761             * @throws SystemException if a system exception occurred
15762             */
15763            @Override
15764            public WikiPage findByN_H_P_S_First(long nodeId, boolean head,
15765                    String parentTitle, int status, OrderByComparator orderByComparator)
15766                    throws NoSuchPageException, SystemException {
15767                    WikiPage wikiPage = fetchByN_H_P_S_First(nodeId, head, parentTitle,
15768                                    status, orderByComparator);
15769    
15770                    if (wikiPage != null) {
15771                            return wikiPage;
15772                    }
15773    
15774                    StringBundler msg = new StringBundler(10);
15775    
15776                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15777    
15778                    msg.append("nodeId=");
15779                    msg.append(nodeId);
15780    
15781                    msg.append(", head=");
15782                    msg.append(head);
15783    
15784                    msg.append(", parentTitle=");
15785                    msg.append(parentTitle);
15786    
15787                    msg.append(", status=");
15788                    msg.append(status);
15789    
15790                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15791    
15792                    throw new NoSuchPageException(msg.toString());
15793            }
15794    
15795            /**
15796             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15797             *
15798             * @param nodeId the node ID
15799             * @param head the head
15800             * @param parentTitle the parent title
15801             * @param status the status
15802             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15803             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
15804             * @throws SystemException if a system exception occurred
15805             */
15806            @Override
15807            public WikiPage fetchByN_H_P_S_First(long nodeId, boolean head,
15808                    String parentTitle, int status, OrderByComparator orderByComparator)
15809                    throws SystemException {
15810                    List<WikiPage> list = findByN_H_P_S(nodeId, head, parentTitle, status,
15811                                    0, 1, orderByComparator);
15812    
15813                    if (!list.isEmpty()) {
15814                            return list.get(0);
15815                    }
15816    
15817                    return null;
15818            }
15819    
15820            /**
15821             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15822             *
15823             * @param nodeId the node ID
15824             * @param head the head
15825             * @param parentTitle the parent title
15826             * @param status the status
15827             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15828             * @return the last matching wiki page
15829             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
15830             * @throws SystemException if a system exception occurred
15831             */
15832            @Override
15833            public WikiPage findByN_H_P_S_Last(long nodeId, boolean head,
15834                    String parentTitle, int status, OrderByComparator orderByComparator)
15835                    throws NoSuchPageException, SystemException {
15836                    WikiPage wikiPage = fetchByN_H_P_S_Last(nodeId, head, parentTitle,
15837                                    status, orderByComparator);
15838    
15839                    if (wikiPage != null) {
15840                            return wikiPage;
15841                    }
15842    
15843                    StringBundler msg = new StringBundler(10);
15844    
15845                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15846    
15847                    msg.append("nodeId=");
15848                    msg.append(nodeId);
15849    
15850                    msg.append(", head=");
15851                    msg.append(head);
15852    
15853                    msg.append(", parentTitle=");
15854                    msg.append(parentTitle);
15855    
15856                    msg.append(", status=");
15857                    msg.append(status);
15858    
15859                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15860    
15861                    throw new NoSuchPageException(msg.toString());
15862            }
15863    
15864            /**
15865             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15866             *
15867             * @param nodeId the node ID
15868             * @param head the head
15869             * @param parentTitle the parent title
15870             * @param status the status
15871             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15872             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
15873             * @throws SystemException if a system exception occurred
15874             */
15875            @Override
15876            public WikiPage fetchByN_H_P_S_Last(long nodeId, boolean head,
15877                    String parentTitle, int status, OrderByComparator orderByComparator)
15878                    throws SystemException {
15879                    int count = countByN_H_P_S(nodeId, head, parentTitle, status);
15880    
15881                    if (count == 0) {
15882                            return null;
15883                    }
15884    
15885                    List<WikiPage> list = findByN_H_P_S(nodeId, head, parentTitle, status,
15886                                    count - 1, count, orderByComparator);
15887    
15888                    if (!list.isEmpty()) {
15889                            return list.get(0);
15890                    }
15891    
15892                    return null;
15893            }
15894    
15895            /**
15896             * 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;.
15897             *
15898             * @param pageId the primary key of the current wiki page
15899             * @param nodeId the node ID
15900             * @param head the head
15901             * @param parentTitle the parent title
15902             * @param status the status
15903             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15904             * @return the previous, current, and next wiki page
15905             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
15906             * @throws SystemException if a system exception occurred
15907             */
15908            @Override
15909            public WikiPage[] findByN_H_P_S_PrevAndNext(long pageId, long nodeId,
15910                    boolean head, String parentTitle, int status,
15911                    OrderByComparator orderByComparator)
15912                    throws NoSuchPageException, SystemException {
15913                    WikiPage wikiPage = findByPrimaryKey(pageId);
15914    
15915                    Session session = null;
15916    
15917                    try {
15918                            session = openSession();
15919    
15920                            WikiPage[] array = new WikiPageImpl[3];
15921    
15922                            array[0] = getByN_H_P_S_PrevAndNext(session, wikiPage, nodeId,
15923                                            head, parentTitle, status, orderByComparator, true);
15924    
15925                            array[1] = wikiPage;
15926    
15927                            array[2] = getByN_H_P_S_PrevAndNext(session, wikiPage, nodeId,
15928                                            head, parentTitle, status, orderByComparator, false);
15929    
15930                            return array;
15931                    }
15932                    catch (Exception e) {
15933                            throw processException(e);
15934                    }
15935                    finally {
15936                            closeSession(session);
15937                    }
15938            }
15939    
15940            protected WikiPage getByN_H_P_S_PrevAndNext(Session session,
15941                    WikiPage wikiPage, long nodeId, boolean head, String parentTitle,
15942                    int status, OrderByComparator orderByComparator, boolean previous) {
15943                    StringBundler query = null;
15944    
15945                    if (orderByComparator != null) {
15946                            query = new StringBundler(6 +
15947                                            (orderByComparator.getOrderByFields().length * 6));
15948                    }
15949                    else {
15950                            query = new StringBundler(3);
15951                    }
15952    
15953                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
15954    
15955                    query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
15956    
15957                    query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
15958    
15959                    boolean bindParentTitle = false;
15960    
15961                    if (parentTitle == null) {
15962                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
15963                    }
15964                    else if (parentTitle.equals(StringPool.BLANK)) {
15965                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
15966                    }
15967                    else {
15968                            bindParentTitle = true;
15969    
15970                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
15971                    }
15972    
15973                    query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
15974    
15975                    if (orderByComparator != null) {
15976                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15977    
15978                            if (orderByConditionFields.length > 0) {
15979                                    query.append(WHERE_AND);
15980                            }
15981    
15982                            for (int i = 0; i < orderByConditionFields.length; i++) {
15983                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15984                                    query.append(orderByConditionFields[i]);
15985    
15986                                    if ((i + 1) < orderByConditionFields.length) {
15987                                            if (orderByComparator.isAscending() ^ previous) {
15988                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15989                                            }
15990                                            else {
15991                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15992                                            }
15993                                    }
15994                                    else {
15995                                            if (orderByComparator.isAscending() ^ previous) {
15996                                                    query.append(WHERE_GREATER_THAN);
15997                                            }
15998                                            else {
15999                                                    query.append(WHERE_LESSER_THAN);
16000                                            }
16001                                    }
16002                            }
16003    
16004                            query.append(ORDER_BY_CLAUSE);
16005    
16006                            String[] orderByFields = orderByComparator.getOrderByFields();
16007    
16008                            for (int i = 0; i < orderByFields.length; i++) {
16009                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16010                                    query.append(orderByFields[i]);
16011    
16012                                    if ((i + 1) < orderByFields.length) {
16013                                            if (orderByComparator.isAscending() ^ previous) {
16014                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16015                                            }
16016                                            else {
16017                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16018                                            }
16019                                    }
16020                                    else {
16021                                            if (orderByComparator.isAscending() ^ previous) {
16022                                                    query.append(ORDER_BY_ASC);
16023                                            }
16024                                            else {
16025                                                    query.append(ORDER_BY_DESC);
16026                                            }
16027                                    }
16028                            }
16029                    }
16030                    else {
16031                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16032                    }
16033    
16034                    String sql = query.toString();
16035    
16036                    Query q = session.createQuery(sql);
16037    
16038                    q.setFirstResult(0);
16039                    q.setMaxResults(2);
16040    
16041                    QueryPos qPos = QueryPos.getInstance(q);
16042    
16043                    qPos.add(nodeId);
16044    
16045                    qPos.add(head);
16046    
16047                    if (bindParentTitle) {
16048                            qPos.add(parentTitle.toLowerCase());
16049                    }
16050    
16051                    qPos.add(status);
16052    
16053                    if (orderByComparator != null) {
16054                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
16055    
16056                            for (Object value : values) {
16057                                    qPos.add(value);
16058                            }
16059                    }
16060    
16061                    List<WikiPage> list = q.list();
16062    
16063                    if (list.size() == 2) {
16064                            return list.get(1);
16065                    }
16066                    else {
16067                            return null;
16068                    }
16069            }
16070    
16071            /**
16072             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63; from the database.
16073             *
16074             * @param nodeId the node ID
16075             * @param head the head
16076             * @param parentTitle the parent title
16077             * @param status the status
16078             * @throws SystemException if a system exception occurred
16079             */
16080            @Override
16081            public void removeByN_H_P_S(long nodeId, boolean head, String parentTitle,
16082                    int status) throws SystemException {
16083                    for (WikiPage wikiPage : findByN_H_P_S(nodeId, head, parentTitle,
16084                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16085                            remove(wikiPage);
16086                    }
16087            }
16088    
16089            /**
16090             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16091             *
16092             * @param nodeId the node ID
16093             * @param head the head
16094             * @param parentTitle the parent title
16095             * @param status the status
16096             * @return the number of matching wiki pages
16097             * @throws SystemException if a system exception occurred
16098             */
16099            @Override
16100            public int countByN_H_P_S(long nodeId, boolean head, String parentTitle,
16101                    int status) throws SystemException {
16102                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_P_S;
16103    
16104                    Object[] finderArgs = new Object[] { nodeId, head, parentTitle, status };
16105    
16106                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
16107                                    this);
16108    
16109                    if (count == null) {
16110                            StringBundler query = new StringBundler(5);
16111    
16112                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
16113    
16114                            query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
16115    
16116                            query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
16117    
16118                            boolean bindParentTitle = false;
16119    
16120                            if (parentTitle == null) {
16121                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
16122                            }
16123                            else if (parentTitle.equals(StringPool.BLANK)) {
16124                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
16125                            }
16126                            else {
16127                                    bindParentTitle = true;
16128    
16129                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
16130                            }
16131    
16132                            query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
16133    
16134                            String sql = query.toString();
16135    
16136                            Session session = null;
16137    
16138                            try {
16139                                    session = openSession();
16140    
16141                                    Query q = session.createQuery(sql);
16142    
16143                                    QueryPos qPos = QueryPos.getInstance(q);
16144    
16145                                    qPos.add(nodeId);
16146    
16147                                    qPos.add(head);
16148    
16149                                    if (bindParentTitle) {
16150                                            qPos.add(parentTitle.toLowerCase());
16151                                    }
16152    
16153                                    qPos.add(status);
16154    
16155                                    count = (Long)q.uniqueResult();
16156    
16157                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
16158                            }
16159                            catch (Exception e) {
16160                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16161    
16162                                    throw processException(e);
16163                            }
16164                            finally {
16165                                    closeSession(session);
16166                            }
16167                    }
16168    
16169                    return count.intValue();
16170            }
16171    
16172            private static final String _FINDER_COLUMN_N_H_P_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
16173            private static final String _FINDER_COLUMN_N_H_P_S_HEAD_2 = "wikiPage.head = ? AND ";
16174            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL AND ";
16175            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ? AND ";
16176            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '') AND ";
16177            private static final String _FINDER_COLUMN_N_H_P_S_STATUS_2 = "wikiPage.status = ?";
16178            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_P_S =
16179                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16180                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
16181                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H_P_S",
16182                            new String[] {
16183                                    Long.class.getName(), Long.class.getName(),
16184                                    Boolean.class.getName(), String.class.getName(),
16185                                    Integer.class.getName(),
16186                                    
16187                            Integer.class.getName(), Integer.class.getName(),
16188                                    OrderByComparator.class.getName()
16189                            });
16190            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S =
16191                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16192                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
16193                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H_P_S",
16194                            new String[] {
16195                                    Long.class.getName(), Long.class.getName(),
16196                                    Boolean.class.getName(), String.class.getName(),
16197                                    Integer.class.getName()
16198                            },
16199                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
16200                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
16201                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
16202                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
16203                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
16204                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
16205                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
16206            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16207                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16208                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H_P_S",
16209                            new String[] {
16210                                    Long.class.getName(), Long.class.getName(),
16211                                    Boolean.class.getName(), String.class.getName(),
16212                                    Integer.class.getName()
16213                            });
16214    
16215            /**
16216             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16217             *
16218             * @param groupId the group ID
16219             * @param nodeId the node ID
16220             * @param head the head
16221             * @param parentTitle the parent title
16222             * @param status the status
16223             * @return the matching wiki pages
16224             * @throws SystemException if a system exception occurred
16225             */
16226            @Override
16227            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
16228                    boolean head, String parentTitle, int status) throws SystemException {
16229                    return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
16230                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16231            }
16232    
16233            /**
16234             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16235             *
16236             * <p>
16237             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16238             * </p>
16239             *
16240             * @param groupId the group ID
16241             * @param nodeId the node ID
16242             * @param head the head
16243             * @param parentTitle the parent title
16244             * @param status the status
16245             * @param start the lower bound of the range of wiki pages
16246             * @param end the upper bound of the range of wiki pages (not inclusive)
16247             * @return the range of matching wiki pages
16248             * @throws SystemException if a system exception occurred
16249             */
16250            @Override
16251            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
16252                    boolean head, String parentTitle, int status, int start, int end)
16253                    throws SystemException {
16254                    return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
16255                            start, end, null);
16256            }
16257    
16258            /**
16259             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16260             *
16261             * <p>
16262             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16263             * </p>
16264             *
16265             * @param groupId the group ID
16266             * @param nodeId the node ID
16267             * @param head the head
16268             * @param parentTitle the parent title
16269             * @param status the status
16270             * @param start the lower bound of the range of wiki pages
16271             * @param end the upper bound of the range of wiki pages (not inclusive)
16272             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16273             * @return the ordered range of matching wiki pages
16274             * @throws SystemException if a system exception occurred
16275             */
16276            @Override
16277            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
16278                    boolean head, String parentTitle, int status, int start, int end,
16279                    OrderByComparator orderByComparator) throws SystemException {
16280                    boolean pagination = true;
16281                    FinderPath finderPath = null;
16282                    Object[] finderArgs = null;
16283    
16284                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16285                                    (orderByComparator == null)) {
16286                            pagination = false;
16287                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S;
16288                            finderArgs = new Object[] { groupId, nodeId, head, parentTitle, status };
16289                    }
16290                    else {
16291                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_P_S;
16292                            finderArgs = new Object[] {
16293                                            groupId, nodeId, head, parentTitle, status,
16294                                            
16295                                            start, end, orderByComparator
16296                                    };
16297                    }
16298    
16299                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
16300                                    finderArgs, this);
16301    
16302                    if ((list != null) && !list.isEmpty()) {
16303                            for (WikiPage wikiPage : list) {
16304                                    if ((groupId != wikiPage.getGroupId()) ||
16305                                                    (nodeId != wikiPage.getNodeId()) ||
16306                                                    (head != wikiPage.getHead()) ||
16307                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle()) ||
16308                                                    (status != wikiPage.getStatus())) {
16309                                            list = null;
16310    
16311                                            break;
16312                                    }
16313                            }
16314                    }
16315    
16316                    if (list == null) {
16317                            StringBundler query = null;
16318    
16319                            if (orderByComparator != null) {
16320                                    query = new StringBundler(7 +
16321                                                    (orderByComparator.getOrderByFields().length * 3));
16322                            }
16323                            else {
16324                                    query = new StringBundler(7);
16325                            }
16326    
16327                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
16328    
16329                            query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
16330    
16331                            query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
16332    
16333                            query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
16334    
16335                            boolean bindParentTitle = false;
16336    
16337                            if (parentTitle == null) {
16338                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
16339                            }
16340                            else if (parentTitle.equals(StringPool.BLANK)) {
16341                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
16342                            }
16343                            else {
16344                                    bindParentTitle = true;
16345    
16346                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
16347                            }
16348    
16349                            query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
16350    
16351                            if (orderByComparator != null) {
16352                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16353                                            orderByComparator);
16354                            }
16355                            else
16356                             if (pagination) {
16357                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16358                            }
16359    
16360                            String sql = query.toString();
16361    
16362                            Session session = null;
16363    
16364                            try {
16365                                    session = openSession();
16366    
16367                                    Query q = session.createQuery(sql);
16368    
16369                                    QueryPos qPos = QueryPos.getInstance(q);
16370    
16371                                    qPos.add(groupId);
16372    
16373                                    qPos.add(nodeId);
16374    
16375                                    qPos.add(head);
16376    
16377                                    if (bindParentTitle) {
16378                                            qPos.add(parentTitle.toLowerCase());
16379                                    }
16380    
16381                                    qPos.add(status);
16382    
16383                                    if (!pagination) {
16384                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
16385                                                            start, end, false);
16386    
16387                                            Collections.sort(list);
16388    
16389                                            list = new UnmodifiableList<WikiPage>(list);
16390                                    }
16391                                    else {
16392                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
16393                                                            start, end);
16394                                    }
16395    
16396                                    cacheResult(list);
16397    
16398                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
16399                            }
16400                            catch (Exception e) {
16401                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16402    
16403                                    throw processException(e);
16404                            }
16405                            finally {
16406                                    closeSession(session);
16407                            }
16408                    }
16409    
16410                    return list;
16411            }
16412    
16413            /**
16414             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16415             *
16416             * @param groupId the group ID
16417             * @param nodeId the node ID
16418             * @param head the head
16419             * @param parentTitle the parent title
16420             * @param status the status
16421             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16422             * @return the first matching wiki page
16423             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
16424             * @throws SystemException if a system exception occurred
16425             */
16426            @Override
16427            public WikiPage findByG_N_H_P_S_First(long groupId, long nodeId,
16428                    boolean head, String parentTitle, int status,
16429                    OrderByComparator orderByComparator)
16430                    throws NoSuchPageException, SystemException {
16431                    WikiPage wikiPage = fetchByG_N_H_P_S_First(groupId, nodeId, head,
16432                                    parentTitle, status, orderByComparator);
16433    
16434                    if (wikiPage != null) {
16435                            return wikiPage;
16436                    }
16437    
16438                    StringBundler msg = new StringBundler(12);
16439    
16440                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16441    
16442                    msg.append("groupId=");
16443                    msg.append(groupId);
16444    
16445                    msg.append(", nodeId=");
16446                    msg.append(nodeId);
16447    
16448                    msg.append(", head=");
16449                    msg.append(head);
16450    
16451                    msg.append(", parentTitle=");
16452                    msg.append(parentTitle);
16453    
16454                    msg.append(", status=");
16455                    msg.append(status);
16456    
16457                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16458    
16459                    throw new NoSuchPageException(msg.toString());
16460            }
16461    
16462            /**
16463             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16464             *
16465             * @param groupId the group ID
16466             * @param nodeId the node ID
16467             * @param head the head
16468             * @param parentTitle the parent title
16469             * @param status the status
16470             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16471             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
16472             * @throws SystemException if a system exception occurred
16473             */
16474            @Override
16475            public WikiPage fetchByG_N_H_P_S_First(long groupId, long nodeId,
16476                    boolean head, String parentTitle, int status,
16477                    OrderByComparator orderByComparator) throws SystemException {
16478                    List<WikiPage> list = findByG_N_H_P_S(groupId, nodeId, head,
16479                                    parentTitle, status, 0, 1, orderByComparator);
16480    
16481                    if (!list.isEmpty()) {
16482                            return list.get(0);
16483                    }
16484    
16485                    return null;
16486            }
16487    
16488            /**
16489             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16490             *
16491             * @param groupId the group ID
16492             * @param nodeId the node ID
16493             * @param head the head
16494             * @param parentTitle the parent title
16495             * @param status the status
16496             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16497             * @return the last matching wiki page
16498             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
16499             * @throws SystemException if a system exception occurred
16500             */
16501            @Override
16502            public WikiPage findByG_N_H_P_S_Last(long groupId, long nodeId,
16503                    boolean head, String parentTitle, int status,
16504                    OrderByComparator orderByComparator)
16505                    throws NoSuchPageException, SystemException {
16506                    WikiPage wikiPage = fetchByG_N_H_P_S_Last(groupId, nodeId, head,
16507                                    parentTitle, status, orderByComparator);
16508    
16509                    if (wikiPage != null) {
16510                            return wikiPage;
16511                    }
16512    
16513                    StringBundler msg = new StringBundler(12);
16514    
16515                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16516    
16517                    msg.append("groupId=");
16518                    msg.append(groupId);
16519    
16520                    msg.append(", nodeId=");
16521                    msg.append(nodeId);
16522    
16523                    msg.append(", head=");
16524                    msg.append(head);
16525    
16526                    msg.append(", parentTitle=");
16527                    msg.append(parentTitle);
16528    
16529                    msg.append(", status=");
16530                    msg.append(status);
16531    
16532                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16533    
16534                    throw new NoSuchPageException(msg.toString());
16535            }
16536    
16537            /**
16538             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16539             *
16540             * @param groupId the group ID
16541             * @param nodeId the node ID
16542             * @param head the head
16543             * @param parentTitle the parent title
16544             * @param status the status
16545             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16546             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
16547             * @throws SystemException if a system exception occurred
16548             */
16549            @Override
16550            public WikiPage fetchByG_N_H_P_S_Last(long groupId, long nodeId,
16551                    boolean head, String parentTitle, int status,
16552                    OrderByComparator orderByComparator) throws SystemException {
16553                    int count = countByG_N_H_P_S(groupId, nodeId, head, parentTitle, status);
16554    
16555                    if (count == 0) {
16556                            return null;
16557                    }
16558    
16559                    List<WikiPage> list = findByG_N_H_P_S(groupId, nodeId, head,
16560                                    parentTitle, status, count - 1, count, orderByComparator);
16561    
16562                    if (!list.isEmpty()) {
16563                            return list.get(0);
16564                    }
16565    
16566                    return null;
16567            }
16568    
16569            /**
16570             * 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;.
16571             *
16572             * @param pageId the primary key of the current wiki page
16573             * @param groupId the group ID
16574             * @param nodeId the node ID
16575             * @param head the head
16576             * @param parentTitle the parent title
16577             * @param status the status
16578             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16579             * @return the previous, current, and next wiki page
16580             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
16581             * @throws SystemException if a system exception occurred
16582             */
16583            @Override
16584            public WikiPage[] findByG_N_H_P_S_PrevAndNext(long pageId, long groupId,
16585                    long nodeId, boolean head, String parentTitle, int status,
16586                    OrderByComparator orderByComparator)
16587                    throws NoSuchPageException, SystemException {
16588                    WikiPage wikiPage = findByPrimaryKey(pageId);
16589    
16590                    Session session = null;
16591    
16592                    try {
16593                            session = openSession();
16594    
16595                            WikiPage[] array = new WikiPageImpl[3];
16596    
16597                            array[0] = getByG_N_H_P_S_PrevAndNext(session, wikiPage, groupId,
16598                                            nodeId, head, parentTitle, status, orderByComparator, true);
16599    
16600                            array[1] = wikiPage;
16601    
16602                            array[2] = getByG_N_H_P_S_PrevAndNext(session, wikiPage, groupId,
16603                                            nodeId, head, parentTitle, status, orderByComparator, false);
16604    
16605                            return array;
16606                    }
16607                    catch (Exception e) {
16608                            throw processException(e);
16609                    }
16610                    finally {
16611                            closeSession(session);
16612                    }
16613            }
16614    
16615            protected WikiPage getByG_N_H_P_S_PrevAndNext(Session session,
16616                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
16617                    String parentTitle, int status, OrderByComparator orderByComparator,
16618                    boolean previous) {
16619                    StringBundler query = null;
16620    
16621                    if (orderByComparator != null) {
16622                            query = new StringBundler(6 +
16623                                            (orderByComparator.getOrderByFields().length * 6));
16624                    }
16625                    else {
16626                            query = new StringBundler(3);
16627                    }
16628    
16629                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
16630    
16631                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
16632    
16633                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
16634    
16635                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
16636    
16637                    boolean bindParentTitle = false;
16638    
16639                    if (parentTitle == null) {
16640                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
16641                    }
16642                    else if (parentTitle.equals(StringPool.BLANK)) {
16643                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
16644                    }
16645                    else {
16646                            bindParentTitle = true;
16647    
16648                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
16649                    }
16650    
16651                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
16652    
16653                    if (orderByComparator != null) {
16654                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16655    
16656                            if (orderByConditionFields.length > 0) {
16657                                    query.append(WHERE_AND);
16658                            }
16659    
16660                            for (int i = 0; i < orderByConditionFields.length; i++) {
16661                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16662                                    query.append(orderByConditionFields[i]);
16663    
16664                                    if ((i + 1) < orderByConditionFields.length) {
16665                                            if (orderByComparator.isAscending() ^ previous) {
16666                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16667                                            }
16668                                            else {
16669                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16670                                            }
16671                                    }
16672                                    else {
16673                                            if (orderByComparator.isAscending() ^ previous) {
16674                                                    query.append(WHERE_GREATER_THAN);
16675                                            }
16676                                            else {
16677                                                    query.append(WHERE_LESSER_THAN);
16678                                            }
16679                                    }
16680                            }
16681    
16682                            query.append(ORDER_BY_CLAUSE);
16683    
16684                            String[] orderByFields = orderByComparator.getOrderByFields();
16685    
16686                            for (int i = 0; i < orderByFields.length; i++) {
16687                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16688                                    query.append(orderByFields[i]);
16689    
16690                                    if ((i + 1) < orderByFields.length) {
16691                                            if (orderByComparator.isAscending() ^ previous) {
16692                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16693                                            }
16694                                            else {
16695                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16696                                            }
16697                                    }
16698                                    else {
16699                                            if (orderByComparator.isAscending() ^ previous) {
16700                                                    query.append(ORDER_BY_ASC);
16701                                            }
16702                                            else {
16703                                                    query.append(ORDER_BY_DESC);
16704                                            }
16705                                    }
16706                            }
16707                    }
16708                    else {
16709                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16710                    }
16711    
16712                    String sql = query.toString();
16713    
16714                    Query q = session.createQuery(sql);
16715    
16716                    q.setFirstResult(0);
16717                    q.setMaxResults(2);
16718    
16719                    QueryPos qPos = QueryPos.getInstance(q);
16720    
16721                    qPos.add(groupId);
16722    
16723                    qPos.add(nodeId);
16724    
16725                    qPos.add(head);
16726    
16727                    if (bindParentTitle) {
16728                            qPos.add(parentTitle.toLowerCase());
16729                    }
16730    
16731                    qPos.add(status);
16732    
16733                    if (orderByComparator != null) {
16734                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
16735    
16736                            for (Object value : values) {
16737                                    qPos.add(value);
16738                            }
16739                    }
16740    
16741                    List<WikiPage> list = q.list();
16742    
16743                    if (list.size() == 2) {
16744                            return list.get(1);
16745                    }
16746                    else {
16747                            return null;
16748                    }
16749            }
16750    
16751            /**
16752             * 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;.
16753             *
16754             * @param groupId the group ID
16755             * @param nodeId the node ID
16756             * @param head the head
16757             * @param parentTitle the parent title
16758             * @param status the status
16759             * @return the matching wiki pages that the user has permission to view
16760             * @throws SystemException if a system exception occurred
16761             */
16762            @Override
16763            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
16764                    boolean head, String parentTitle, int status) throws SystemException {
16765                    return filterFindByG_N_H_P_S(groupId, nodeId, head, parentTitle,
16766                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16767            }
16768    
16769            /**
16770             * 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;.
16771             *
16772             * <p>
16773             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16774             * </p>
16775             *
16776             * @param groupId the group ID
16777             * @param nodeId the node ID
16778             * @param head the head
16779             * @param parentTitle the parent title
16780             * @param status the status
16781             * @param start the lower bound of the range of wiki pages
16782             * @param end the upper bound of the range of wiki pages (not inclusive)
16783             * @return the range of matching wiki pages that the user has permission to view
16784             * @throws SystemException if a system exception occurred
16785             */
16786            @Override
16787            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
16788                    boolean head, String parentTitle, int status, int start, int end)
16789                    throws SystemException {
16790                    return filterFindByG_N_H_P_S(groupId, nodeId, head, parentTitle,
16791                            status, start, end, null);
16792            }
16793    
16794            /**
16795             * 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;.
16796             *
16797             * <p>
16798             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16799             * </p>
16800             *
16801             * @param groupId the group ID
16802             * @param nodeId the node ID
16803             * @param head the head
16804             * @param parentTitle the parent title
16805             * @param status the status
16806             * @param start the lower bound of the range of wiki pages
16807             * @param end the upper bound of the range of wiki pages (not inclusive)
16808             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16809             * @return the ordered range of matching wiki pages that the user has permission to view
16810             * @throws SystemException if a system exception occurred
16811             */
16812            @Override
16813            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
16814                    boolean head, String parentTitle, int status, int start, int end,
16815                    OrderByComparator orderByComparator) throws SystemException {
16816                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16817                            return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
16818                                    start, end, orderByComparator);
16819                    }
16820    
16821                    StringBundler query = null;
16822    
16823                    if (orderByComparator != null) {
16824                            query = new StringBundler(7 +
16825                                            (orderByComparator.getOrderByFields().length * 3));
16826                    }
16827                    else {
16828                            query = new StringBundler(7);
16829                    }
16830    
16831                    if (getDB().isSupportsInlineDistinct()) {
16832                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
16833                    }
16834                    else {
16835                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
16836                    }
16837    
16838                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
16839    
16840                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
16841    
16842                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
16843    
16844                    boolean bindParentTitle = false;
16845    
16846                    if (parentTitle == null) {
16847                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
16848                    }
16849                    else if (parentTitle.equals(StringPool.BLANK)) {
16850                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
16851                    }
16852                    else {
16853                            bindParentTitle = true;
16854    
16855                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
16856                    }
16857    
16858                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
16859    
16860                    if (!getDB().isSupportsInlineDistinct()) {
16861                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
16862                    }
16863    
16864                    if (orderByComparator != null) {
16865                            if (getDB().isSupportsInlineDistinct()) {
16866                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16867                                            orderByComparator, true);
16868                            }
16869                            else {
16870                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16871                                            orderByComparator, true);
16872                            }
16873                    }
16874                    else {
16875                            if (getDB().isSupportsInlineDistinct()) {
16876                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16877                            }
16878                            else {
16879                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
16880                            }
16881                    }
16882    
16883                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16884                                    WikiPage.class.getName(),
16885                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16886    
16887                    Session session = null;
16888    
16889                    try {
16890                            session = openSession();
16891    
16892                            SQLQuery q = session.createSQLQuery(sql);
16893    
16894                            if (getDB().isSupportsInlineDistinct()) {
16895                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
16896                            }
16897                            else {
16898                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
16899                            }
16900    
16901                            QueryPos qPos = QueryPos.getInstance(q);
16902    
16903                            qPos.add(groupId);
16904    
16905                            qPos.add(nodeId);
16906    
16907                            qPos.add(head);
16908    
16909                            if (bindParentTitle) {
16910                                    qPos.add(parentTitle.toLowerCase());
16911                            }
16912    
16913                            qPos.add(status);
16914    
16915                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
16916                    }
16917                    catch (Exception e) {
16918                            throw processException(e);
16919                    }
16920                    finally {
16921                            closeSession(session);
16922                    }
16923            }
16924    
16925            /**
16926             * 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;.
16927             *
16928             * @param pageId the primary key of the current wiki page
16929             * @param groupId the group ID
16930             * @param nodeId the node ID
16931             * @param head the head
16932             * @param parentTitle the parent title
16933             * @param status the status
16934             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16935             * @return the previous, current, and next wiki page
16936             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
16937             * @throws SystemException if a system exception occurred
16938             */
16939            @Override
16940            public WikiPage[] filterFindByG_N_H_P_S_PrevAndNext(long pageId,
16941                    long groupId, long nodeId, boolean head, String parentTitle,
16942                    int status, OrderByComparator orderByComparator)
16943                    throws NoSuchPageException, SystemException {
16944                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16945                            return findByG_N_H_P_S_PrevAndNext(pageId, groupId, nodeId, head,
16946                                    parentTitle, status, orderByComparator);
16947                    }
16948    
16949                    WikiPage wikiPage = findByPrimaryKey(pageId);
16950    
16951                    Session session = null;
16952    
16953                    try {
16954                            session = openSession();
16955    
16956                            WikiPage[] array = new WikiPageImpl[3];
16957    
16958                            array[0] = filterGetByG_N_H_P_S_PrevAndNext(session, wikiPage,
16959                                            groupId, nodeId, head, parentTitle, status,
16960                                            orderByComparator, true);
16961    
16962                            array[1] = wikiPage;
16963    
16964                            array[2] = filterGetByG_N_H_P_S_PrevAndNext(session, wikiPage,
16965                                            groupId, nodeId, head, parentTitle, status,
16966                                            orderByComparator, false);
16967    
16968                            return array;
16969                    }
16970                    catch (Exception e) {
16971                            throw processException(e);
16972                    }
16973                    finally {
16974                            closeSession(session);
16975                    }
16976            }
16977    
16978            protected WikiPage filterGetByG_N_H_P_S_PrevAndNext(Session session,
16979                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
16980                    String parentTitle, int status, OrderByComparator orderByComparator,
16981                    boolean previous) {
16982                    StringBundler query = null;
16983    
16984                    if (orderByComparator != null) {
16985                            query = new StringBundler(6 +
16986                                            (orderByComparator.getOrderByFields().length * 6));
16987                    }
16988                    else {
16989                            query = new StringBundler(3);
16990                    }
16991    
16992                    if (getDB().isSupportsInlineDistinct()) {
16993                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
16994                    }
16995                    else {
16996                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
16997                    }
16998    
16999                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
17000    
17001                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
17002    
17003                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
17004    
17005                    boolean bindParentTitle = false;
17006    
17007                    if (parentTitle == null) {
17008                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
17009                    }
17010                    else if (parentTitle.equals(StringPool.BLANK)) {
17011                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
17012                    }
17013                    else {
17014                            bindParentTitle = true;
17015    
17016                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
17017                    }
17018    
17019                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
17020    
17021                    if (!getDB().isSupportsInlineDistinct()) {
17022                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
17023                    }
17024    
17025                    if (orderByComparator != null) {
17026                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17027    
17028                            if (orderByConditionFields.length > 0) {
17029                                    query.append(WHERE_AND);
17030                            }
17031    
17032                            for (int i = 0; i < orderByConditionFields.length; i++) {
17033                                    if (getDB().isSupportsInlineDistinct()) {
17034                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17035                                    }
17036                                    else {
17037                                            query.append(_ORDER_BY_ENTITY_TABLE);
17038                                    }
17039    
17040                                    query.append(orderByConditionFields[i]);
17041    
17042                                    if ((i + 1) < orderByConditionFields.length) {
17043                                            if (orderByComparator.isAscending() ^ previous) {
17044                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17045                                            }
17046                                            else {
17047                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17048                                            }
17049                                    }
17050                                    else {
17051                                            if (orderByComparator.isAscending() ^ previous) {
17052                                                    query.append(WHERE_GREATER_THAN);
17053                                            }
17054                                            else {
17055                                                    query.append(WHERE_LESSER_THAN);
17056                                            }
17057                                    }
17058                            }
17059    
17060                            query.append(ORDER_BY_CLAUSE);
17061    
17062                            String[] orderByFields = orderByComparator.getOrderByFields();
17063    
17064                            for (int i = 0; i < orderByFields.length; i++) {
17065                                    if (getDB().isSupportsInlineDistinct()) {
17066                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17067                                    }
17068                                    else {
17069                                            query.append(_ORDER_BY_ENTITY_TABLE);
17070                                    }
17071    
17072                                    query.append(orderByFields[i]);
17073    
17074                                    if ((i + 1) < orderByFields.length) {
17075                                            if (orderByComparator.isAscending() ^ previous) {
17076                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17077                                            }
17078                                            else {
17079                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17080                                            }
17081                                    }
17082                                    else {
17083                                            if (orderByComparator.isAscending() ^ previous) {
17084                                                    query.append(ORDER_BY_ASC);
17085                                            }
17086                                            else {
17087                                                    query.append(ORDER_BY_DESC);
17088                                            }
17089                                    }
17090                            }
17091                    }
17092                    else {
17093                            if (getDB().isSupportsInlineDistinct()) {
17094                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
17095                            }
17096                            else {
17097                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
17098                            }
17099                    }
17100    
17101                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17102                                    WikiPage.class.getName(),
17103                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17104    
17105                    SQLQuery q = session.createSQLQuery(sql);
17106    
17107                    q.setFirstResult(0);
17108                    q.setMaxResults(2);
17109    
17110                    if (getDB().isSupportsInlineDistinct()) {
17111                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
17112                    }
17113                    else {
17114                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
17115                    }
17116    
17117                    QueryPos qPos = QueryPos.getInstance(q);
17118    
17119                    qPos.add(groupId);
17120    
17121                    qPos.add(nodeId);
17122    
17123                    qPos.add(head);
17124    
17125                    if (bindParentTitle) {
17126                            qPos.add(parentTitle.toLowerCase());
17127                    }
17128    
17129                    qPos.add(status);
17130    
17131                    if (orderByComparator != null) {
17132                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
17133    
17134                            for (Object value : values) {
17135                                    qPos.add(value);
17136                            }
17137                    }
17138    
17139                    List<WikiPage> list = q.list();
17140    
17141                    if (list.size() == 2) {
17142                            return list.get(1);
17143                    }
17144                    else {
17145                            return null;
17146                    }
17147            }
17148    
17149            /**
17150             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63; from the database.
17151             *
17152             * @param groupId the group ID
17153             * @param nodeId the node ID
17154             * @param head the head
17155             * @param parentTitle the parent title
17156             * @param status the status
17157             * @throws SystemException if a system exception occurred
17158             */
17159            @Override
17160            public void removeByG_N_H_P_S(long groupId, long nodeId, boolean head,
17161                    String parentTitle, int status) throws SystemException {
17162                    for (WikiPage wikiPage : findByG_N_H_P_S(groupId, nodeId, head,
17163                                    parentTitle, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17164                            remove(wikiPage);
17165                    }
17166            }
17167    
17168            /**
17169             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17170             *
17171             * @param groupId the group ID
17172             * @param nodeId the node ID
17173             * @param head the head
17174             * @param parentTitle the parent title
17175             * @param status the status
17176             * @return the number of matching wiki pages
17177             * @throws SystemException if a system exception occurred
17178             */
17179            @Override
17180            public int countByG_N_H_P_S(long groupId, long nodeId, boolean head,
17181                    String parentTitle, int status) throws SystemException {
17182                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H_P_S;
17183    
17184                    Object[] finderArgs = new Object[] {
17185                                    groupId, nodeId, head, parentTitle, status
17186                            };
17187    
17188                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
17189                                    this);
17190    
17191                    if (count == null) {
17192                            StringBundler query = new StringBundler(6);
17193    
17194                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
17195    
17196                            query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
17197    
17198                            query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
17199    
17200                            query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
17201    
17202                            boolean bindParentTitle = false;
17203    
17204                            if (parentTitle == null) {
17205                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
17206                            }
17207                            else if (parentTitle.equals(StringPool.BLANK)) {
17208                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
17209                            }
17210                            else {
17211                                    bindParentTitle = true;
17212    
17213                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
17214                            }
17215    
17216                            query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
17217    
17218                            String sql = query.toString();
17219    
17220                            Session session = null;
17221    
17222                            try {
17223                                    session = openSession();
17224    
17225                                    Query q = session.createQuery(sql);
17226    
17227                                    QueryPos qPos = QueryPos.getInstance(q);
17228    
17229                                    qPos.add(groupId);
17230    
17231                                    qPos.add(nodeId);
17232    
17233                                    qPos.add(head);
17234    
17235                                    if (bindParentTitle) {
17236                                            qPos.add(parentTitle.toLowerCase());
17237                                    }
17238    
17239                                    qPos.add(status);
17240    
17241                                    count = (Long)q.uniqueResult();
17242    
17243                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
17244                            }
17245                            catch (Exception e) {
17246                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17247    
17248                                    throw processException(e);
17249                            }
17250                            finally {
17251                                    closeSession(session);
17252                            }
17253                    }
17254    
17255                    return count.intValue();
17256            }
17257    
17258            /**
17259             * 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;.
17260             *
17261             * @param groupId the group ID
17262             * @param nodeId the node ID
17263             * @param head the head
17264             * @param parentTitle the parent title
17265             * @param status the status
17266             * @return the number of matching wiki pages that the user has permission to view
17267             * @throws SystemException if a system exception occurred
17268             */
17269            @Override
17270            public int filterCountByG_N_H_P_S(long groupId, long nodeId, boolean head,
17271                    String parentTitle, int status) throws SystemException {
17272                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17273                            return countByG_N_H_P_S(groupId, nodeId, head, parentTitle, status);
17274                    }
17275    
17276                    StringBundler query = new StringBundler(6);
17277    
17278                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
17279    
17280                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
17281    
17282                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
17283    
17284                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
17285    
17286                    boolean bindParentTitle = false;
17287    
17288                    if (parentTitle == null) {
17289                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
17290                    }
17291                    else if (parentTitle.equals(StringPool.BLANK)) {
17292                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
17293                    }
17294                    else {
17295                            bindParentTitle = true;
17296    
17297                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
17298                    }
17299    
17300                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
17301    
17302                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17303                                    WikiPage.class.getName(),
17304                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17305    
17306                    Session session = null;
17307    
17308                    try {
17309                            session = openSession();
17310    
17311                            SQLQuery q = session.createSQLQuery(sql);
17312    
17313                            q.addScalar(COUNT_COLUMN_NAME,
17314                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17315    
17316                            QueryPos qPos = QueryPos.getInstance(q);
17317    
17318                            qPos.add(groupId);
17319    
17320                            qPos.add(nodeId);
17321    
17322                            qPos.add(head);
17323    
17324                            if (bindParentTitle) {
17325                                    qPos.add(parentTitle.toLowerCase());
17326                            }
17327    
17328                            qPos.add(status);
17329    
17330                            Long count = (Long)q.uniqueResult();
17331    
17332                            return count.intValue();
17333                    }
17334                    catch (Exception e) {
17335                            throw processException(e);
17336                    }
17337                    finally {
17338                            closeSession(session);
17339                    }
17340            }
17341    
17342            private static final String _FINDER_COLUMN_G_N_H_P_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
17343            private static final String _FINDER_COLUMN_G_N_H_P_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
17344            private static final String _FINDER_COLUMN_G_N_H_P_S_HEAD_2 = "wikiPage.head = ? AND ";
17345            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL AND ";
17346            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ? AND ";
17347            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '') AND ";
17348            private static final String _FINDER_COLUMN_G_N_H_P_S_STATUS_2 = "wikiPage.status = ?";
17349    
17350            /**
17351             * Caches the wiki page in the entity cache if it is enabled.
17352             *
17353             * @param wikiPage the wiki page
17354             */
17355            @Override
17356            public void cacheResult(WikiPage wikiPage) {
17357                    EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17358                            WikiPageImpl.class, wikiPage.getPrimaryKey(), wikiPage);
17359    
17360                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
17361                            new Object[] { wikiPage.getUuid(), wikiPage.getGroupId() }, wikiPage);
17362    
17363                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
17364                            new Object[] {
17365                                    wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
17366                                    wikiPage.getVersion()
17367                            }, wikiPage);
17368    
17369                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
17370                            new Object[] {
17371                                    wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion()
17372                            }, wikiPage);
17373    
17374                    wikiPage.resetOriginalValues();
17375            }
17376    
17377            /**
17378             * Caches the wiki pages in the entity cache if it is enabled.
17379             *
17380             * @param wikiPages the wiki pages
17381             */
17382            @Override
17383            public void cacheResult(List<WikiPage> wikiPages) {
17384                    for (WikiPage wikiPage : wikiPages) {
17385                            if (EntityCacheUtil.getResult(
17386                                                    WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17387                                                    WikiPageImpl.class, wikiPage.getPrimaryKey()) == null) {
17388                                    cacheResult(wikiPage);
17389                            }
17390                            else {
17391                                    wikiPage.resetOriginalValues();
17392                            }
17393                    }
17394            }
17395    
17396            /**
17397             * Clears the cache for all wiki pages.
17398             *
17399             * <p>
17400             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
17401             * </p>
17402             */
17403            @Override
17404            public void clearCache() {
17405                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
17406                            CacheRegistryUtil.clear(WikiPageImpl.class.getName());
17407                    }
17408    
17409                    EntityCacheUtil.clearCache(WikiPageImpl.class.getName());
17410    
17411                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
17412                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
17413                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
17414            }
17415    
17416            /**
17417             * Clears the cache for the wiki page.
17418             *
17419             * <p>
17420             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
17421             * </p>
17422             */
17423            @Override
17424            public void clearCache(WikiPage wikiPage) {
17425                    EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17426                            WikiPageImpl.class, wikiPage.getPrimaryKey());
17427    
17428                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
17429                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
17430    
17431                    clearUniqueFindersCache(wikiPage);
17432            }
17433    
17434            @Override
17435            public void clearCache(List<WikiPage> wikiPages) {
17436                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
17437                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
17438    
17439                    for (WikiPage wikiPage : wikiPages) {
17440                            EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17441                                    WikiPageImpl.class, wikiPage.getPrimaryKey());
17442    
17443                            clearUniqueFindersCache(wikiPage);
17444                    }
17445            }
17446    
17447            protected void cacheUniqueFindersCache(WikiPage wikiPage) {
17448                    if (wikiPage.isNew()) {
17449                            Object[] args = new Object[] {
17450                                            wikiPage.getUuid(), wikiPage.getGroupId()
17451                                    };
17452    
17453                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
17454                                    Long.valueOf(1));
17455                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
17456                                    wikiPage);
17457    
17458                            args = new Object[] {
17459                                            wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
17460                                            wikiPage.getVersion()
17461                                    };
17462    
17463                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_N_V, args,
17464                                    Long.valueOf(1));
17465                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V, args, wikiPage);
17466    
17467                            args = new Object[] {
17468                                            wikiPage.getNodeId(), wikiPage.getTitle(),
17469                                            wikiPage.getVersion()
17470                                    };
17471    
17472                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T_V, args,
17473                                    Long.valueOf(1));
17474                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V, args, wikiPage);
17475                    }
17476                    else {
17477                            WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
17478    
17479                            if ((wikiPageModelImpl.getColumnBitmask() &
17480                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
17481                                    Object[] args = new Object[] {
17482                                                    wikiPage.getUuid(), wikiPage.getGroupId()
17483                                            };
17484    
17485                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
17486                                            Long.valueOf(1));
17487                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
17488                                            wikiPage);
17489                            }
17490    
17491                            if ((wikiPageModelImpl.getColumnBitmask() &
17492                                            FINDER_PATH_FETCH_BY_R_N_V.getColumnBitmask()) != 0) {
17493                                    Object[] args = new Object[] {
17494                                                    wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
17495                                                    wikiPage.getVersion()
17496                                            };
17497    
17498                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_N_V, args,
17499                                            Long.valueOf(1));
17500                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V, args,
17501                                            wikiPage);
17502                            }
17503    
17504                            if ((wikiPageModelImpl.getColumnBitmask() &
17505                                            FINDER_PATH_FETCH_BY_N_T_V.getColumnBitmask()) != 0) {
17506                                    Object[] args = new Object[] {
17507                                                    wikiPage.getNodeId(), wikiPage.getTitle(),
17508                                                    wikiPage.getVersion()
17509                                            };
17510    
17511                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T_V, args,
17512                                            Long.valueOf(1));
17513                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V, args,
17514                                            wikiPage);
17515                            }
17516                    }
17517            }
17518    
17519            protected void clearUniqueFindersCache(WikiPage wikiPage) {
17520                    WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
17521    
17522                    Object[] args = new Object[] { wikiPage.getUuid(), wikiPage.getGroupId() };
17523    
17524                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
17525                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
17526    
17527                    if ((wikiPageModelImpl.getColumnBitmask() &
17528                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
17529                            args = new Object[] {
17530                                            wikiPageModelImpl.getOriginalUuid(),
17531                                            wikiPageModelImpl.getOriginalGroupId()
17532                                    };
17533    
17534                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
17535                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
17536                    }
17537    
17538                    args = new Object[] {
17539                                    wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
17540                                    wikiPage.getVersion()
17541                            };
17542    
17543                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_V, args);
17544                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V, args);
17545    
17546                    if ((wikiPageModelImpl.getColumnBitmask() &
17547                                    FINDER_PATH_FETCH_BY_R_N_V.getColumnBitmask()) != 0) {
17548                            args = new Object[] {
17549                                            wikiPageModelImpl.getOriginalResourcePrimKey(),
17550                                            wikiPageModelImpl.getOriginalNodeId(),
17551                                            wikiPageModelImpl.getOriginalVersion()
17552                                    };
17553    
17554                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_V, args);
17555                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V, args);
17556                    }
17557    
17558                    args = new Object[] {
17559                                    wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion()
17560                            };
17561    
17562                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_V, args);
17563                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V, args);
17564    
17565                    if ((wikiPageModelImpl.getColumnBitmask() &
17566                                    FINDER_PATH_FETCH_BY_N_T_V.getColumnBitmask()) != 0) {
17567                            args = new Object[] {
17568                                            wikiPageModelImpl.getOriginalNodeId(),
17569                                            wikiPageModelImpl.getOriginalTitle(),
17570                                            wikiPageModelImpl.getOriginalVersion()
17571                                    };
17572    
17573                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_V, args);
17574                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V, args);
17575                    }
17576            }
17577    
17578            /**
17579             * Creates a new wiki page with the primary key. Does not add the wiki page to the database.
17580             *
17581             * @param pageId the primary key for the new wiki page
17582             * @return the new wiki page
17583             */
17584            @Override
17585            public WikiPage create(long pageId) {
17586                    WikiPage wikiPage = new WikiPageImpl();
17587    
17588                    wikiPage.setNew(true);
17589                    wikiPage.setPrimaryKey(pageId);
17590    
17591                    String uuid = PortalUUIDUtil.generate();
17592    
17593                    wikiPage.setUuid(uuid);
17594    
17595                    return wikiPage;
17596            }
17597    
17598            /**
17599             * Removes the wiki page with the primary key from the database. Also notifies the appropriate model listeners.
17600             *
17601             * @param pageId the primary key of the wiki page
17602             * @return the wiki page that was removed
17603             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
17604             * @throws SystemException if a system exception occurred
17605             */
17606            @Override
17607            public WikiPage remove(long pageId)
17608                    throws NoSuchPageException, SystemException {
17609                    return remove((Serializable)pageId);
17610            }
17611    
17612            /**
17613             * Removes the wiki page with the primary key from the database. Also notifies the appropriate model listeners.
17614             *
17615             * @param primaryKey the primary key of the wiki page
17616             * @return the wiki page that was removed
17617             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
17618             * @throws SystemException if a system exception occurred
17619             */
17620            @Override
17621            public WikiPage remove(Serializable primaryKey)
17622                    throws NoSuchPageException, SystemException {
17623                    Session session = null;
17624    
17625                    try {
17626                            session = openSession();
17627    
17628                            WikiPage wikiPage = (WikiPage)session.get(WikiPageImpl.class,
17629                                            primaryKey);
17630    
17631                            if (wikiPage == null) {
17632                                    if (_log.isWarnEnabled()) {
17633                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
17634                                    }
17635    
17636                                    throw new NoSuchPageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
17637                                            primaryKey);
17638                            }
17639    
17640                            return remove(wikiPage);
17641                    }
17642                    catch (NoSuchPageException nsee) {
17643                            throw nsee;
17644                    }
17645                    catch (Exception e) {
17646                            throw processException(e);
17647                    }
17648                    finally {
17649                            closeSession(session);
17650                    }
17651            }
17652    
17653            @Override
17654            protected WikiPage removeImpl(WikiPage wikiPage) throws SystemException {
17655                    wikiPage = toUnwrappedModel(wikiPage);
17656    
17657                    Session session = null;
17658    
17659                    try {
17660                            session = openSession();
17661    
17662                            if (!session.contains(wikiPage)) {
17663                                    wikiPage = (WikiPage)session.get(WikiPageImpl.class,
17664                                                    wikiPage.getPrimaryKeyObj());
17665                            }
17666    
17667                            if (wikiPage != null) {
17668                                    session.delete(wikiPage);
17669                            }
17670                    }
17671                    catch (Exception e) {
17672                            throw processException(e);
17673                    }
17674                    finally {
17675                            closeSession(session);
17676                    }
17677    
17678                    if (wikiPage != null) {
17679                            clearCache(wikiPage);
17680                    }
17681    
17682                    return wikiPage;
17683            }
17684    
17685            @Override
17686            public WikiPage updateImpl(com.liferay.portlet.wiki.model.WikiPage wikiPage)
17687                    throws SystemException {
17688                    wikiPage = toUnwrappedModel(wikiPage);
17689    
17690                    boolean isNew = wikiPage.isNew();
17691    
17692                    WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
17693    
17694                    if (Validator.isNull(wikiPage.getUuid())) {
17695                            String uuid = PortalUUIDUtil.generate();
17696    
17697                            wikiPage.setUuid(uuid);
17698                    }
17699    
17700                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
17701    
17702                    if (userId > 0) {
17703                            long companyId = wikiPage.getCompanyId();
17704    
17705                            long groupId = wikiPage.getGroupId();
17706    
17707                            long pageId = 0;
17708    
17709                            if (!isNew) {
17710                                    pageId = wikiPage.getPrimaryKey();
17711                            }
17712    
17713                            try {
17714                                    wikiPage.setTitle(SanitizerUtil.sanitize(companyId, groupId,
17715                                                    userId,
17716                                                    com.liferay.portlet.wiki.model.WikiPage.class.getName(),
17717                                                    pageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
17718                                                    wikiPage.getTitle(), null));
17719                            }
17720                            catch (SanitizerException se) {
17721                                    throw new SystemException(se);
17722                            }
17723                    }
17724    
17725                    Session session = null;
17726    
17727                    try {
17728                            session = openSession();
17729    
17730                            if (wikiPage.isNew()) {
17731                                    session.save(wikiPage);
17732    
17733                                    wikiPage.setNew(false);
17734                            }
17735                            else {
17736                                    session.merge(wikiPage);
17737                            }
17738                    }
17739                    catch (Exception e) {
17740                            throw processException(e);
17741                    }
17742                    finally {
17743                            closeSession(session);
17744                    }
17745    
17746                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
17747    
17748                    if (isNew || !WikiPageModelImpl.COLUMN_BITMASK_ENABLED) {
17749                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
17750                    }
17751    
17752                    else {
17753                            if ((wikiPageModelImpl.getColumnBitmask() &
17754                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
17755                                    Object[] args = new Object[] { wikiPageModelImpl.getOriginalUuid() };
17756    
17757                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
17758                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
17759                                            args);
17760    
17761                                    args = new Object[] { wikiPageModelImpl.getUuid() };
17762    
17763                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
17764                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
17765                                            args);
17766                            }
17767    
17768                            if ((wikiPageModelImpl.getColumnBitmask() &
17769                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
17770                                    Object[] args = new Object[] {
17771                                                    wikiPageModelImpl.getOriginalUuid(),
17772                                                    wikiPageModelImpl.getOriginalCompanyId()
17773                                            };
17774    
17775                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
17776                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
17777                                            args);
17778    
17779                                    args = new Object[] {
17780                                                    wikiPageModelImpl.getUuid(),
17781                                                    wikiPageModelImpl.getCompanyId()
17782                                            };
17783    
17784                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
17785                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
17786                                            args);
17787                            }
17788    
17789                            if ((wikiPageModelImpl.getColumnBitmask() &
17790                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID.getColumnBitmask()) != 0) {
17791                                    Object[] args = new Object[] {
17792                                                    wikiPageModelImpl.getOriginalNodeId()
17793                                            };
17794    
17795                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NODEID, args);
17796                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID,
17797                                            args);
17798    
17799                                    args = new Object[] { wikiPageModelImpl.getNodeId() };
17800    
17801                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NODEID, args);
17802                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID,
17803                                            args);
17804                            }
17805    
17806                            if ((wikiPageModelImpl.getColumnBitmask() &
17807                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT.getColumnBitmask()) != 0) {
17808                                    Object[] args = new Object[] {
17809                                                    wikiPageModelImpl.getOriginalFormat()
17810                                            };
17811    
17812                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FORMAT, args);
17813                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT,
17814                                            args);
17815    
17816                                    args = new Object[] { wikiPageModelImpl.getFormat() };
17817    
17818                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FORMAT, args);
17819                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT,
17820                                            args);
17821                            }
17822    
17823                            if ((wikiPageModelImpl.getColumnBitmask() &
17824                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N.getColumnBitmask()) != 0) {
17825                                    Object[] args = new Object[] {
17826                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
17827                                                    wikiPageModelImpl.getOriginalNodeId()
17828                                            };
17829    
17830                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N, args);
17831                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N,
17832                                            args);
17833    
17834                                    args = new Object[] {
17835                                                    wikiPageModelImpl.getResourcePrimKey(),
17836                                                    wikiPageModelImpl.getNodeId()
17837                                            };
17838    
17839                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N, args);
17840                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N,
17841                                            args);
17842                            }
17843    
17844                            if ((wikiPageModelImpl.getColumnBitmask() &
17845                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T.getColumnBitmask()) != 0) {
17846                                    Object[] args = new Object[] {
17847                                                    wikiPageModelImpl.getOriginalNodeId(),
17848                                                    wikiPageModelImpl.getOriginalTitle()
17849                                            };
17850    
17851                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
17852                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T,
17853                                            args);
17854    
17855                                    args = new Object[] {
17856                                                    wikiPageModelImpl.getNodeId(),
17857                                                    wikiPageModelImpl.getTitle()
17858                                            };
17859    
17860                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
17861                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T,
17862                                            args);
17863                            }
17864    
17865                            if ((wikiPageModelImpl.getColumnBitmask() &
17866                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H.getColumnBitmask()) != 0) {
17867                                    Object[] args = new Object[] {
17868                                                    wikiPageModelImpl.getOriginalNodeId(),
17869                                                    wikiPageModelImpl.getOriginalHead()
17870                                            };
17871    
17872                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H, args);
17873                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H,
17874                                            args);
17875    
17876                                    args = new Object[] {
17877                                                    wikiPageModelImpl.getNodeId(),
17878                                                    wikiPageModelImpl.getHead()
17879                                            };
17880    
17881                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H, args);
17882                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H,
17883                                            args);
17884                            }
17885    
17886                            if ((wikiPageModelImpl.getColumnBitmask() &
17887                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P.getColumnBitmask()) != 0) {
17888                                    Object[] args = new Object[] {
17889                                                    wikiPageModelImpl.getOriginalNodeId(),
17890                                                    wikiPageModelImpl.getOriginalParentTitle()
17891                                            };
17892    
17893                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_P, args);
17894                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P,
17895                                            args);
17896    
17897                                    args = new Object[] {
17898                                                    wikiPageModelImpl.getNodeId(),
17899                                                    wikiPageModelImpl.getParentTitle()
17900                                            };
17901    
17902                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_P, args);
17903                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P,
17904                                            args);
17905                            }
17906    
17907                            if ((wikiPageModelImpl.getColumnBitmask() &
17908                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R.getColumnBitmask()) != 0) {
17909                                    Object[] args = new Object[] {
17910                                                    wikiPageModelImpl.getOriginalNodeId(),
17911                                                    wikiPageModelImpl.getOriginalRedirectTitle()
17912                                            };
17913    
17914                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_R, args);
17915                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R,
17916                                            args);
17917    
17918                                    args = new Object[] {
17919                                                    wikiPageModelImpl.getNodeId(),
17920                                                    wikiPageModelImpl.getRedirectTitle()
17921                                            };
17922    
17923                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_R, args);
17924                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R,
17925                                            args);
17926                            }
17927    
17928                            if ((wikiPageModelImpl.getColumnBitmask() &
17929                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S.getColumnBitmask()) != 0) {
17930                                    Object[] args = new Object[] {
17931                                                    wikiPageModelImpl.getOriginalNodeId(),
17932                                                    wikiPageModelImpl.getOriginalStatus()
17933                                            };
17934    
17935                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_S, args);
17936                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S,
17937                                            args);
17938    
17939                                    args = new Object[] {
17940                                                    wikiPageModelImpl.getNodeId(),
17941                                                    wikiPageModelImpl.getStatus()
17942                                            };
17943    
17944                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_S, args);
17945                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S,
17946                                            args);
17947                            }
17948    
17949                            if ((wikiPageModelImpl.getColumnBitmask() &
17950                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H.getColumnBitmask()) != 0) {
17951                                    Object[] args = new Object[] {
17952                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
17953                                                    wikiPageModelImpl.getOriginalNodeId(),
17954                                                    wikiPageModelImpl.getOriginalHead()
17955                                            };
17956    
17957                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_H, args);
17958                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H,
17959                                            args);
17960    
17961                                    args = new Object[] {
17962                                                    wikiPageModelImpl.getResourcePrimKey(),
17963                                                    wikiPageModelImpl.getNodeId(),
17964                                                    wikiPageModelImpl.getHead()
17965                                            };
17966    
17967                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_H, args);
17968                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H,
17969                                            args);
17970                            }
17971    
17972                            if ((wikiPageModelImpl.getColumnBitmask() &
17973                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S.getColumnBitmask()) != 0) {
17974                                    Object[] args = new Object[] {
17975                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
17976                                                    wikiPageModelImpl.getOriginalNodeId(),
17977                                                    wikiPageModelImpl.getOriginalStatus()
17978                                            };
17979    
17980                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_S, args);
17981                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S,
17982                                            args);
17983    
17984                                    args = new Object[] {
17985                                                    wikiPageModelImpl.getResourcePrimKey(),
17986                                                    wikiPageModelImpl.getNodeId(),
17987                                                    wikiPageModelImpl.getStatus()
17988                                            };
17989    
17990                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_S, args);
17991                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S,
17992                                            args);
17993                            }
17994    
17995                            if ((wikiPageModelImpl.getColumnBitmask() &
17996                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H.getColumnBitmask()) != 0) {
17997                                    Object[] args = new Object[] {
17998                                                    wikiPageModelImpl.getOriginalGroupId(),
17999                                                    wikiPageModelImpl.getOriginalNodeId(),
18000                                                    wikiPageModelImpl.getOriginalHead()
18001                                            };
18002    
18003                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H, args);
18004                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H,
18005                                            args);
18006    
18007                                    args = new Object[] {
18008                                                    wikiPageModelImpl.getGroupId(),
18009                                                    wikiPageModelImpl.getNodeId(),
18010                                                    wikiPageModelImpl.getHead()
18011                                            };
18012    
18013                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H, args);
18014                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H,
18015                                            args);
18016                            }
18017    
18018                            if ((wikiPageModelImpl.getColumnBitmask() &
18019                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S.getColumnBitmask()) != 0) {
18020                                    Object[] args = new Object[] {
18021                                                    wikiPageModelImpl.getOriginalGroupId(),
18022                                                    wikiPageModelImpl.getOriginalNodeId(),
18023                                                    wikiPageModelImpl.getOriginalStatus()
18024                                            };
18025    
18026                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_S, args);
18027                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S,
18028                                            args);
18029    
18030                                    args = new Object[] {
18031                                                    wikiPageModelImpl.getGroupId(),
18032                                                    wikiPageModelImpl.getNodeId(),
18033                                                    wikiPageModelImpl.getStatus()
18034                                            };
18035    
18036                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_S, args);
18037                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S,
18038                                            args);
18039                            }
18040    
18041                            if ((wikiPageModelImpl.getColumnBitmask() &
18042                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S.getColumnBitmask()) != 0) {
18043                                    Object[] args = new Object[] {
18044                                                    wikiPageModelImpl.getOriginalUserId(),
18045                                                    wikiPageModelImpl.getOriginalNodeId(),
18046                                                    wikiPageModelImpl.getOriginalStatus()
18047                                            };
18048    
18049                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_N_S, args);
18050                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S,
18051                                            args);
18052    
18053                                    args = new Object[] {
18054                                                    wikiPageModelImpl.getUserId(),
18055                                                    wikiPageModelImpl.getNodeId(),
18056                                                    wikiPageModelImpl.getStatus()
18057                                            };
18058    
18059                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_N_S, args);
18060                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S,
18061                                            args);
18062                            }
18063    
18064                            if ((wikiPageModelImpl.getColumnBitmask() &
18065                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H.getColumnBitmask()) != 0) {
18066                                    Object[] args = new Object[] {
18067                                                    wikiPageModelImpl.getOriginalNodeId(),
18068                                                    wikiPageModelImpl.getOriginalTitle(),
18069                                                    wikiPageModelImpl.getOriginalHead()
18070                                            };
18071    
18072                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_H, args);
18073                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H,
18074                                            args);
18075    
18076                                    args = new Object[] {
18077                                                    wikiPageModelImpl.getNodeId(),
18078                                                    wikiPageModelImpl.getTitle(),
18079                                                    wikiPageModelImpl.getHead()
18080                                            };
18081    
18082                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_H, args);
18083                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H,
18084                                            args);
18085                            }
18086    
18087                            if ((wikiPageModelImpl.getColumnBitmask() &
18088                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S.getColumnBitmask()) != 0) {
18089                                    Object[] args = new Object[] {
18090                                                    wikiPageModelImpl.getOriginalNodeId(),
18091                                                    wikiPageModelImpl.getOriginalTitle(),
18092                                                    wikiPageModelImpl.getOriginalStatus()
18093                                            };
18094    
18095                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_S, args);
18096                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S,
18097                                            args);
18098    
18099                                    args = new Object[] {
18100                                                    wikiPageModelImpl.getNodeId(),
18101                                                    wikiPageModelImpl.getTitle(),
18102                                                    wikiPageModelImpl.getStatus()
18103                                            };
18104    
18105                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_S, args);
18106                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S,
18107                                            args);
18108                            }
18109    
18110                            if ((wikiPageModelImpl.getColumnBitmask() &
18111                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P.getColumnBitmask()) != 0) {
18112                                    Object[] args = new Object[] {
18113                                                    wikiPageModelImpl.getOriginalNodeId(),
18114                                                    wikiPageModelImpl.getOriginalHead(),
18115                                                    wikiPageModelImpl.getOriginalParentTitle()
18116                                            };
18117    
18118                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P, args);
18119                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P,
18120                                            args);
18121    
18122                                    args = new Object[] {
18123                                                    wikiPageModelImpl.getNodeId(),
18124                                                    wikiPageModelImpl.getHead(),
18125                                                    wikiPageModelImpl.getParentTitle()
18126                                            };
18127    
18128                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P, args);
18129                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P,
18130                                            args);
18131                            }
18132    
18133                            if ((wikiPageModelImpl.getColumnBitmask() &
18134                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S.getColumnBitmask()) != 0) {
18135                                    Object[] args = new Object[] {
18136                                                    wikiPageModelImpl.getOriginalNodeId(),
18137                                                    wikiPageModelImpl.getOriginalHead(),
18138                                                    wikiPageModelImpl.getOriginalStatus()
18139                                            };
18140    
18141                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_S, args);
18142                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S,
18143                                            args);
18144    
18145                                    args = new Object[] {
18146                                                    wikiPageModelImpl.getNodeId(),
18147                                                    wikiPageModelImpl.getHead(),
18148                                                    wikiPageModelImpl.getStatus()
18149                                            };
18150    
18151                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_S, args);
18152                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S,
18153                                            args);
18154                            }
18155    
18156                            if ((wikiPageModelImpl.getColumnBitmask() &
18157                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S.getColumnBitmask()) != 0) {
18158                                    Object[] args = new Object[] {
18159                                                    wikiPageModelImpl.getOriginalGroupId(),
18160                                                    wikiPageModelImpl.getOriginalUserId(),
18161                                                    wikiPageModelImpl.getOriginalNodeId(),
18162                                                    wikiPageModelImpl.getOriginalStatus()
18163                                            };
18164    
18165                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_N_S, args);
18166                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S,
18167                                            args);
18168    
18169                                    args = new Object[] {
18170                                                    wikiPageModelImpl.getGroupId(),
18171                                                    wikiPageModelImpl.getUserId(),
18172                                                    wikiPageModelImpl.getNodeId(),
18173                                                    wikiPageModelImpl.getStatus()
18174                                            };
18175    
18176                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_N_S, args);
18177                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S,
18178                                            args);
18179                            }
18180    
18181                            if ((wikiPageModelImpl.getColumnBitmask() &
18182                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H.getColumnBitmask()) != 0) {
18183                                    Object[] args = new Object[] {
18184                                                    wikiPageModelImpl.getOriginalGroupId(),
18185                                                    wikiPageModelImpl.getOriginalNodeId(),
18186                                                    wikiPageModelImpl.getOriginalTitle(),
18187                                                    wikiPageModelImpl.getOriginalHead()
18188                                            };
18189    
18190                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T_H, args);
18191                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H,
18192                                            args);
18193    
18194                                    args = new Object[] {
18195                                                    wikiPageModelImpl.getGroupId(),
18196                                                    wikiPageModelImpl.getNodeId(),
18197                                                    wikiPageModelImpl.getTitle(),
18198                                                    wikiPageModelImpl.getHead()
18199                                            };
18200    
18201                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T_H, args);
18202                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H,
18203                                            args);
18204                            }
18205    
18206                            if ((wikiPageModelImpl.getColumnBitmask() &
18207                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S.getColumnBitmask()) != 0) {
18208                                    Object[] args = new Object[] {
18209                                                    wikiPageModelImpl.getOriginalGroupId(),
18210                                                    wikiPageModelImpl.getOriginalNodeId(),
18211                                                    wikiPageModelImpl.getOriginalHead(),
18212                                                    wikiPageModelImpl.getOriginalStatus()
18213                                            };
18214    
18215                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_S, args);
18216                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S,
18217                                            args);
18218    
18219                                    args = new Object[] {
18220                                                    wikiPageModelImpl.getGroupId(),
18221                                                    wikiPageModelImpl.getNodeId(),
18222                                                    wikiPageModelImpl.getHead(),
18223                                                    wikiPageModelImpl.getStatus()
18224                                            };
18225    
18226                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_S, args);
18227                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S,
18228                                            args);
18229                            }
18230    
18231                            if ((wikiPageModelImpl.getColumnBitmask() &
18232                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S.getColumnBitmask()) != 0) {
18233                                    Object[] args = new Object[] {
18234                                                    wikiPageModelImpl.getOriginalNodeId(),
18235                                                    wikiPageModelImpl.getOriginalHead(),
18236                                                    wikiPageModelImpl.getOriginalParentTitle(),
18237                                                    wikiPageModelImpl.getOriginalStatus()
18238                                            };
18239    
18240                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P_S, args);
18241                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S,
18242                                            args);
18243    
18244                                    args = new Object[] {
18245                                                    wikiPageModelImpl.getNodeId(),
18246                                                    wikiPageModelImpl.getHead(),
18247                                                    wikiPageModelImpl.getParentTitle(),
18248                                                    wikiPageModelImpl.getStatus()
18249                                            };
18250    
18251                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P_S, args);
18252                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S,
18253                                            args);
18254                            }
18255    
18256                            if ((wikiPageModelImpl.getColumnBitmask() &
18257                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S.getColumnBitmask()) != 0) {
18258                                    Object[] args = new Object[] {
18259                                                    wikiPageModelImpl.getOriginalGroupId(),
18260                                                    wikiPageModelImpl.getOriginalNodeId(),
18261                                                    wikiPageModelImpl.getOriginalHead(),
18262                                                    wikiPageModelImpl.getOriginalParentTitle(),
18263                                                    wikiPageModelImpl.getOriginalStatus()
18264                                            };
18265    
18266                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_P_S,
18267                                            args);
18268                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S,
18269                                            args);
18270    
18271                                    args = new Object[] {
18272                                                    wikiPageModelImpl.getGroupId(),
18273                                                    wikiPageModelImpl.getNodeId(),
18274                                                    wikiPageModelImpl.getHead(),
18275                                                    wikiPageModelImpl.getParentTitle(),
18276                                                    wikiPageModelImpl.getStatus()
18277                                            };
18278    
18279                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_P_S,
18280                                            args);
18281                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S,
18282                                            args);
18283                            }
18284                    }
18285    
18286                    EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
18287                            WikiPageImpl.class, wikiPage.getPrimaryKey(), wikiPage);
18288    
18289                    clearUniqueFindersCache(wikiPage);
18290                    cacheUniqueFindersCache(wikiPage);
18291    
18292                    return wikiPage;
18293            }
18294    
18295            protected WikiPage toUnwrappedModel(WikiPage wikiPage) {
18296                    if (wikiPage instanceof WikiPageImpl) {
18297                            return wikiPage;
18298                    }
18299    
18300                    WikiPageImpl wikiPageImpl = new WikiPageImpl();
18301    
18302                    wikiPageImpl.setNew(wikiPage.isNew());
18303                    wikiPageImpl.setPrimaryKey(wikiPage.getPrimaryKey());
18304    
18305                    wikiPageImpl.setUuid(wikiPage.getUuid());
18306                    wikiPageImpl.setPageId(wikiPage.getPageId());
18307                    wikiPageImpl.setResourcePrimKey(wikiPage.getResourcePrimKey());
18308                    wikiPageImpl.setGroupId(wikiPage.getGroupId());
18309                    wikiPageImpl.setCompanyId(wikiPage.getCompanyId());
18310                    wikiPageImpl.setUserId(wikiPage.getUserId());
18311                    wikiPageImpl.setUserName(wikiPage.getUserName());
18312                    wikiPageImpl.setCreateDate(wikiPage.getCreateDate());
18313                    wikiPageImpl.setModifiedDate(wikiPage.getModifiedDate());
18314                    wikiPageImpl.setNodeId(wikiPage.getNodeId());
18315                    wikiPageImpl.setTitle(wikiPage.getTitle());
18316                    wikiPageImpl.setVersion(wikiPage.getVersion());
18317                    wikiPageImpl.setMinorEdit(wikiPage.isMinorEdit());
18318                    wikiPageImpl.setContent(wikiPage.getContent());
18319                    wikiPageImpl.setSummary(wikiPage.getSummary());
18320                    wikiPageImpl.setFormat(wikiPage.getFormat());
18321                    wikiPageImpl.setHead(wikiPage.isHead());
18322                    wikiPageImpl.setParentTitle(wikiPage.getParentTitle());
18323                    wikiPageImpl.setRedirectTitle(wikiPage.getRedirectTitle());
18324                    wikiPageImpl.setStatus(wikiPage.getStatus());
18325                    wikiPageImpl.setStatusByUserId(wikiPage.getStatusByUserId());
18326                    wikiPageImpl.setStatusByUserName(wikiPage.getStatusByUserName());
18327                    wikiPageImpl.setStatusDate(wikiPage.getStatusDate());
18328    
18329                    return wikiPageImpl;
18330            }
18331    
18332            /**
18333             * Returns the wiki page with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
18334             *
18335             * @param primaryKey the primary key of the wiki page
18336             * @return the wiki page
18337             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
18338             * @throws SystemException if a system exception occurred
18339             */
18340            @Override
18341            public WikiPage findByPrimaryKey(Serializable primaryKey)
18342                    throws NoSuchPageException, SystemException {
18343                    WikiPage wikiPage = fetchByPrimaryKey(primaryKey);
18344    
18345                    if (wikiPage == null) {
18346                            if (_log.isWarnEnabled()) {
18347                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
18348                            }
18349    
18350                            throw new NoSuchPageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
18351                                    primaryKey);
18352                    }
18353    
18354                    return wikiPage;
18355            }
18356    
18357            /**
18358             * Returns the wiki page with the primary key or throws a {@link com.liferay.portlet.wiki.NoSuchPageException} if it could not be found.
18359             *
18360             * @param pageId the primary key of the wiki page
18361             * @return the wiki page
18362             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
18363             * @throws SystemException if a system exception occurred
18364             */
18365            @Override
18366            public WikiPage findByPrimaryKey(long pageId)
18367                    throws NoSuchPageException, SystemException {
18368                    return findByPrimaryKey((Serializable)pageId);
18369            }
18370    
18371            /**
18372             * Returns the wiki page with the primary key or returns <code>null</code> if it could not be found.
18373             *
18374             * @param primaryKey the primary key of the wiki page
18375             * @return the wiki page, or <code>null</code> if a wiki page with the primary key could not be found
18376             * @throws SystemException if a system exception occurred
18377             */
18378            @Override
18379            public WikiPage fetchByPrimaryKey(Serializable primaryKey)
18380                    throws SystemException {
18381                    WikiPage wikiPage = (WikiPage)EntityCacheUtil.getResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
18382                                    WikiPageImpl.class, primaryKey);
18383    
18384                    if (wikiPage == _nullWikiPage) {
18385                            return null;
18386                    }
18387    
18388                    if (wikiPage == null) {
18389                            Session session = null;
18390    
18391                            try {
18392                                    session = openSession();
18393    
18394                                    wikiPage = (WikiPage)session.get(WikiPageImpl.class, primaryKey);
18395    
18396                                    if (wikiPage != null) {
18397                                            cacheResult(wikiPage);
18398                                    }
18399                                    else {
18400                                            EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
18401                                                    WikiPageImpl.class, primaryKey, _nullWikiPage);
18402                                    }
18403                            }
18404                            catch (Exception e) {
18405                                    EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
18406                                            WikiPageImpl.class, primaryKey);
18407    
18408                                    throw processException(e);
18409                            }
18410                            finally {
18411                                    closeSession(session);
18412                            }
18413                    }
18414    
18415                    return wikiPage;
18416            }
18417    
18418            /**
18419             * Returns the wiki page with the primary key or returns <code>null</code> if it could not be found.
18420             *
18421             * @param pageId the primary key of the wiki page
18422             * @return the wiki page, or <code>null</code> if a wiki page with the primary key could not be found
18423             * @throws SystemException if a system exception occurred
18424             */
18425            @Override
18426            public WikiPage fetchByPrimaryKey(long pageId) throws SystemException {
18427                    return fetchByPrimaryKey((Serializable)pageId);
18428            }
18429    
18430            /**
18431             * Returns all the wiki pages.
18432             *
18433             * @return the wiki pages
18434             * @throws SystemException if a system exception occurred
18435             */
18436            @Override
18437            public List<WikiPage> findAll() throws SystemException {
18438                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
18439            }
18440    
18441            /**
18442             * Returns a range of all the wiki pages.
18443             *
18444             * <p>
18445             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18446             * </p>
18447             *
18448             * @param start the lower bound of the range of wiki pages
18449             * @param end the upper bound of the range of wiki pages (not inclusive)
18450             * @return the range of wiki pages
18451             * @throws SystemException if a system exception occurred
18452             */
18453            @Override
18454            public List<WikiPage> findAll(int start, int end) throws SystemException {
18455                    return findAll(start, end, null);
18456            }
18457    
18458            /**
18459             * Returns an ordered range of all the wiki pages.
18460             *
18461             * <p>
18462             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18463             * </p>
18464             *
18465             * @param start the lower bound of the range of wiki pages
18466             * @param end the upper bound of the range of wiki pages (not inclusive)
18467             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18468             * @return the ordered range of wiki pages
18469             * @throws SystemException if a system exception occurred
18470             */
18471            @Override
18472            public List<WikiPage> findAll(int start, int end,
18473                    OrderByComparator orderByComparator) throws SystemException {
18474                    boolean pagination = true;
18475                    FinderPath finderPath = null;
18476                    Object[] finderArgs = null;
18477    
18478                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
18479                                    (orderByComparator == null)) {
18480                            pagination = false;
18481                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
18482                            finderArgs = FINDER_ARGS_EMPTY;
18483                    }
18484                    else {
18485                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
18486                            finderArgs = new Object[] { start, end, orderByComparator };
18487                    }
18488    
18489                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
18490                                    finderArgs, this);
18491    
18492                    if (list == null) {
18493                            StringBundler query = null;
18494                            String sql = null;
18495    
18496                            if (orderByComparator != null) {
18497                                    query = new StringBundler(2 +
18498                                                    (orderByComparator.getOrderByFields().length * 3));
18499    
18500                                    query.append(_SQL_SELECT_WIKIPAGE);
18501    
18502                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18503                                            orderByComparator);
18504    
18505                                    sql = query.toString();
18506                            }
18507                            else {
18508                                    sql = _SQL_SELECT_WIKIPAGE;
18509    
18510                                    if (pagination) {
18511                                            sql = sql.concat(WikiPageModelImpl.ORDER_BY_JPQL);
18512                                    }
18513                            }
18514    
18515                            Session session = null;
18516    
18517                            try {
18518                                    session = openSession();
18519    
18520                                    Query q = session.createQuery(sql);
18521    
18522                                    if (!pagination) {
18523                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
18524                                                            start, end, false);
18525    
18526                                            Collections.sort(list);
18527    
18528                                            list = new UnmodifiableList<WikiPage>(list);
18529                                    }
18530                                    else {
18531                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
18532                                                            start, end);
18533                                    }
18534    
18535                                    cacheResult(list);
18536    
18537                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
18538                            }
18539                            catch (Exception e) {
18540                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18541    
18542                                    throw processException(e);
18543                            }
18544                            finally {
18545                                    closeSession(session);
18546                            }
18547                    }
18548    
18549                    return list;
18550            }
18551    
18552            /**
18553             * Removes all the wiki pages from the database.
18554             *
18555             * @throws SystemException if a system exception occurred
18556             */
18557            @Override
18558            public void removeAll() throws SystemException {
18559                    for (WikiPage wikiPage : findAll()) {
18560                            remove(wikiPage);
18561                    }
18562            }
18563    
18564            /**
18565             * Returns the number of wiki pages.
18566             *
18567             * @return the number of wiki pages
18568             * @throws SystemException if a system exception occurred
18569             */
18570            @Override
18571            public int countAll() throws SystemException {
18572                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
18573                                    FINDER_ARGS_EMPTY, this);
18574    
18575                    if (count == null) {
18576                            Session session = null;
18577    
18578                            try {
18579                                    session = openSession();
18580    
18581                                    Query q = session.createQuery(_SQL_COUNT_WIKIPAGE);
18582    
18583                                    count = (Long)q.uniqueResult();
18584    
18585                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
18586                                            FINDER_ARGS_EMPTY, count);
18587                            }
18588                            catch (Exception e) {
18589                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
18590                                            FINDER_ARGS_EMPTY);
18591    
18592                                    throw processException(e);
18593                            }
18594                            finally {
18595                                    closeSession(session);
18596                            }
18597                    }
18598    
18599                    return count.intValue();
18600            }
18601    
18602            @Override
18603            protected Set<String> getBadColumnNames() {
18604                    return _badColumnNames;
18605            }
18606    
18607            /**
18608             * Initializes the wiki page persistence.
18609             */
18610            public void afterPropertiesSet() {
18611                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
18612                                            com.liferay.portal.util.PropsUtil.get(
18613                                                    "value.object.listener.com.liferay.portlet.wiki.model.WikiPage")));
18614    
18615                    if (listenerClassNames.length > 0) {
18616                            try {
18617                                    List<ModelListener<WikiPage>> listenersList = new ArrayList<ModelListener<WikiPage>>();
18618    
18619                                    for (String listenerClassName : listenerClassNames) {
18620                                            listenersList.add((ModelListener<WikiPage>)InstanceFactory.newInstance(
18621                                                            getClassLoader(), listenerClassName));
18622                                    }
18623    
18624                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
18625                            }
18626                            catch (Exception e) {
18627                                    _log.error(e);
18628                            }
18629                    }
18630            }
18631    
18632            public void destroy() {
18633                    EntityCacheUtil.removeCache(WikiPageImpl.class.getName());
18634                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
18635                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18636                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18637            }
18638    
18639            private static final String _SQL_SELECT_WIKIPAGE = "SELECT wikiPage FROM WikiPage wikiPage";
18640            private static final String _SQL_SELECT_WIKIPAGE_WHERE = "SELECT wikiPage FROM WikiPage wikiPage WHERE ";
18641            private static final String _SQL_COUNT_WIKIPAGE = "SELECT COUNT(wikiPage) FROM WikiPage wikiPage";
18642            private static final String _SQL_COUNT_WIKIPAGE_WHERE = "SELECT COUNT(wikiPage) FROM WikiPage wikiPage WHERE ";
18643            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "wikiPage.resourcePrimKey";
18644            private static final String _FILTER_SQL_SELECT_WIKIPAGE_WHERE = "SELECT DISTINCT {wikiPage.*} FROM WikiPage wikiPage WHERE ";
18645            private static final String _FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1 =
18646                    "SELECT {WikiPage.*} FROM (SELECT DISTINCT wikiPage.pageId FROM WikiPage wikiPage WHERE ";
18647            private static final String _FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2 =
18648                    ") TEMP_TABLE INNER JOIN WikiPage ON TEMP_TABLE.pageId = WikiPage.pageId";
18649            private static final String _FILTER_SQL_COUNT_WIKIPAGE_WHERE = "SELECT COUNT(DISTINCT wikiPage.pageId) AS COUNT_VALUE FROM WikiPage wikiPage WHERE ";
18650            private static final String _FILTER_ENTITY_ALIAS = "wikiPage";
18651            private static final String _FILTER_ENTITY_TABLE = "WikiPage";
18652            private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPage.";
18653            private static final String _ORDER_BY_ENTITY_TABLE = "WikiPage.";
18654            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPage exists with the primary key ";
18655            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPage exists with the key {";
18656            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
18657            private static Log _log = LogFactoryUtil.getLog(WikiPagePersistenceImpl.class);
18658            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
18659                                    "uuid"
18660                            });
18661            private static WikiPage _nullWikiPage = new WikiPageImpl() {
18662                            @Override
18663                            public Object clone() {
18664                                    return this;
18665                            }
18666    
18667                            @Override
18668                            public CacheModel<WikiPage> toCacheModel() {
18669                                    return _nullWikiPageCacheModel;
18670                            }
18671                    };
18672    
18673            private static CacheModel<WikiPage> _nullWikiPageCacheModel = new CacheModel<WikiPage>() {
18674                            @Override
18675                            public WikiPage toEntityModel() {
18676                                    return _nullWikiPage;
18677                            }
18678                    };
18679    }