001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.wiki.service.persistence;
016    
017    import com.liferay.portal.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.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import com.liferay.portlet.wiki.NoSuchNodeException;
044    import com.liferay.portlet.wiki.model.WikiNode;
045    import com.liferay.portlet.wiki.model.impl.WikiNodeImpl;
046    import com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl;
047    
048    import java.io.Serializable;
049    
050    import java.util.ArrayList;
051    import java.util.Collections;
052    import java.util.List;
053    
054    /**
055     * The persistence implementation for the wiki node service.
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see WikiNodePersistence
063     * @see WikiNodeUtil
064     * @generated
065     */
066    public class WikiNodePersistenceImpl extends BasePersistenceImpl<WikiNode>
067            implements WikiNodePersistence {
068            /*
069             * NOTE FOR DEVELOPERS:
070             *
071             * Never modify or reference this class directly. Always use {@link WikiNodeUtil} to access the wiki node persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
072             */
073            public static final String FINDER_CLASS_NAME_ENTITY = WikiNodeImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List1";
076            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List2";
078            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
079                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
082                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
085                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
088                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
090                            new String[] {
091                                    String.class.getName(),
092                                    
093                            Integer.class.getName(), Integer.class.getName(),
094                                    OrderByComparator.class.getName()
095                            });
096            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
097                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
099                            new String[] { String.class.getName() },
100                            WikiNodeModelImpl.UUID_COLUMN_BITMASK |
101                            WikiNodeModelImpl.NAME_COLUMN_BITMASK);
102            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
103                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
105                            new String[] { String.class.getName() });
106    
107            /**
108             * Returns all the wiki nodes where uuid = &#63;.
109             *
110             * @param uuid the uuid
111             * @return the matching wiki nodes
112             * @throws SystemException if a system exception occurred
113             */
114            public List<WikiNode> findByUuid(String uuid) throws SystemException {
115                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
116            }
117    
118            /**
119             * Returns a range of all the wiki nodes where uuid = &#63;.
120             *
121             * <p>
122             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
123             * </p>
124             *
125             * @param uuid the uuid
126             * @param start the lower bound of the range of wiki nodes
127             * @param end the upper bound of the range of wiki nodes (not inclusive)
128             * @return the range of matching wiki nodes
129             * @throws SystemException if a system exception occurred
130             */
131            public List<WikiNode> findByUuid(String uuid, int start, int end)
132                    throws SystemException {
133                    return findByUuid(uuid, start, end, null);
134            }
135    
136            /**
137             * Returns an ordered range of all the wiki nodes where uuid = &#63;.
138             *
139             * <p>
140             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
141             * </p>
142             *
143             * @param uuid the uuid
144             * @param start the lower bound of the range of wiki nodes
145             * @param end the upper bound of the range of wiki nodes (not inclusive)
146             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
147             * @return the ordered range of matching wiki nodes
148             * @throws SystemException if a system exception occurred
149             */
150            public List<WikiNode> findByUuid(String uuid, int start, int end,
151                    OrderByComparator orderByComparator) throws SystemException {
152                    boolean pagination = true;
153                    FinderPath finderPath = null;
154                    Object[] finderArgs = null;
155    
156                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
157                                    (orderByComparator == null)) {
158                            pagination = false;
159                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
160                            finderArgs = new Object[] { uuid };
161                    }
162                    else {
163                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
164                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
165                    }
166    
167                    List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
168                                    finderArgs, this);
169    
170                    if ((list != null) && !list.isEmpty()) {
171                            for (WikiNode wikiNode : list) {
172                                    if (!Validator.equals(uuid, wikiNode.getUuid())) {
173                                            list = null;
174    
175                                            break;
176                                    }
177                            }
178                    }
179    
180                    if (list == null) {
181                            StringBundler query = null;
182    
183                            if (orderByComparator != null) {
184                                    query = new StringBundler(3 +
185                                                    (orderByComparator.getOrderByFields().length * 3));
186                            }
187                            else {
188                                    query = new StringBundler(3);
189                            }
190    
191                            query.append(_SQL_SELECT_WIKINODE_WHERE);
192    
193                            boolean bindUuid = false;
194    
195                            if (uuid == null) {
196                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
197                            }
198                            else if (uuid.equals(StringPool.BLANK)) {
199                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
200                            }
201                            else {
202                                    bindUuid = true;
203    
204                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
205                            }
206    
207                            if (orderByComparator != null) {
208                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
209                                            orderByComparator);
210                            }
211                            else
212                             if (pagination) {
213                                    query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
214                            }
215    
216                            String sql = query.toString();
217    
218                            Session session = null;
219    
220                            try {
221                                    session = openSession();
222    
223                                    Query q = session.createQuery(sql);
224    
225                                    QueryPos qPos = QueryPos.getInstance(q);
226    
227                                    if (bindUuid) {
228                                            qPos.add(uuid);
229                                    }
230    
231                                    if (!pagination) {
232                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
233                                                            start, end, false);
234    
235                                            Collections.sort(list);
236    
237                                            list = new UnmodifiableList<WikiNode>(list);
238                                    }
239                                    else {
240                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
241                                                            start, end);
242                                    }
243    
244                                    cacheResult(list);
245    
246                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
247                            }
248                            catch (Exception e) {
249                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
250    
251                                    throw processException(e);
252                            }
253                            finally {
254                                    closeSession(session);
255                            }
256                    }
257    
258                    return list;
259            }
260    
261            /**
262             * Returns the first wiki node in the ordered set where uuid = &#63;.
263             *
264             * @param uuid the uuid
265             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
266             * @return the first matching wiki node
267             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
268             * @throws SystemException if a system exception occurred
269             */
270            public WikiNode findByUuid_First(String uuid,
271                    OrderByComparator orderByComparator)
272                    throws NoSuchNodeException, SystemException {
273                    WikiNode wikiNode = fetchByUuid_First(uuid, orderByComparator);
274    
275                    if (wikiNode != null) {
276                            return wikiNode;
277                    }
278    
279                    StringBundler msg = new StringBundler(4);
280    
281                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
282    
283                    msg.append("uuid=");
284                    msg.append(uuid);
285    
286                    msg.append(StringPool.CLOSE_CURLY_BRACE);
287    
288                    throw new NoSuchNodeException(msg.toString());
289            }
290    
291            /**
292             * Returns the first wiki node in the ordered set where uuid = &#63;.
293             *
294             * @param uuid the uuid
295             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
296             * @return the first matching wiki node, or <code>null</code> if a matching wiki node could not be found
297             * @throws SystemException if a system exception occurred
298             */
299            public WikiNode fetchByUuid_First(String uuid,
300                    OrderByComparator orderByComparator) throws SystemException {
301                    List<WikiNode> list = findByUuid(uuid, 0, 1, orderByComparator);
302    
303                    if (!list.isEmpty()) {
304                            return list.get(0);
305                    }
306    
307                    return null;
308            }
309    
310            /**
311             * Returns the last wiki node in the ordered set where uuid = &#63;.
312             *
313             * @param uuid the uuid
314             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
315             * @return the last matching wiki node
316             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
317             * @throws SystemException if a system exception occurred
318             */
319            public WikiNode findByUuid_Last(String uuid,
320                    OrderByComparator orderByComparator)
321                    throws NoSuchNodeException, SystemException {
322                    WikiNode wikiNode = fetchByUuid_Last(uuid, orderByComparator);
323    
324                    if (wikiNode != null) {
325                            return wikiNode;
326                    }
327    
328                    StringBundler msg = new StringBundler(4);
329    
330                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
331    
332                    msg.append("uuid=");
333                    msg.append(uuid);
334    
335                    msg.append(StringPool.CLOSE_CURLY_BRACE);
336    
337                    throw new NoSuchNodeException(msg.toString());
338            }
339    
340            /**
341             * Returns the last wiki node in the ordered set where uuid = &#63;.
342             *
343             * @param uuid the uuid
344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
345             * @return the last matching wiki node, or <code>null</code> if a matching wiki node could not be found
346             * @throws SystemException if a system exception occurred
347             */
348            public WikiNode fetchByUuid_Last(String uuid,
349                    OrderByComparator orderByComparator) throws SystemException {
350                    int count = countByUuid(uuid);
351    
352                    List<WikiNode> list = findByUuid(uuid, count - 1, count,
353                                    orderByComparator);
354    
355                    if (!list.isEmpty()) {
356                            return list.get(0);
357                    }
358    
359                    return null;
360            }
361    
362            /**
363             * Returns the wiki nodes before and after the current wiki node in the ordered set where uuid = &#63;.
364             *
365             * @param nodeId the primary key of the current wiki node
366             * @param uuid the uuid
367             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
368             * @return the previous, current, and next wiki node
369             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
370             * @throws SystemException if a system exception occurred
371             */
372            public WikiNode[] findByUuid_PrevAndNext(long nodeId, String uuid,
373                    OrderByComparator orderByComparator)
374                    throws NoSuchNodeException, SystemException {
375                    WikiNode wikiNode = findByPrimaryKey(nodeId);
376    
377                    Session session = null;
378    
379                    try {
380                            session = openSession();
381    
382                            WikiNode[] array = new WikiNodeImpl[3];
383    
384                            array[0] = getByUuid_PrevAndNext(session, wikiNode, uuid,
385                                            orderByComparator, true);
386    
387                            array[1] = wikiNode;
388    
389                            array[2] = getByUuid_PrevAndNext(session, wikiNode, uuid,
390                                            orderByComparator, false);
391    
392                            return array;
393                    }
394                    catch (Exception e) {
395                            throw processException(e);
396                    }
397                    finally {
398                            closeSession(session);
399                    }
400            }
401    
402            protected WikiNode getByUuid_PrevAndNext(Session session,
403                    WikiNode wikiNode, String uuid, OrderByComparator orderByComparator,
404                    boolean previous) {
405                    StringBundler query = null;
406    
407                    if (orderByComparator != null) {
408                            query = new StringBundler(6 +
409                                            (orderByComparator.getOrderByFields().length * 6));
410                    }
411                    else {
412                            query = new StringBundler(3);
413                    }
414    
415                    query.append(_SQL_SELECT_WIKINODE_WHERE);
416    
417                    boolean bindUuid = false;
418    
419                    if (uuid == null) {
420                            query.append(_FINDER_COLUMN_UUID_UUID_1);
421                    }
422                    else if (uuid.equals(StringPool.BLANK)) {
423                            query.append(_FINDER_COLUMN_UUID_UUID_3);
424                    }
425                    else {
426                            bindUuid = true;
427    
428                            query.append(_FINDER_COLUMN_UUID_UUID_2);
429                    }
430    
431                    if (orderByComparator != null) {
432                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
433    
434                            if (orderByConditionFields.length > 0) {
435                                    query.append(WHERE_AND);
436                            }
437    
438                            for (int i = 0; i < orderByConditionFields.length; i++) {
439                                    query.append(_ORDER_BY_ENTITY_ALIAS);
440                                    query.append(orderByConditionFields[i]);
441    
442                                    if ((i + 1) < orderByConditionFields.length) {
443                                            if (orderByComparator.isAscending() ^ previous) {
444                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
445                                            }
446                                            else {
447                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
448                                            }
449                                    }
450                                    else {
451                                            if (orderByComparator.isAscending() ^ previous) {
452                                                    query.append(WHERE_GREATER_THAN);
453                                            }
454                                            else {
455                                                    query.append(WHERE_LESSER_THAN);
456                                            }
457                                    }
458                            }
459    
460                            query.append(ORDER_BY_CLAUSE);
461    
462                            String[] orderByFields = orderByComparator.getOrderByFields();
463    
464                            for (int i = 0; i < orderByFields.length; i++) {
465                                    query.append(_ORDER_BY_ENTITY_ALIAS);
466                                    query.append(orderByFields[i]);
467    
468                                    if ((i + 1) < orderByFields.length) {
469                                            if (orderByComparator.isAscending() ^ previous) {
470                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
471                                            }
472                                            else {
473                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
474                                            }
475                                    }
476                                    else {
477                                            if (orderByComparator.isAscending() ^ previous) {
478                                                    query.append(ORDER_BY_ASC);
479                                            }
480                                            else {
481                                                    query.append(ORDER_BY_DESC);
482                                            }
483                                    }
484                            }
485                    }
486                    else {
487                            query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
488                    }
489    
490                    String sql = query.toString();
491    
492                    Query q = session.createQuery(sql);
493    
494                    q.setFirstResult(0);
495                    q.setMaxResults(2);
496    
497                    QueryPos qPos = QueryPos.getInstance(q);
498    
499                    if (bindUuid) {
500                            qPos.add(uuid);
501                    }
502    
503                    if (orderByComparator != null) {
504                            Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
505    
506                            for (Object value : values) {
507                                    qPos.add(value);
508                            }
509                    }
510    
511                    List<WikiNode> list = q.list();
512    
513                    if (list.size() == 2) {
514                            return list.get(1);
515                    }
516                    else {
517                            return null;
518                    }
519            }
520    
521            /**
522             * Removes all the wiki nodes where uuid = &#63; from the database.
523             *
524             * @param uuid the uuid
525             * @throws SystemException if a system exception occurred
526             */
527            public void removeByUuid(String uuid) throws SystemException {
528                    for (WikiNode wikiNode : findByUuid(uuid, QueryUtil.ALL_POS,
529                                    QueryUtil.ALL_POS, null)) {
530                            remove(wikiNode);
531                    }
532            }
533    
534            /**
535             * Returns the number of wiki nodes where uuid = &#63;.
536             *
537             * @param uuid the uuid
538             * @return the number of matching wiki nodes
539             * @throws SystemException if a system exception occurred
540             */
541            public int countByUuid(String uuid) throws SystemException {
542                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
543    
544                    Object[] finderArgs = new Object[] { uuid };
545    
546                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
547                                    this);
548    
549                    if (count == null) {
550                            StringBundler query = new StringBundler(2);
551    
552                            query.append(_SQL_COUNT_WIKINODE_WHERE);
553    
554                            boolean bindUuid = false;
555    
556                            if (uuid == null) {
557                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
558                            }
559                            else if (uuid.equals(StringPool.BLANK)) {
560                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
561                            }
562                            else {
563                                    bindUuid = true;
564    
565                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
566                            }
567    
568                            String sql = query.toString();
569    
570                            Session session = null;
571    
572                            try {
573                                    session = openSession();
574    
575                                    Query q = session.createQuery(sql);
576    
577                                    QueryPos qPos = QueryPos.getInstance(q);
578    
579                                    if (bindUuid) {
580                                            qPos.add(uuid);
581                                    }
582    
583                                    count = (Long)q.uniqueResult();
584    
585                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
586                            }
587                            catch (Exception e) {
588                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
589    
590                                    throw processException(e);
591                            }
592                            finally {
593                                    closeSession(session);
594                            }
595                    }
596    
597                    return count.intValue();
598            }
599    
600            private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiNode.uuid IS NULL";
601            private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiNode.uuid = ?";
602            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiNode.uuid IS NULL OR wikiNode.uuid = '')";
603            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
604                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
605                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
606                            new String[] { String.class.getName(), Long.class.getName() },
607                            WikiNodeModelImpl.UUID_COLUMN_BITMASK |
608                            WikiNodeModelImpl.GROUPID_COLUMN_BITMASK);
609            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
610                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
611                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
612                            new String[] { String.class.getName(), Long.class.getName() });
613    
614            /**
615             * Returns the wiki node where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.wiki.NoSuchNodeException} if it could not be found.
616             *
617             * @param uuid the uuid
618             * @param groupId the group ID
619             * @return the matching wiki node
620             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
621             * @throws SystemException if a system exception occurred
622             */
623            public WikiNode findByUUID_G(String uuid, long groupId)
624                    throws NoSuchNodeException, SystemException {
625                    WikiNode wikiNode = fetchByUUID_G(uuid, groupId);
626    
627                    if (wikiNode == null) {
628                            StringBundler msg = new StringBundler(6);
629    
630                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
631    
632                            msg.append("uuid=");
633                            msg.append(uuid);
634    
635                            msg.append(", groupId=");
636                            msg.append(groupId);
637    
638                            msg.append(StringPool.CLOSE_CURLY_BRACE);
639    
640                            if (_log.isWarnEnabled()) {
641                                    _log.warn(msg.toString());
642                            }
643    
644                            throw new NoSuchNodeException(msg.toString());
645                    }
646    
647                    return wikiNode;
648            }
649    
650            /**
651             * Returns the wiki node where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
652             *
653             * @param uuid the uuid
654             * @param groupId the group ID
655             * @return the matching wiki node, or <code>null</code> if a matching wiki node could not be found
656             * @throws SystemException if a system exception occurred
657             */
658            public WikiNode fetchByUUID_G(String uuid, long groupId)
659                    throws SystemException {
660                    return fetchByUUID_G(uuid, groupId, true);
661            }
662    
663            /**
664             * Returns the wiki node where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
665             *
666             * @param uuid the uuid
667             * @param groupId the group ID
668             * @param retrieveFromCache whether to use the finder cache
669             * @return the matching wiki node, or <code>null</code> if a matching wiki node could not be found
670             * @throws SystemException if a system exception occurred
671             */
672            public WikiNode fetchByUUID_G(String uuid, long groupId,
673                    boolean retrieveFromCache) throws SystemException {
674                    Object[] finderArgs = new Object[] { uuid, groupId };
675    
676                    Object result = null;
677    
678                    if (retrieveFromCache) {
679                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
680                                            finderArgs, this);
681                    }
682    
683                    if (result instanceof WikiNode) {
684                            WikiNode wikiNode = (WikiNode)result;
685    
686                            if (!Validator.equals(uuid, wikiNode.getUuid()) ||
687                                            (groupId != wikiNode.getGroupId())) {
688                                    result = null;
689                            }
690                    }
691    
692                    if (result == null) {
693                            StringBundler query = new StringBundler(4);
694    
695                            query.append(_SQL_SELECT_WIKINODE_WHERE);
696    
697                            boolean bindUuid = false;
698    
699                            if (uuid == null) {
700                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
701                            }
702                            else if (uuid.equals(StringPool.BLANK)) {
703                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
704                            }
705                            else {
706                                    bindUuid = true;
707    
708                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
709                            }
710    
711                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
712    
713                            String sql = query.toString();
714    
715                            Session session = null;
716    
717                            try {
718                                    session = openSession();
719    
720                                    Query q = session.createQuery(sql);
721    
722                                    QueryPos qPos = QueryPos.getInstance(q);
723    
724                                    if (bindUuid) {
725                                            qPos.add(uuid);
726                                    }
727    
728                                    qPos.add(groupId);
729    
730                                    List<WikiNode> list = q.list();
731    
732                                    if (list.isEmpty()) {
733                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
734                                                    finderArgs, list);
735                                    }
736                                    else {
737                                            WikiNode wikiNode = list.get(0);
738    
739                                            result = wikiNode;
740    
741                                            cacheResult(wikiNode);
742    
743                                            if ((wikiNode.getUuid() == null) ||
744                                                            !wikiNode.getUuid().equals(uuid) ||
745                                                            (wikiNode.getGroupId() != groupId)) {
746                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
747                                                            finderArgs, wikiNode);
748                                            }
749                                    }
750                            }
751                            catch (Exception e) {
752                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
753                                            finderArgs);
754    
755                                    throw processException(e);
756                            }
757                            finally {
758                                    closeSession(session);
759                            }
760                    }
761    
762                    if (result instanceof List<?>) {
763                            return null;
764                    }
765                    else {
766                            return (WikiNode)result;
767                    }
768            }
769    
770            /**
771             * Removes the wiki node where uuid = &#63; and groupId = &#63; from the database.
772             *
773             * @param uuid the uuid
774             * @param groupId the group ID
775             * @return the wiki node that was removed
776             * @throws SystemException if a system exception occurred
777             */
778            public WikiNode removeByUUID_G(String uuid, long groupId)
779                    throws NoSuchNodeException, SystemException {
780                    WikiNode wikiNode = findByUUID_G(uuid, groupId);
781    
782                    return remove(wikiNode);
783            }
784    
785            /**
786             * Returns the number of wiki nodes where uuid = &#63; and groupId = &#63;.
787             *
788             * @param uuid the uuid
789             * @param groupId the group ID
790             * @return the number of matching wiki nodes
791             * @throws SystemException if a system exception occurred
792             */
793            public int countByUUID_G(String uuid, long groupId)
794                    throws SystemException {
795                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
796    
797                    Object[] finderArgs = new Object[] { uuid, groupId };
798    
799                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
800                                    this);
801    
802                    if (count == null) {
803                            StringBundler query = new StringBundler(3);
804    
805                            query.append(_SQL_COUNT_WIKINODE_WHERE);
806    
807                            boolean bindUuid = false;
808    
809                            if (uuid == null) {
810                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
811                            }
812                            else if (uuid.equals(StringPool.BLANK)) {
813                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
814                            }
815                            else {
816                                    bindUuid = true;
817    
818                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
819                            }
820    
821                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
822    
823                            String sql = query.toString();
824    
825                            Session session = null;
826    
827                            try {
828                                    session = openSession();
829    
830                                    Query q = session.createQuery(sql);
831    
832                                    QueryPos qPos = QueryPos.getInstance(q);
833    
834                                    if (bindUuid) {
835                                            qPos.add(uuid);
836                                    }
837    
838                                    qPos.add(groupId);
839    
840                                    count = (Long)q.uniqueResult();
841    
842                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
843                            }
844                            catch (Exception e) {
845                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
846    
847                                    throw processException(e);
848                            }
849                            finally {
850                                    closeSession(session);
851                            }
852                    }
853    
854                    return count.intValue();
855            }
856    
857            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "wikiNode.uuid IS NULL AND ";
858            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "wikiNode.uuid = ? AND ";
859            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(wikiNode.uuid IS NULL OR wikiNode.uuid = '') AND ";
860            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "wikiNode.groupId = ?";
861            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
862                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
863                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
864                            new String[] {
865                                    String.class.getName(), Long.class.getName(),
866                                    
867                            Integer.class.getName(), Integer.class.getName(),
868                                    OrderByComparator.class.getName()
869                            });
870            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
871                    new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
872                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
873                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
874                            new String[] { String.class.getName(), Long.class.getName() },
875                            WikiNodeModelImpl.UUID_COLUMN_BITMASK |
876                            WikiNodeModelImpl.COMPANYID_COLUMN_BITMASK |
877                            WikiNodeModelImpl.NAME_COLUMN_BITMASK);
878            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
879                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
880                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
881                            new String[] { String.class.getName(), Long.class.getName() });
882    
883            /**
884             * Returns all the wiki nodes where uuid = &#63; and companyId = &#63;.
885             *
886             * @param uuid the uuid
887             * @param companyId the company ID
888             * @return the matching wiki nodes
889             * @throws SystemException if a system exception occurred
890             */
891            public List<WikiNode> findByUuid_C(String uuid, long companyId)
892                    throws SystemException {
893                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
894                            QueryUtil.ALL_POS, null);
895            }
896    
897            /**
898             * Returns a range of all the wiki nodes where uuid = &#63; and companyId = &#63;.
899             *
900             * <p>
901             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
902             * </p>
903             *
904             * @param uuid the uuid
905             * @param companyId the company ID
906             * @param start the lower bound of the range of wiki nodes
907             * @param end the upper bound of the range of wiki nodes (not inclusive)
908             * @return the range of matching wiki nodes
909             * @throws SystemException if a system exception occurred
910             */
911            public List<WikiNode> findByUuid_C(String uuid, long companyId, int start,
912                    int end) throws SystemException {
913                    return findByUuid_C(uuid, companyId, start, end, null);
914            }
915    
916            /**
917             * Returns an ordered range of all the wiki nodes where uuid = &#63; and companyId = &#63;.
918             *
919             * <p>
920             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
921             * </p>
922             *
923             * @param uuid the uuid
924             * @param companyId the company ID
925             * @param start the lower bound of the range of wiki nodes
926             * @param end the upper bound of the range of wiki nodes (not inclusive)
927             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
928             * @return the ordered range of matching wiki nodes
929             * @throws SystemException if a system exception occurred
930             */
931            public List<WikiNode> findByUuid_C(String uuid, long companyId, int start,
932                    int end, OrderByComparator orderByComparator) throws SystemException {
933                    boolean pagination = true;
934                    FinderPath finderPath = null;
935                    Object[] finderArgs = null;
936    
937                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
938                                    (orderByComparator == null)) {
939                            pagination = false;
940                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
941                            finderArgs = new Object[] { uuid, companyId };
942                    }
943                    else {
944                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
945                            finderArgs = new Object[] {
946                                            uuid, companyId,
947                                            
948                                            start, end, orderByComparator
949                                    };
950                    }
951    
952                    List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
953                                    finderArgs, this);
954    
955                    if ((list != null) && !list.isEmpty()) {
956                            for (WikiNode wikiNode : list) {
957                                    if (!Validator.equals(uuid, wikiNode.getUuid()) ||
958                                                    (companyId != wikiNode.getCompanyId())) {
959                                            list = null;
960    
961                                            break;
962                                    }
963                            }
964                    }
965    
966                    if (list == null) {
967                            StringBundler query = null;
968    
969                            if (orderByComparator != null) {
970                                    query = new StringBundler(4 +
971                                                    (orderByComparator.getOrderByFields().length * 3));
972                            }
973                            else {
974                                    query = new StringBundler(4);
975                            }
976    
977                            query.append(_SQL_SELECT_WIKINODE_WHERE);
978    
979                            boolean bindUuid = false;
980    
981                            if (uuid == null) {
982                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
983                            }
984                            else if (uuid.equals(StringPool.BLANK)) {
985                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
986                            }
987                            else {
988                                    bindUuid = true;
989    
990                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
991                            }
992    
993                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
994    
995                            if (orderByComparator != null) {
996                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
997                                            orderByComparator);
998                            }
999                            else
1000                             if (pagination) {
1001                                    query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1002                            }
1003    
1004                            String sql = query.toString();
1005    
1006                            Session session = null;
1007    
1008                            try {
1009                                    session = openSession();
1010    
1011                                    Query q = session.createQuery(sql);
1012    
1013                                    QueryPos qPos = QueryPos.getInstance(q);
1014    
1015                                    if (bindUuid) {
1016                                            qPos.add(uuid);
1017                                    }
1018    
1019                                    qPos.add(companyId);
1020    
1021                                    if (!pagination) {
1022                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
1023                                                            start, end, false);
1024    
1025                                            Collections.sort(list);
1026    
1027                                            list = new UnmodifiableList<WikiNode>(list);
1028                                    }
1029                                    else {
1030                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
1031                                                            start, end);
1032                                    }
1033    
1034                                    cacheResult(list);
1035    
1036                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1037                            }
1038                            catch (Exception e) {
1039                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1040    
1041                                    throw processException(e);
1042                            }
1043                            finally {
1044                                    closeSession(session);
1045                            }
1046                    }
1047    
1048                    return list;
1049            }
1050    
1051            /**
1052             * Returns the first wiki node in the ordered set where uuid = &#63; and companyId = &#63;.
1053             *
1054             * @param uuid the uuid
1055             * @param companyId the company ID
1056             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1057             * @return the first matching wiki node
1058             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
1059             * @throws SystemException if a system exception occurred
1060             */
1061            public WikiNode findByUuid_C_First(String uuid, long companyId,
1062                    OrderByComparator orderByComparator)
1063                    throws NoSuchNodeException, SystemException {
1064                    WikiNode wikiNode = fetchByUuid_C_First(uuid, companyId,
1065                                    orderByComparator);
1066    
1067                    if (wikiNode != null) {
1068                            return wikiNode;
1069                    }
1070    
1071                    StringBundler msg = new StringBundler(6);
1072    
1073                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1074    
1075                    msg.append("uuid=");
1076                    msg.append(uuid);
1077    
1078                    msg.append(", companyId=");
1079                    msg.append(companyId);
1080    
1081                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1082    
1083                    throw new NoSuchNodeException(msg.toString());
1084            }
1085    
1086            /**
1087             * Returns the first wiki node in the ordered set where uuid = &#63; and companyId = &#63;.
1088             *
1089             * @param uuid the uuid
1090             * @param companyId the company ID
1091             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1092             * @return the first matching wiki node, or <code>null</code> if a matching wiki node could not be found
1093             * @throws SystemException if a system exception occurred
1094             */
1095            public WikiNode fetchByUuid_C_First(String uuid, long companyId,
1096                    OrderByComparator orderByComparator) throws SystemException {
1097                    List<WikiNode> list = findByUuid_C(uuid, companyId, 0, 1,
1098                                    orderByComparator);
1099    
1100                    if (!list.isEmpty()) {
1101                            return list.get(0);
1102                    }
1103    
1104                    return null;
1105            }
1106    
1107            /**
1108             * Returns the last wiki node in the ordered set where uuid = &#63; and companyId = &#63;.
1109             *
1110             * @param uuid the uuid
1111             * @param companyId the company ID
1112             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1113             * @return the last matching wiki node
1114             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
1115             * @throws SystemException if a system exception occurred
1116             */
1117            public WikiNode findByUuid_C_Last(String uuid, long companyId,
1118                    OrderByComparator orderByComparator)
1119                    throws NoSuchNodeException, SystemException {
1120                    WikiNode wikiNode = fetchByUuid_C_Last(uuid, companyId,
1121                                    orderByComparator);
1122    
1123                    if (wikiNode != null) {
1124                            return wikiNode;
1125                    }
1126    
1127                    StringBundler msg = new StringBundler(6);
1128    
1129                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1130    
1131                    msg.append("uuid=");
1132                    msg.append(uuid);
1133    
1134                    msg.append(", companyId=");
1135                    msg.append(companyId);
1136    
1137                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1138    
1139                    throw new NoSuchNodeException(msg.toString());
1140            }
1141    
1142            /**
1143             * Returns the last wiki node 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 node, or <code>null</code> if a matching wiki node could not be found
1149             * @throws SystemException if a system exception occurred
1150             */
1151            public WikiNode fetchByUuid_C_Last(String uuid, long companyId,
1152                    OrderByComparator orderByComparator) throws SystemException {
1153                    int count = countByUuid_C(uuid, companyId);
1154    
1155                    List<WikiNode> list = findByUuid_C(uuid, companyId, count - 1, count,
1156                                    orderByComparator);
1157    
1158                    if (!list.isEmpty()) {
1159                            return list.get(0);
1160                    }
1161    
1162                    return null;
1163            }
1164    
1165            /**
1166             * Returns the wiki nodes before and after the current wiki node in the ordered set where uuid = &#63; and companyId = &#63;.
1167             *
1168             * @param nodeId the primary key of the current wiki node
1169             * @param uuid the uuid
1170             * @param companyId the company ID
1171             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1172             * @return the previous, current, and next wiki node
1173             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
1174             * @throws SystemException if a system exception occurred
1175             */
1176            public WikiNode[] findByUuid_C_PrevAndNext(long nodeId, String uuid,
1177                    long companyId, OrderByComparator orderByComparator)
1178                    throws NoSuchNodeException, SystemException {
1179                    WikiNode wikiNode = findByPrimaryKey(nodeId);
1180    
1181                    Session session = null;
1182    
1183                    try {
1184                            session = openSession();
1185    
1186                            WikiNode[] array = new WikiNodeImpl[3];
1187    
1188                            array[0] = getByUuid_C_PrevAndNext(session, wikiNode, uuid,
1189                                            companyId, orderByComparator, true);
1190    
1191                            array[1] = wikiNode;
1192    
1193                            array[2] = getByUuid_C_PrevAndNext(session, wikiNode, uuid,
1194                                            companyId, orderByComparator, false);
1195    
1196                            return array;
1197                    }
1198                    catch (Exception e) {
1199                            throw processException(e);
1200                    }
1201                    finally {
1202                            closeSession(session);
1203                    }
1204            }
1205    
1206            protected WikiNode getByUuid_C_PrevAndNext(Session session,
1207                    WikiNode wikiNode, String uuid, long companyId,
1208                    OrderByComparator orderByComparator, boolean previous) {
1209                    StringBundler query = null;
1210    
1211                    if (orderByComparator != null) {
1212                            query = new StringBundler(6 +
1213                                            (orderByComparator.getOrderByFields().length * 6));
1214                    }
1215                    else {
1216                            query = new StringBundler(3);
1217                    }
1218    
1219                    query.append(_SQL_SELECT_WIKINODE_WHERE);
1220    
1221                    boolean bindUuid = false;
1222    
1223                    if (uuid == null) {
1224                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1225                    }
1226                    else if (uuid.equals(StringPool.BLANK)) {
1227                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1228                    }
1229                    else {
1230                            bindUuid = true;
1231    
1232                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1233                    }
1234    
1235                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1236    
1237                    if (orderByComparator != null) {
1238                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1239    
1240                            if (orderByConditionFields.length > 0) {
1241                                    query.append(WHERE_AND);
1242                            }
1243    
1244                            for (int i = 0; i < orderByConditionFields.length; i++) {
1245                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1246                                    query.append(orderByConditionFields[i]);
1247    
1248                                    if ((i + 1) < orderByConditionFields.length) {
1249                                            if (orderByComparator.isAscending() ^ previous) {
1250                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1251                                            }
1252                                            else {
1253                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1254                                            }
1255                                    }
1256                                    else {
1257                                            if (orderByComparator.isAscending() ^ previous) {
1258                                                    query.append(WHERE_GREATER_THAN);
1259                                            }
1260                                            else {
1261                                                    query.append(WHERE_LESSER_THAN);
1262                                            }
1263                                    }
1264                            }
1265    
1266                            query.append(ORDER_BY_CLAUSE);
1267    
1268                            String[] orderByFields = orderByComparator.getOrderByFields();
1269    
1270                            for (int i = 0; i < orderByFields.length; i++) {
1271                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1272                                    query.append(orderByFields[i]);
1273    
1274                                    if ((i + 1) < orderByFields.length) {
1275                                            if (orderByComparator.isAscending() ^ previous) {
1276                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1277                                            }
1278                                            else {
1279                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1280                                            }
1281                                    }
1282                                    else {
1283                                            if (orderByComparator.isAscending() ^ previous) {
1284                                                    query.append(ORDER_BY_ASC);
1285                                            }
1286                                            else {
1287                                                    query.append(ORDER_BY_DESC);
1288                                            }
1289                                    }
1290                            }
1291                    }
1292                    else {
1293                            query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1294                    }
1295    
1296                    String sql = query.toString();
1297    
1298                    Query q = session.createQuery(sql);
1299    
1300                    q.setFirstResult(0);
1301                    q.setMaxResults(2);
1302    
1303                    QueryPos qPos = QueryPos.getInstance(q);
1304    
1305                    if (bindUuid) {
1306                            qPos.add(uuid);
1307                    }
1308    
1309                    qPos.add(companyId);
1310    
1311                    if (orderByComparator != null) {
1312                            Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
1313    
1314                            for (Object value : values) {
1315                                    qPos.add(value);
1316                            }
1317                    }
1318    
1319                    List<WikiNode> list = q.list();
1320    
1321                    if (list.size() == 2) {
1322                            return list.get(1);
1323                    }
1324                    else {
1325                            return null;
1326                    }
1327            }
1328    
1329            /**
1330             * Removes all the wiki nodes where uuid = &#63; and companyId = &#63; from the database.
1331             *
1332             * @param uuid the uuid
1333             * @param companyId the company ID
1334             * @throws SystemException if a system exception occurred
1335             */
1336            public void removeByUuid_C(String uuid, long companyId)
1337                    throws SystemException {
1338                    for (WikiNode wikiNode : findByUuid_C(uuid, companyId,
1339                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1340                            remove(wikiNode);
1341                    }
1342            }
1343    
1344            /**
1345             * Returns the number of wiki nodes where uuid = &#63; and companyId = &#63;.
1346             *
1347             * @param uuid the uuid
1348             * @param companyId the company ID
1349             * @return the number of matching wiki nodes
1350             * @throws SystemException if a system exception occurred
1351             */
1352            public int countByUuid_C(String uuid, long companyId)
1353                    throws SystemException {
1354                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1355    
1356                    Object[] finderArgs = new Object[] { uuid, companyId };
1357    
1358                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1359                                    this);
1360    
1361                    if (count == null) {
1362                            StringBundler query = new StringBundler(3);
1363    
1364                            query.append(_SQL_COUNT_WIKINODE_WHERE);
1365    
1366                            boolean bindUuid = false;
1367    
1368                            if (uuid == null) {
1369                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1370                            }
1371                            else if (uuid.equals(StringPool.BLANK)) {
1372                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1373                            }
1374                            else {
1375                                    bindUuid = true;
1376    
1377                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1378                            }
1379    
1380                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1381    
1382                            String sql = query.toString();
1383    
1384                            Session session = null;
1385    
1386                            try {
1387                                    session = openSession();
1388    
1389                                    Query q = session.createQuery(sql);
1390    
1391                                    QueryPos qPos = QueryPos.getInstance(q);
1392    
1393                                    if (bindUuid) {
1394                                            qPos.add(uuid);
1395                                    }
1396    
1397                                    qPos.add(companyId);
1398    
1399                                    count = (Long)q.uniqueResult();
1400    
1401                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1402                            }
1403                            catch (Exception e) {
1404                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1405    
1406                                    throw processException(e);
1407                            }
1408                            finally {
1409                                    closeSession(session);
1410                            }
1411                    }
1412    
1413                    return count.intValue();
1414            }
1415    
1416            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "wikiNode.uuid IS NULL AND ";
1417            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "wikiNode.uuid = ? AND ";
1418            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(wikiNode.uuid IS NULL OR wikiNode.uuid = '') AND ";
1419            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "wikiNode.companyId = ?";
1420            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
1421                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
1422                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1423                            new String[] {
1424                                    Long.class.getName(),
1425                                    
1426                            Integer.class.getName(), Integer.class.getName(),
1427                                    OrderByComparator.class.getName()
1428                            });
1429            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1430                    new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
1431                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
1432                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1433                            new String[] { Long.class.getName() },
1434                            WikiNodeModelImpl.GROUPID_COLUMN_BITMASK |
1435                            WikiNodeModelImpl.NAME_COLUMN_BITMASK);
1436            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
1437                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
1438                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1439                            new String[] { Long.class.getName() });
1440    
1441            /**
1442             * Returns all the wiki nodes where groupId = &#63;.
1443             *
1444             * @param groupId the group ID
1445             * @return the matching wiki nodes
1446             * @throws SystemException if a system exception occurred
1447             */
1448            public List<WikiNode> findByGroupId(long groupId) throws SystemException {
1449                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1450            }
1451    
1452            /**
1453             * Returns a range of all the wiki nodes where groupId = &#63;.
1454             *
1455             * <p>
1456             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1457             * </p>
1458             *
1459             * @param groupId the group ID
1460             * @param start the lower bound of the range of wiki nodes
1461             * @param end the upper bound of the range of wiki nodes (not inclusive)
1462             * @return the range of matching wiki nodes
1463             * @throws SystemException if a system exception occurred
1464             */
1465            public List<WikiNode> findByGroupId(long groupId, int start, int end)
1466                    throws SystemException {
1467                    return findByGroupId(groupId, start, end, null);
1468            }
1469    
1470            /**
1471             * Returns an ordered range of all the wiki nodes where groupId = &#63;.
1472             *
1473             * <p>
1474             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1475             * </p>
1476             *
1477             * @param groupId the group ID
1478             * @param start the lower bound of the range of wiki nodes
1479             * @param end the upper bound of the range of wiki nodes (not inclusive)
1480             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1481             * @return the ordered range of matching wiki nodes
1482             * @throws SystemException if a system exception occurred
1483             */
1484            public List<WikiNode> findByGroupId(long groupId, int start, int end,
1485                    OrderByComparator orderByComparator) throws SystemException {
1486                    boolean pagination = true;
1487                    FinderPath finderPath = null;
1488                    Object[] finderArgs = null;
1489    
1490                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1491                                    (orderByComparator == null)) {
1492                            pagination = false;
1493                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1494                            finderArgs = new Object[] { groupId };
1495                    }
1496                    else {
1497                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1498                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1499                    }
1500    
1501                    List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
1502                                    finderArgs, this);
1503    
1504                    if ((list != null) && !list.isEmpty()) {
1505                            for (WikiNode wikiNode : list) {
1506                                    if ((groupId != wikiNode.getGroupId())) {
1507                                            list = null;
1508    
1509                                            break;
1510                                    }
1511                            }
1512                    }
1513    
1514                    if (list == null) {
1515                            StringBundler query = null;
1516    
1517                            if (orderByComparator != null) {
1518                                    query = new StringBundler(3 +
1519                                                    (orderByComparator.getOrderByFields().length * 3));
1520                            }
1521                            else {
1522                                    query = new StringBundler(3);
1523                            }
1524    
1525                            query.append(_SQL_SELECT_WIKINODE_WHERE);
1526    
1527                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1528    
1529                            if (orderByComparator != null) {
1530                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1531                                            orderByComparator);
1532                            }
1533                            else
1534                             if (pagination) {
1535                                    query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1536                            }
1537    
1538                            String sql = query.toString();
1539    
1540                            Session session = null;
1541    
1542                            try {
1543                                    session = openSession();
1544    
1545                                    Query q = session.createQuery(sql);
1546    
1547                                    QueryPos qPos = QueryPos.getInstance(q);
1548    
1549                                    qPos.add(groupId);
1550    
1551                                    if (!pagination) {
1552                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
1553                                                            start, end, false);
1554    
1555                                            Collections.sort(list);
1556    
1557                                            list = new UnmodifiableList<WikiNode>(list);
1558                                    }
1559                                    else {
1560                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
1561                                                            start, end);
1562                                    }
1563    
1564                                    cacheResult(list);
1565    
1566                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1567                            }
1568                            catch (Exception e) {
1569                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1570    
1571                                    throw processException(e);
1572                            }
1573                            finally {
1574                                    closeSession(session);
1575                            }
1576                    }
1577    
1578                    return list;
1579            }
1580    
1581            /**
1582             * Returns the first wiki node in the ordered set where groupId = &#63;.
1583             *
1584             * @param groupId the group ID
1585             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1586             * @return the first matching wiki node
1587             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
1588             * @throws SystemException if a system exception occurred
1589             */
1590            public WikiNode findByGroupId_First(long groupId,
1591                    OrderByComparator orderByComparator)
1592                    throws NoSuchNodeException, SystemException {
1593                    WikiNode wikiNode = fetchByGroupId_First(groupId, orderByComparator);
1594    
1595                    if (wikiNode != null) {
1596                            return wikiNode;
1597                    }
1598    
1599                    StringBundler msg = new StringBundler(4);
1600    
1601                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1602    
1603                    msg.append("groupId=");
1604                    msg.append(groupId);
1605    
1606                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1607    
1608                    throw new NoSuchNodeException(msg.toString());
1609            }
1610    
1611            /**
1612             * Returns the first wiki node in the ordered set where groupId = &#63;.
1613             *
1614             * @param groupId the group ID
1615             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1616             * @return the first matching wiki node, or <code>null</code> if a matching wiki node could not be found
1617             * @throws SystemException if a system exception occurred
1618             */
1619            public WikiNode fetchByGroupId_First(long groupId,
1620                    OrderByComparator orderByComparator) throws SystemException {
1621                    List<WikiNode> list = findByGroupId(groupId, 0, 1, orderByComparator);
1622    
1623                    if (!list.isEmpty()) {
1624                            return list.get(0);
1625                    }
1626    
1627                    return null;
1628            }
1629    
1630            /**
1631             * Returns the last wiki node in the ordered set where groupId = &#63;.
1632             *
1633             * @param groupId the group ID
1634             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1635             * @return the last matching wiki node
1636             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
1637             * @throws SystemException if a system exception occurred
1638             */
1639            public WikiNode findByGroupId_Last(long groupId,
1640                    OrderByComparator orderByComparator)
1641                    throws NoSuchNodeException, SystemException {
1642                    WikiNode wikiNode = fetchByGroupId_Last(groupId, orderByComparator);
1643    
1644                    if (wikiNode != null) {
1645                            return wikiNode;
1646                    }
1647    
1648                    StringBundler msg = new StringBundler(4);
1649    
1650                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1651    
1652                    msg.append("groupId=");
1653                    msg.append(groupId);
1654    
1655                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1656    
1657                    throw new NoSuchNodeException(msg.toString());
1658            }
1659    
1660            /**
1661             * Returns the last wiki node in the ordered set where groupId = &#63;.
1662             *
1663             * @param groupId the group ID
1664             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1665             * @return the last matching wiki node, or <code>null</code> if a matching wiki node could not be found
1666             * @throws SystemException if a system exception occurred
1667             */
1668            public WikiNode fetchByGroupId_Last(long groupId,
1669                    OrderByComparator orderByComparator) throws SystemException {
1670                    int count = countByGroupId(groupId);
1671    
1672                    List<WikiNode> list = findByGroupId(groupId, count - 1, count,
1673                                    orderByComparator);
1674    
1675                    if (!list.isEmpty()) {
1676                            return list.get(0);
1677                    }
1678    
1679                    return null;
1680            }
1681    
1682            /**
1683             * Returns the wiki nodes before and after the current wiki node in the ordered set where groupId = &#63;.
1684             *
1685             * @param nodeId the primary key of the current wiki node
1686             * @param groupId the group ID
1687             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1688             * @return the previous, current, and next wiki node
1689             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
1690             * @throws SystemException if a system exception occurred
1691             */
1692            public WikiNode[] findByGroupId_PrevAndNext(long nodeId, long groupId,
1693                    OrderByComparator orderByComparator)
1694                    throws NoSuchNodeException, SystemException {
1695                    WikiNode wikiNode = findByPrimaryKey(nodeId);
1696    
1697                    Session session = null;
1698    
1699                    try {
1700                            session = openSession();
1701    
1702                            WikiNode[] array = new WikiNodeImpl[3];
1703    
1704                            array[0] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
1705                                            orderByComparator, true);
1706    
1707                            array[1] = wikiNode;
1708    
1709                            array[2] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
1710                                            orderByComparator, false);
1711    
1712                            return array;
1713                    }
1714                    catch (Exception e) {
1715                            throw processException(e);
1716                    }
1717                    finally {
1718                            closeSession(session);
1719                    }
1720            }
1721    
1722            protected WikiNode getByGroupId_PrevAndNext(Session session,
1723                    WikiNode wikiNode, long groupId, OrderByComparator orderByComparator,
1724                    boolean previous) {
1725                    StringBundler query = null;
1726    
1727                    if (orderByComparator != null) {
1728                            query = new StringBundler(6 +
1729                                            (orderByComparator.getOrderByFields().length * 6));
1730                    }
1731                    else {
1732                            query = new StringBundler(3);
1733                    }
1734    
1735                    query.append(_SQL_SELECT_WIKINODE_WHERE);
1736    
1737                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1738    
1739                    if (orderByComparator != null) {
1740                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1741    
1742                            if (orderByConditionFields.length > 0) {
1743                                    query.append(WHERE_AND);
1744                            }
1745    
1746                            for (int i = 0; i < orderByConditionFields.length; i++) {
1747                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1748                                    query.append(orderByConditionFields[i]);
1749    
1750                                    if ((i + 1) < orderByConditionFields.length) {
1751                                            if (orderByComparator.isAscending() ^ previous) {
1752                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1753                                            }
1754                                            else {
1755                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1756                                            }
1757                                    }
1758                                    else {
1759                                            if (orderByComparator.isAscending() ^ previous) {
1760                                                    query.append(WHERE_GREATER_THAN);
1761                                            }
1762                                            else {
1763                                                    query.append(WHERE_LESSER_THAN);
1764                                            }
1765                                    }
1766                            }
1767    
1768                            query.append(ORDER_BY_CLAUSE);
1769    
1770                            String[] orderByFields = orderByComparator.getOrderByFields();
1771    
1772                            for (int i = 0; i < orderByFields.length; i++) {
1773                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1774                                    query.append(orderByFields[i]);
1775    
1776                                    if ((i + 1) < orderByFields.length) {
1777                                            if (orderByComparator.isAscending() ^ previous) {
1778                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1779                                            }
1780                                            else {
1781                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1782                                            }
1783                                    }
1784                                    else {
1785                                            if (orderByComparator.isAscending() ^ previous) {
1786                                                    query.append(ORDER_BY_ASC);
1787                                            }
1788                                            else {
1789                                                    query.append(ORDER_BY_DESC);
1790                                            }
1791                                    }
1792                            }
1793                    }
1794                    else {
1795                            query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1796                    }
1797    
1798                    String sql = query.toString();
1799    
1800                    Query q = session.createQuery(sql);
1801    
1802                    q.setFirstResult(0);
1803                    q.setMaxResults(2);
1804    
1805                    QueryPos qPos = QueryPos.getInstance(q);
1806    
1807                    qPos.add(groupId);
1808    
1809                    if (orderByComparator != null) {
1810                            Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
1811    
1812                            for (Object value : values) {
1813                                    qPos.add(value);
1814                            }
1815                    }
1816    
1817                    List<WikiNode> list = q.list();
1818    
1819                    if (list.size() == 2) {
1820                            return list.get(1);
1821                    }
1822                    else {
1823                            return null;
1824                    }
1825            }
1826    
1827            /**
1828             * Returns all the wiki nodes that the user has permission to view where groupId = &#63;.
1829             *
1830             * @param groupId the group ID
1831             * @return the matching wiki nodes that the user has permission to view
1832             * @throws SystemException if a system exception occurred
1833             */
1834            public List<WikiNode> filterFindByGroupId(long groupId)
1835                    throws SystemException {
1836                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1837                            QueryUtil.ALL_POS, null);
1838            }
1839    
1840            /**
1841             * Returns a range of all the wiki nodes that the user has permission to view where groupId = &#63;.
1842             *
1843             * <p>
1844             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1845             * </p>
1846             *
1847             * @param groupId the group ID
1848             * @param start the lower bound of the range of wiki nodes
1849             * @param end the upper bound of the range of wiki nodes (not inclusive)
1850             * @return the range of matching wiki nodes that the user has permission to view
1851             * @throws SystemException if a system exception occurred
1852             */
1853            public List<WikiNode> filterFindByGroupId(long groupId, int start, int end)
1854                    throws SystemException {
1855                    return filterFindByGroupId(groupId, start, end, null);
1856            }
1857    
1858            /**
1859             * Returns an ordered range of all the wiki nodes that the user has permissions to view where groupId = &#63;.
1860             *
1861             * <p>
1862             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1863             * </p>
1864             *
1865             * @param groupId the group ID
1866             * @param start the lower bound of the range of wiki nodes
1867             * @param end the upper bound of the range of wiki nodes (not inclusive)
1868             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1869             * @return the ordered range of matching wiki nodes that the user has permission to view
1870             * @throws SystemException if a system exception occurred
1871             */
1872            public List<WikiNode> filterFindByGroupId(long groupId, int start, int end,
1873                    OrderByComparator orderByComparator) throws SystemException {
1874                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1875                            return findByGroupId(groupId, start, end, orderByComparator);
1876                    }
1877    
1878                    StringBundler query = null;
1879    
1880                    if (orderByComparator != null) {
1881                            query = new StringBundler(3 +
1882                                            (orderByComparator.getOrderByFields().length * 3));
1883                    }
1884                    else {
1885                            query = new StringBundler(3);
1886                    }
1887    
1888                    if (getDB().isSupportsInlineDistinct()) {
1889                            query.append(_FILTER_SQL_SELECT_WIKINODE_WHERE);
1890                    }
1891                    else {
1892                            query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_1);
1893                    }
1894    
1895                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1896    
1897                    if (!getDB().isSupportsInlineDistinct()) {
1898                            query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_2);
1899                    }
1900    
1901                    if (orderByComparator != null) {
1902                            if (getDB().isSupportsInlineDistinct()) {
1903                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1904                                            orderByComparator);
1905                            }
1906                            else {
1907                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1908                                            orderByComparator);
1909                            }
1910                    }
1911                    else {
1912                            if (getDB().isSupportsInlineDistinct()) {
1913                                    query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1914                            }
1915                            else {
1916                                    query.append(WikiNodeModelImpl.ORDER_BY_SQL);
1917                            }
1918                    }
1919    
1920                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1921                                    WikiNode.class.getName(),
1922                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1923    
1924                    Session session = null;
1925    
1926                    try {
1927                            session = openSession();
1928    
1929                            SQLQuery q = session.createSQLQuery(sql);
1930    
1931                            if (getDB().isSupportsInlineDistinct()) {
1932                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiNodeImpl.class);
1933                            }
1934                            else {
1935                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiNodeImpl.class);
1936                            }
1937    
1938                            QueryPos qPos = QueryPos.getInstance(q);
1939    
1940                            qPos.add(groupId);
1941    
1942                            return (List<WikiNode>)QueryUtil.list(q, getDialect(), start, end);
1943                    }
1944                    catch (Exception e) {
1945                            throw processException(e);
1946                    }
1947                    finally {
1948                            closeSession(session);
1949                    }
1950            }
1951    
1952            /**
1953             * Returns the wiki nodes before and after the current wiki node in the ordered set of wiki nodes that the user has permission to view where groupId = &#63;.
1954             *
1955             * @param nodeId the primary key of the current wiki node
1956             * @param groupId the group ID
1957             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1958             * @return the previous, current, and next wiki node
1959             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
1960             * @throws SystemException if a system exception occurred
1961             */
1962            public WikiNode[] filterFindByGroupId_PrevAndNext(long nodeId,
1963                    long groupId, OrderByComparator orderByComparator)
1964                    throws NoSuchNodeException, SystemException {
1965                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1966                            return findByGroupId_PrevAndNext(nodeId, groupId, orderByComparator);
1967                    }
1968    
1969                    WikiNode wikiNode = findByPrimaryKey(nodeId);
1970    
1971                    Session session = null;
1972    
1973                    try {
1974                            session = openSession();
1975    
1976                            WikiNode[] array = new WikiNodeImpl[3];
1977    
1978                            array[0] = filterGetByGroupId_PrevAndNext(session, wikiNode,
1979                                            groupId, orderByComparator, true);
1980    
1981                            array[1] = wikiNode;
1982    
1983                            array[2] = filterGetByGroupId_PrevAndNext(session, wikiNode,
1984                                            groupId, orderByComparator, false);
1985    
1986                            return array;
1987                    }
1988                    catch (Exception e) {
1989                            throw processException(e);
1990                    }
1991                    finally {
1992                            closeSession(session);
1993                    }
1994            }
1995    
1996            protected WikiNode filterGetByGroupId_PrevAndNext(Session session,
1997                    WikiNode wikiNode, long groupId, OrderByComparator orderByComparator,
1998                    boolean previous) {
1999                    StringBundler query = null;
2000    
2001                    if (orderByComparator != null) {
2002                            query = new StringBundler(6 +
2003                                            (orderByComparator.getOrderByFields().length * 6));
2004                    }
2005                    else {
2006                            query = new StringBundler(3);
2007                    }
2008    
2009                    if (getDB().isSupportsInlineDistinct()) {
2010                            query.append(_FILTER_SQL_SELECT_WIKINODE_WHERE);
2011                    }
2012                    else {
2013                            query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_1);
2014                    }
2015    
2016                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2017    
2018                    if (!getDB().isSupportsInlineDistinct()) {
2019                            query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_2);
2020                    }
2021    
2022                    if (orderByComparator != null) {
2023                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2024    
2025                            if (orderByConditionFields.length > 0) {
2026                                    query.append(WHERE_AND);
2027                            }
2028    
2029                            for (int i = 0; i < orderByConditionFields.length; i++) {
2030                                    if (getDB().isSupportsInlineDistinct()) {
2031                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2032                                    }
2033                                    else {
2034                                            query.append(_ORDER_BY_ENTITY_TABLE);
2035                                    }
2036    
2037                                    query.append(orderByConditionFields[i]);
2038    
2039                                    if ((i + 1) < orderByConditionFields.length) {
2040                                            if (orderByComparator.isAscending() ^ previous) {
2041                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2042                                            }
2043                                            else {
2044                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2045                                            }
2046                                    }
2047                                    else {
2048                                            if (orderByComparator.isAscending() ^ previous) {
2049                                                    query.append(WHERE_GREATER_THAN);
2050                                            }
2051                                            else {
2052                                                    query.append(WHERE_LESSER_THAN);
2053                                            }
2054                                    }
2055                            }
2056    
2057                            query.append(ORDER_BY_CLAUSE);
2058    
2059                            String[] orderByFields = orderByComparator.getOrderByFields();
2060    
2061                            for (int i = 0; i < orderByFields.length; i++) {
2062                                    if (getDB().isSupportsInlineDistinct()) {
2063                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2064                                    }
2065                                    else {
2066                                            query.append(_ORDER_BY_ENTITY_TABLE);
2067                                    }
2068    
2069                                    query.append(orderByFields[i]);
2070    
2071                                    if ((i + 1) < orderByFields.length) {
2072                                            if (orderByComparator.isAscending() ^ previous) {
2073                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2074                                            }
2075                                            else {
2076                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2077                                            }
2078                                    }
2079                                    else {
2080                                            if (orderByComparator.isAscending() ^ previous) {
2081                                                    query.append(ORDER_BY_ASC);
2082                                            }
2083                                            else {
2084                                                    query.append(ORDER_BY_DESC);
2085                                            }
2086                                    }
2087                            }
2088                    }
2089                    else {
2090                            if (getDB().isSupportsInlineDistinct()) {
2091                                    query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
2092                            }
2093                            else {
2094                                    query.append(WikiNodeModelImpl.ORDER_BY_SQL);
2095                            }
2096                    }
2097    
2098                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2099                                    WikiNode.class.getName(),
2100                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2101    
2102                    SQLQuery q = session.createSQLQuery(sql);
2103    
2104                    q.setFirstResult(0);
2105                    q.setMaxResults(2);
2106    
2107                    if (getDB().isSupportsInlineDistinct()) {
2108                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiNodeImpl.class);
2109                    }
2110                    else {
2111                            q.addEntity(_FILTER_ENTITY_TABLE, WikiNodeImpl.class);
2112                    }
2113    
2114                    QueryPos qPos = QueryPos.getInstance(q);
2115    
2116                    qPos.add(groupId);
2117    
2118                    if (orderByComparator != null) {
2119                            Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
2120    
2121                            for (Object value : values) {
2122                                    qPos.add(value);
2123                            }
2124                    }
2125    
2126                    List<WikiNode> list = q.list();
2127    
2128                    if (list.size() == 2) {
2129                            return list.get(1);
2130                    }
2131                    else {
2132                            return null;
2133                    }
2134            }
2135    
2136            /**
2137             * Removes all the wiki nodes where groupId = &#63; from the database.
2138             *
2139             * @param groupId the group ID
2140             * @throws SystemException if a system exception occurred
2141             */
2142            public void removeByGroupId(long groupId) throws SystemException {
2143                    for (WikiNode wikiNode : findByGroupId(groupId, QueryUtil.ALL_POS,
2144                                    QueryUtil.ALL_POS, null)) {
2145                            remove(wikiNode);
2146                    }
2147            }
2148    
2149            /**
2150             * Returns the number of wiki nodes where groupId = &#63;.
2151             *
2152             * @param groupId the group ID
2153             * @return the number of matching wiki nodes
2154             * @throws SystemException if a system exception occurred
2155             */
2156            public int countByGroupId(long groupId) throws SystemException {
2157                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2158    
2159                    Object[] finderArgs = new Object[] { groupId };
2160    
2161                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2162                                    this);
2163    
2164                    if (count == null) {
2165                            StringBundler query = new StringBundler(2);
2166    
2167                            query.append(_SQL_COUNT_WIKINODE_WHERE);
2168    
2169                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2170    
2171                            String sql = query.toString();
2172    
2173                            Session session = null;
2174    
2175                            try {
2176                                    session = openSession();
2177    
2178                                    Query q = session.createQuery(sql);
2179    
2180                                    QueryPos qPos = QueryPos.getInstance(q);
2181    
2182                                    qPos.add(groupId);
2183    
2184                                    count = (Long)q.uniqueResult();
2185    
2186                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2187                            }
2188                            catch (Exception e) {
2189                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2190    
2191                                    throw processException(e);
2192                            }
2193                            finally {
2194                                    closeSession(session);
2195                            }
2196                    }
2197    
2198                    return count.intValue();
2199            }
2200    
2201            /**
2202             * Returns the number of wiki nodes that the user has permission to view where groupId = &#63;.
2203             *
2204             * @param groupId the group ID
2205             * @return the number of matching wiki nodes that the user has permission to view
2206             * @throws SystemException if a system exception occurred
2207             */
2208            public int filterCountByGroupId(long groupId) throws SystemException {
2209                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2210                            return countByGroupId(groupId);
2211                    }
2212    
2213                    StringBundler query = new StringBundler(2);
2214    
2215                    query.append(_FILTER_SQL_COUNT_WIKINODE_WHERE);
2216    
2217                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2218    
2219                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2220                                    WikiNode.class.getName(),
2221                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2222    
2223                    Session session = null;
2224    
2225                    try {
2226                            session = openSession();
2227    
2228                            SQLQuery q = session.createSQLQuery(sql);
2229    
2230                            q.addScalar(COUNT_COLUMN_NAME,
2231                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2232    
2233                            QueryPos qPos = QueryPos.getInstance(q);
2234    
2235                            qPos.add(groupId);
2236    
2237                            Long count = (Long)q.uniqueResult();
2238    
2239                            return count.intValue();
2240                    }
2241                    catch (Exception e) {
2242                            throw processException(e);
2243                    }
2244                    finally {
2245                            closeSession(session);
2246                    }
2247            }
2248    
2249            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "wikiNode.groupId = ?";
2250            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2251                    new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
2252                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
2253                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2254                            new String[] {
2255                                    Long.class.getName(),
2256                                    
2257                            Integer.class.getName(), Integer.class.getName(),
2258                                    OrderByComparator.class.getName()
2259                            });
2260            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2261                    new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
2262                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
2263                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2264                            new String[] { Long.class.getName() },
2265                            WikiNodeModelImpl.COMPANYID_COLUMN_BITMASK |
2266                            WikiNodeModelImpl.NAME_COLUMN_BITMASK);
2267            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
2268                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
2269                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2270                            new String[] { Long.class.getName() });
2271    
2272            /**
2273             * Returns all the wiki nodes where companyId = &#63;.
2274             *
2275             * @param companyId the company ID
2276             * @return the matching wiki nodes
2277             * @throws SystemException if a system exception occurred
2278             */
2279            public List<WikiNode> findByCompanyId(long companyId)
2280                    throws SystemException {
2281                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2282                            null);
2283            }
2284    
2285            /**
2286             * Returns a range of all the wiki nodes where companyId = &#63;.
2287             *
2288             * <p>
2289             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2290             * </p>
2291             *
2292             * @param companyId the company ID
2293             * @param start the lower bound of the range of wiki nodes
2294             * @param end the upper bound of the range of wiki nodes (not inclusive)
2295             * @return the range of matching wiki nodes
2296             * @throws SystemException if a system exception occurred
2297             */
2298            public List<WikiNode> findByCompanyId(long companyId, int start, int end)
2299                    throws SystemException {
2300                    return findByCompanyId(companyId, start, end, null);
2301            }
2302    
2303            /**
2304             * Returns an ordered range of all the wiki nodes where companyId = &#63;.
2305             *
2306             * <p>
2307             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2308             * </p>
2309             *
2310             * @param companyId the company ID
2311             * @param start the lower bound of the range of wiki nodes
2312             * @param end the upper bound of the range of wiki nodes (not inclusive)
2313             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2314             * @return the ordered range of matching wiki nodes
2315             * @throws SystemException if a system exception occurred
2316             */
2317            public List<WikiNode> findByCompanyId(long companyId, int start, int end,
2318                    OrderByComparator orderByComparator) throws SystemException {
2319                    boolean pagination = true;
2320                    FinderPath finderPath = null;
2321                    Object[] finderArgs = null;
2322    
2323                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2324                                    (orderByComparator == null)) {
2325                            pagination = false;
2326                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2327                            finderArgs = new Object[] { companyId };
2328                    }
2329                    else {
2330                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2331                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2332                    }
2333    
2334                    List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
2335                                    finderArgs, this);
2336    
2337                    if ((list != null) && !list.isEmpty()) {
2338                            for (WikiNode wikiNode : list) {
2339                                    if ((companyId != wikiNode.getCompanyId())) {
2340                                            list = null;
2341    
2342                                            break;
2343                                    }
2344                            }
2345                    }
2346    
2347                    if (list == null) {
2348                            StringBundler query = null;
2349    
2350                            if (orderByComparator != null) {
2351                                    query = new StringBundler(3 +
2352                                                    (orderByComparator.getOrderByFields().length * 3));
2353                            }
2354                            else {
2355                                    query = new StringBundler(3);
2356                            }
2357    
2358                            query.append(_SQL_SELECT_WIKINODE_WHERE);
2359    
2360                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2361    
2362                            if (orderByComparator != null) {
2363                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2364                                            orderByComparator);
2365                            }
2366                            else
2367                             if (pagination) {
2368                                    query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
2369                            }
2370    
2371                            String sql = query.toString();
2372    
2373                            Session session = null;
2374    
2375                            try {
2376                                    session = openSession();
2377    
2378                                    Query q = session.createQuery(sql);
2379    
2380                                    QueryPos qPos = QueryPos.getInstance(q);
2381    
2382                                    qPos.add(companyId);
2383    
2384                                    if (!pagination) {
2385                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
2386                                                            start, end, false);
2387    
2388                                            Collections.sort(list);
2389    
2390                                            list = new UnmodifiableList<WikiNode>(list);
2391                                    }
2392                                    else {
2393                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
2394                                                            start, end);
2395                                    }
2396    
2397                                    cacheResult(list);
2398    
2399                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2400                            }
2401                            catch (Exception e) {
2402                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2403    
2404                                    throw processException(e);
2405                            }
2406                            finally {
2407                                    closeSession(session);
2408                            }
2409                    }
2410    
2411                    return list;
2412            }
2413    
2414            /**
2415             * Returns the first wiki node in the ordered set where companyId = &#63;.
2416             *
2417             * @param companyId the company ID
2418             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2419             * @return the first matching wiki node
2420             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
2421             * @throws SystemException if a system exception occurred
2422             */
2423            public WikiNode findByCompanyId_First(long companyId,
2424                    OrderByComparator orderByComparator)
2425                    throws NoSuchNodeException, SystemException {
2426                    WikiNode wikiNode = fetchByCompanyId_First(companyId, orderByComparator);
2427    
2428                    if (wikiNode != null) {
2429                            return wikiNode;
2430                    }
2431    
2432                    StringBundler msg = new StringBundler(4);
2433    
2434                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2435    
2436                    msg.append("companyId=");
2437                    msg.append(companyId);
2438    
2439                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2440    
2441                    throw new NoSuchNodeException(msg.toString());
2442            }
2443    
2444            /**
2445             * Returns the first wiki node in the ordered set where companyId = &#63;.
2446             *
2447             * @param companyId the company ID
2448             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2449             * @return the first matching wiki node, or <code>null</code> if a matching wiki node could not be found
2450             * @throws SystemException if a system exception occurred
2451             */
2452            public WikiNode fetchByCompanyId_First(long companyId,
2453                    OrderByComparator orderByComparator) throws SystemException {
2454                    List<WikiNode> list = findByCompanyId(companyId, 0, 1, orderByComparator);
2455    
2456                    if (!list.isEmpty()) {
2457                            return list.get(0);
2458                    }
2459    
2460                    return null;
2461            }
2462    
2463            /**
2464             * Returns the last wiki node in the ordered set where companyId = &#63;.
2465             *
2466             * @param companyId the company ID
2467             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2468             * @return the last matching wiki node
2469             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
2470             * @throws SystemException if a system exception occurred
2471             */
2472            public WikiNode findByCompanyId_Last(long companyId,
2473                    OrderByComparator orderByComparator)
2474                    throws NoSuchNodeException, SystemException {
2475                    WikiNode wikiNode = fetchByCompanyId_Last(companyId, orderByComparator);
2476    
2477                    if (wikiNode != null) {
2478                            return wikiNode;
2479                    }
2480    
2481                    StringBundler msg = new StringBundler(4);
2482    
2483                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2484    
2485                    msg.append("companyId=");
2486                    msg.append(companyId);
2487    
2488                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2489    
2490                    throw new NoSuchNodeException(msg.toString());
2491            }
2492    
2493            /**
2494             * Returns the last wiki node in the ordered set where companyId = &#63;.
2495             *
2496             * @param companyId the company ID
2497             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2498             * @return the last matching wiki node, or <code>null</code> if a matching wiki node could not be found
2499             * @throws SystemException if a system exception occurred
2500             */
2501            public WikiNode fetchByCompanyId_Last(long companyId,
2502                    OrderByComparator orderByComparator) throws SystemException {
2503                    int count = countByCompanyId(companyId);
2504    
2505                    List<WikiNode> list = findByCompanyId(companyId, count - 1, count,
2506                                    orderByComparator);
2507    
2508                    if (!list.isEmpty()) {
2509                            return list.get(0);
2510                    }
2511    
2512                    return null;
2513            }
2514    
2515            /**
2516             * Returns the wiki nodes before and after the current wiki node in the ordered set where companyId = &#63;.
2517             *
2518             * @param nodeId the primary key of the current wiki node
2519             * @param companyId the company ID
2520             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2521             * @return the previous, current, and next wiki node
2522             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
2523             * @throws SystemException if a system exception occurred
2524             */
2525            public WikiNode[] findByCompanyId_PrevAndNext(long nodeId, long companyId,
2526                    OrderByComparator orderByComparator)
2527                    throws NoSuchNodeException, SystemException {
2528                    WikiNode wikiNode = findByPrimaryKey(nodeId);
2529    
2530                    Session session = null;
2531    
2532                    try {
2533                            session = openSession();
2534    
2535                            WikiNode[] array = new WikiNodeImpl[3];
2536    
2537                            array[0] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
2538                                            orderByComparator, true);
2539    
2540                            array[1] = wikiNode;
2541    
2542                            array[2] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
2543                                            orderByComparator, false);
2544    
2545                            return array;
2546                    }
2547                    catch (Exception e) {
2548                            throw processException(e);
2549                    }
2550                    finally {
2551                            closeSession(session);
2552                    }
2553            }
2554    
2555            protected WikiNode getByCompanyId_PrevAndNext(Session session,
2556                    WikiNode wikiNode, long companyId, OrderByComparator orderByComparator,
2557                    boolean previous) {
2558                    StringBundler query = null;
2559    
2560                    if (orderByComparator != null) {
2561                            query = new StringBundler(6 +
2562                                            (orderByComparator.getOrderByFields().length * 6));
2563                    }
2564                    else {
2565                            query = new StringBundler(3);
2566                    }
2567    
2568                    query.append(_SQL_SELECT_WIKINODE_WHERE);
2569    
2570                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2571    
2572                    if (orderByComparator != null) {
2573                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2574    
2575                            if (orderByConditionFields.length > 0) {
2576                                    query.append(WHERE_AND);
2577                            }
2578    
2579                            for (int i = 0; i < orderByConditionFields.length; i++) {
2580                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2581                                    query.append(orderByConditionFields[i]);
2582    
2583                                    if ((i + 1) < orderByConditionFields.length) {
2584                                            if (orderByComparator.isAscending() ^ previous) {
2585                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2586                                            }
2587                                            else {
2588                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2589                                            }
2590                                    }
2591                                    else {
2592                                            if (orderByComparator.isAscending() ^ previous) {
2593                                                    query.append(WHERE_GREATER_THAN);
2594                                            }
2595                                            else {
2596                                                    query.append(WHERE_LESSER_THAN);
2597                                            }
2598                                    }
2599                            }
2600    
2601                            query.append(ORDER_BY_CLAUSE);
2602    
2603                            String[] orderByFields = orderByComparator.getOrderByFields();
2604    
2605                            for (int i = 0; i < orderByFields.length; i++) {
2606                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2607                                    query.append(orderByFields[i]);
2608    
2609                                    if ((i + 1) < orderByFields.length) {
2610                                            if (orderByComparator.isAscending() ^ previous) {
2611                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2612                                            }
2613                                            else {
2614                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2615                                            }
2616                                    }
2617                                    else {
2618                                            if (orderByComparator.isAscending() ^ previous) {
2619                                                    query.append(ORDER_BY_ASC);
2620                                            }
2621                                            else {
2622                                                    query.append(ORDER_BY_DESC);
2623                                            }
2624                                    }
2625                            }
2626                    }
2627                    else {
2628                            query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
2629                    }
2630    
2631                    String sql = query.toString();
2632    
2633                    Query q = session.createQuery(sql);
2634    
2635                    q.setFirstResult(0);
2636                    q.setMaxResults(2);
2637    
2638                    QueryPos qPos = QueryPos.getInstance(q);
2639    
2640                    qPos.add(companyId);
2641    
2642                    if (orderByComparator != null) {
2643                            Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
2644    
2645                            for (Object value : values) {
2646                                    qPos.add(value);
2647                            }
2648                    }
2649    
2650                    List<WikiNode> list = q.list();
2651    
2652                    if (list.size() == 2) {
2653                            return list.get(1);
2654                    }
2655                    else {
2656                            return null;
2657                    }
2658            }
2659    
2660            /**
2661             * Removes all the wiki nodes where companyId = &#63; from the database.
2662             *
2663             * @param companyId the company ID
2664             * @throws SystemException if a system exception occurred
2665             */
2666            public void removeByCompanyId(long companyId) throws SystemException {
2667                    for (WikiNode wikiNode : findByCompanyId(companyId, QueryUtil.ALL_POS,
2668                                    QueryUtil.ALL_POS, null)) {
2669                            remove(wikiNode);
2670                    }
2671            }
2672    
2673            /**
2674             * Returns the number of wiki nodes where companyId = &#63;.
2675             *
2676             * @param companyId the company ID
2677             * @return the number of matching wiki nodes
2678             * @throws SystemException if a system exception occurred
2679             */
2680            public int countByCompanyId(long companyId) throws SystemException {
2681                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2682    
2683                    Object[] finderArgs = new Object[] { companyId };
2684    
2685                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2686                                    this);
2687    
2688                    if (count == null) {
2689                            StringBundler query = new StringBundler(2);
2690    
2691                            query.append(_SQL_COUNT_WIKINODE_WHERE);
2692    
2693                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2694    
2695                            String sql = query.toString();
2696    
2697                            Session session = null;
2698    
2699                            try {
2700                                    session = openSession();
2701    
2702                                    Query q = session.createQuery(sql);
2703    
2704                                    QueryPos qPos = QueryPos.getInstance(q);
2705    
2706                                    qPos.add(companyId);
2707    
2708                                    count = (Long)q.uniqueResult();
2709    
2710                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2711                            }
2712                            catch (Exception e) {
2713                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2714    
2715                                    throw processException(e);
2716                            }
2717                            finally {
2718                                    closeSession(session);
2719                            }
2720                    }
2721    
2722                    return count.intValue();
2723            }
2724    
2725            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "wikiNode.companyId = ?";
2726            public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
2727                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
2728                            FINDER_CLASS_NAME_ENTITY, "fetchByG_N",
2729                            new String[] { Long.class.getName(), String.class.getName() },
2730                            WikiNodeModelImpl.GROUPID_COLUMN_BITMASK |
2731                            WikiNodeModelImpl.NAME_COLUMN_BITMASK);
2732            public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
2733                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
2734                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N",
2735                            new String[] { Long.class.getName(), String.class.getName() });
2736    
2737            /**
2738             * Returns the wiki node where groupId = &#63; and name = &#63; or throws a {@link com.liferay.portlet.wiki.NoSuchNodeException} if it could not be found.
2739             *
2740             * @param groupId the group ID
2741             * @param name the name
2742             * @return the matching wiki node
2743             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
2744             * @throws SystemException if a system exception occurred
2745             */
2746            public WikiNode findByG_N(long groupId, String name)
2747                    throws NoSuchNodeException, SystemException {
2748                    WikiNode wikiNode = fetchByG_N(groupId, name);
2749    
2750                    if (wikiNode == null) {
2751                            StringBundler msg = new StringBundler(6);
2752    
2753                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2754    
2755                            msg.append("groupId=");
2756                            msg.append(groupId);
2757    
2758                            msg.append(", name=");
2759                            msg.append(name);
2760    
2761                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2762    
2763                            if (_log.isWarnEnabled()) {
2764                                    _log.warn(msg.toString());
2765                            }
2766    
2767                            throw new NoSuchNodeException(msg.toString());
2768                    }
2769    
2770                    return wikiNode;
2771            }
2772    
2773            /**
2774             * Returns the wiki node where groupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2775             *
2776             * @param groupId the group ID
2777             * @param name the name
2778             * @return the matching wiki node, or <code>null</code> if a matching wiki node could not be found
2779             * @throws SystemException if a system exception occurred
2780             */
2781            public WikiNode fetchByG_N(long groupId, String name)
2782                    throws SystemException {
2783                    return fetchByG_N(groupId, name, true);
2784            }
2785    
2786            /**
2787             * Returns the wiki node where groupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2788             *
2789             * @param groupId the group ID
2790             * @param name the name
2791             * @param retrieveFromCache whether to use the finder cache
2792             * @return the matching wiki node, or <code>null</code> if a matching wiki node could not be found
2793             * @throws SystemException if a system exception occurred
2794             */
2795            public WikiNode fetchByG_N(long groupId, String name,
2796                    boolean retrieveFromCache) throws SystemException {
2797                    Object[] finderArgs = new Object[] { groupId, name };
2798    
2799                    Object result = null;
2800    
2801                    if (retrieveFromCache) {
2802                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
2803                                            finderArgs, this);
2804                    }
2805    
2806                    if (result instanceof WikiNode) {
2807                            WikiNode wikiNode = (WikiNode)result;
2808    
2809                            if ((groupId != wikiNode.getGroupId()) ||
2810                                            !Validator.equals(name, wikiNode.getName())) {
2811                                    result = null;
2812                            }
2813                    }
2814    
2815                    if (result == null) {
2816                            StringBundler query = new StringBundler(4);
2817    
2818                            query.append(_SQL_SELECT_WIKINODE_WHERE);
2819    
2820                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2821    
2822                            boolean bindName = false;
2823    
2824                            if (name == null) {
2825                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
2826                            }
2827                            else if (name.equals(StringPool.BLANK)) {
2828                                    query.append(_FINDER_COLUMN_G_N_NAME_3);
2829                            }
2830                            else {
2831                                    bindName = true;
2832    
2833                                    query.append(_FINDER_COLUMN_G_N_NAME_2);
2834                            }
2835    
2836                            String sql = query.toString();
2837    
2838                            Session session = null;
2839    
2840                            try {
2841                                    session = openSession();
2842    
2843                                    Query q = session.createQuery(sql);
2844    
2845                                    QueryPos qPos = QueryPos.getInstance(q);
2846    
2847                                    qPos.add(groupId);
2848    
2849                                    if (bindName) {
2850                                            qPos.add(name);
2851                                    }
2852    
2853                                    List<WikiNode> list = q.list();
2854    
2855                                    if (list.isEmpty()) {
2856                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
2857                                                    finderArgs, list);
2858                                    }
2859                                    else {
2860                                            WikiNode wikiNode = list.get(0);
2861    
2862                                            result = wikiNode;
2863    
2864                                            cacheResult(wikiNode);
2865    
2866                                            if ((wikiNode.getGroupId() != groupId) ||
2867                                                            (wikiNode.getName() == null) ||
2868                                                            !wikiNode.getName().equals(name)) {
2869                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
2870                                                            finderArgs, wikiNode);
2871                                            }
2872                                    }
2873                            }
2874                            catch (Exception e) {
2875                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
2876                                            finderArgs);
2877    
2878                                    throw processException(e);
2879                            }
2880                            finally {
2881                                    closeSession(session);
2882                            }
2883                    }
2884    
2885                    if (result instanceof List<?>) {
2886                            return null;
2887                    }
2888                    else {
2889                            return (WikiNode)result;
2890                    }
2891            }
2892    
2893            /**
2894             * Removes the wiki node where groupId = &#63; and name = &#63; from the database.
2895             *
2896             * @param groupId the group ID
2897             * @param name the name
2898             * @return the wiki node that was removed
2899             * @throws SystemException if a system exception occurred
2900             */
2901            public WikiNode removeByG_N(long groupId, String name)
2902                    throws NoSuchNodeException, SystemException {
2903                    WikiNode wikiNode = findByG_N(groupId, name);
2904    
2905                    return remove(wikiNode);
2906            }
2907    
2908            /**
2909             * Returns the number of wiki nodes where groupId = &#63; and name = &#63;.
2910             *
2911             * @param groupId the group ID
2912             * @param name the name
2913             * @return the number of matching wiki nodes
2914             * @throws SystemException if a system exception occurred
2915             */
2916            public int countByG_N(long groupId, String name) throws SystemException {
2917                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N;
2918    
2919                    Object[] finderArgs = new Object[] { groupId, name };
2920    
2921                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2922                                    this);
2923    
2924                    if (count == null) {
2925                            StringBundler query = new StringBundler(3);
2926    
2927                            query.append(_SQL_COUNT_WIKINODE_WHERE);
2928    
2929                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2930    
2931                            boolean bindName = false;
2932    
2933                            if (name == null) {
2934                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
2935                            }
2936                            else if (name.equals(StringPool.BLANK)) {
2937                                    query.append(_FINDER_COLUMN_G_N_NAME_3);
2938                            }
2939                            else {
2940                                    bindName = true;
2941    
2942                                    query.append(_FINDER_COLUMN_G_N_NAME_2);
2943                            }
2944    
2945                            String sql = query.toString();
2946    
2947                            Session session = null;
2948    
2949                            try {
2950                                    session = openSession();
2951    
2952                                    Query q = session.createQuery(sql);
2953    
2954                                    QueryPos qPos = QueryPos.getInstance(q);
2955    
2956                                    qPos.add(groupId);
2957    
2958                                    if (bindName) {
2959                                            qPos.add(name);
2960                                    }
2961    
2962                                    count = (Long)q.uniqueResult();
2963    
2964                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2965                            }
2966                            catch (Exception e) {
2967                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2968    
2969                                    throw processException(e);
2970                            }
2971                            finally {
2972                                    closeSession(session);
2973                            }
2974                    }
2975    
2976                    return count.intValue();
2977            }
2978    
2979            private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "wikiNode.groupId = ? AND ";
2980            private static final String _FINDER_COLUMN_G_N_NAME_1 = "wikiNode.name IS NULL";
2981            private static final String _FINDER_COLUMN_G_N_NAME_2 = "wikiNode.name = ?";
2982            private static final String _FINDER_COLUMN_G_N_NAME_3 = "(wikiNode.name IS NULL OR wikiNode.name = '')";
2983            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
2984                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
2985                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
2986                            new String[] {
2987                                    Long.class.getName(), Integer.class.getName(),
2988                                    
2989                            Integer.class.getName(), Integer.class.getName(),
2990                                    OrderByComparator.class.getName()
2991                            });
2992            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
2993                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
2994                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
2995                            new String[] { Long.class.getName(), Integer.class.getName() },
2996                            WikiNodeModelImpl.GROUPID_COLUMN_BITMASK |
2997                            WikiNodeModelImpl.STATUS_COLUMN_BITMASK |
2998                            WikiNodeModelImpl.NAME_COLUMN_BITMASK);
2999            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
3000                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
3001                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
3002                            new String[] { Long.class.getName(), Integer.class.getName() });
3003    
3004            /**
3005             * Returns all the wiki nodes where groupId = &#63; and status = &#63;.
3006             *
3007             * @param groupId the group ID
3008             * @param status the status
3009             * @return the matching wiki nodes
3010             * @throws SystemException if a system exception occurred
3011             */
3012            public List<WikiNode> findByG_S(long groupId, int status)
3013                    throws SystemException {
3014                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3015                            null);
3016            }
3017    
3018            /**
3019             * Returns a range of all the wiki nodes where groupId = &#63; and status = &#63;.
3020             *
3021             * <p>
3022             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3023             * </p>
3024             *
3025             * @param groupId the group ID
3026             * @param status the status
3027             * @param start the lower bound of the range of wiki nodes
3028             * @param end the upper bound of the range of wiki nodes (not inclusive)
3029             * @return the range of matching wiki nodes
3030             * @throws SystemException if a system exception occurred
3031             */
3032            public List<WikiNode> findByG_S(long groupId, int status, int start, int end)
3033                    throws SystemException {
3034                    return findByG_S(groupId, status, start, end, null);
3035            }
3036    
3037            /**
3038             * Returns an ordered range of all the wiki nodes where groupId = &#63; and status = &#63;.
3039             *
3040             * <p>
3041             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3042             * </p>
3043             *
3044             * @param groupId the group ID
3045             * @param status the status
3046             * @param start the lower bound of the range of wiki nodes
3047             * @param end the upper bound of the range of wiki nodes (not inclusive)
3048             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3049             * @return the ordered range of matching wiki nodes
3050             * @throws SystemException if a system exception occurred
3051             */
3052            public List<WikiNode> findByG_S(long groupId, int status, int start,
3053                    int end, OrderByComparator orderByComparator) throws SystemException {
3054                    boolean pagination = true;
3055                    FinderPath finderPath = null;
3056                    Object[] finderArgs = null;
3057    
3058                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3059                                    (orderByComparator == null)) {
3060                            pagination = false;
3061                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
3062                            finderArgs = new Object[] { groupId, status };
3063                    }
3064                    else {
3065                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
3066                            finderArgs = new Object[] {
3067                                            groupId, status,
3068                                            
3069                                            start, end, orderByComparator
3070                                    };
3071                    }
3072    
3073                    List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
3074                                    finderArgs, this);
3075    
3076                    if ((list != null) && !list.isEmpty()) {
3077                            for (WikiNode wikiNode : list) {
3078                                    if ((groupId != wikiNode.getGroupId()) ||
3079                                                    (status != wikiNode.getStatus())) {
3080                                            list = null;
3081    
3082                                            break;
3083                                    }
3084                            }
3085                    }
3086    
3087                    if (list == null) {
3088                            StringBundler query = null;
3089    
3090                            if (orderByComparator != null) {
3091                                    query = new StringBundler(4 +
3092                                                    (orderByComparator.getOrderByFields().length * 3));
3093                            }
3094                            else {
3095                                    query = new StringBundler(4);
3096                            }
3097    
3098                            query.append(_SQL_SELECT_WIKINODE_WHERE);
3099    
3100                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3101    
3102                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
3103    
3104                            if (orderByComparator != null) {
3105                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3106                                            orderByComparator);
3107                            }
3108                            else
3109                             if (pagination) {
3110                                    query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
3111                            }
3112    
3113                            String sql = query.toString();
3114    
3115                            Session session = null;
3116    
3117                            try {
3118                                    session = openSession();
3119    
3120                                    Query q = session.createQuery(sql);
3121    
3122                                    QueryPos qPos = QueryPos.getInstance(q);
3123    
3124                                    qPos.add(groupId);
3125    
3126                                    qPos.add(status);
3127    
3128                                    if (!pagination) {
3129                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
3130                                                            start, end, false);
3131    
3132                                            Collections.sort(list);
3133    
3134                                            list = new UnmodifiableList<WikiNode>(list);
3135                                    }
3136                                    else {
3137                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
3138                                                            start, end);
3139                                    }
3140    
3141                                    cacheResult(list);
3142    
3143                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3144                            }
3145                            catch (Exception e) {
3146                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3147    
3148                                    throw processException(e);
3149                            }
3150                            finally {
3151                                    closeSession(session);
3152                            }
3153                    }
3154    
3155                    return list;
3156            }
3157    
3158            /**
3159             * Returns the first wiki node in the ordered set where groupId = &#63; and status = &#63;.
3160             *
3161             * @param groupId the group ID
3162             * @param status the status
3163             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3164             * @return the first matching wiki node
3165             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
3166             * @throws SystemException if a system exception occurred
3167             */
3168            public WikiNode findByG_S_First(long groupId, int status,
3169                    OrderByComparator orderByComparator)
3170                    throws NoSuchNodeException, SystemException {
3171                    WikiNode wikiNode = fetchByG_S_First(groupId, status, orderByComparator);
3172    
3173                    if (wikiNode != null) {
3174                            return wikiNode;
3175                    }
3176    
3177                    StringBundler msg = new StringBundler(6);
3178    
3179                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3180    
3181                    msg.append("groupId=");
3182                    msg.append(groupId);
3183    
3184                    msg.append(", status=");
3185                    msg.append(status);
3186    
3187                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3188    
3189                    throw new NoSuchNodeException(msg.toString());
3190            }
3191    
3192            /**
3193             * Returns the first wiki node in the ordered set where groupId = &#63; and status = &#63;.
3194             *
3195             * @param groupId the group ID
3196             * @param status the status
3197             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3198             * @return the first matching wiki node, or <code>null</code> if a matching wiki node could not be found
3199             * @throws SystemException if a system exception occurred
3200             */
3201            public WikiNode fetchByG_S_First(long groupId, int status,
3202                    OrderByComparator orderByComparator) throws SystemException {
3203                    List<WikiNode> list = findByG_S(groupId, status, 0, 1, orderByComparator);
3204    
3205                    if (!list.isEmpty()) {
3206                            return list.get(0);
3207                    }
3208    
3209                    return null;
3210            }
3211    
3212            /**
3213             * Returns the last wiki node in the ordered set where groupId = &#63; and status = &#63;.
3214             *
3215             * @param groupId the group ID
3216             * @param status the status
3217             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3218             * @return the last matching wiki node
3219             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
3220             * @throws SystemException if a system exception occurred
3221             */
3222            public WikiNode findByG_S_Last(long groupId, int status,
3223                    OrderByComparator orderByComparator)
3224                    throws NoSuchNodeException, SystemException {
3225                    WikiNode wikiNode = fetchByG_S_Last(groupId, status, orderByComparator);
3226    
3227                    if (wikiNode != null) {
3228                            return wikiNode;
3229                    }
3230    
3231                    StringBundler msg = new StringBundler(6);
3232    
3233                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3234    
3235                    msg.append("groupId=");
3236                    msg.append(groupId);
3237    
3238                    msg.append(", status=");
3239                    msg.append(status);
3240    
3241                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3242    
3243                    throw new NoSuchNodeException(msg.toString());
3244            }
3245    
3246            /**
3247             * Returns the last wiki node in the ordered set where groupId = &#63; and status = &#63;.
3248             *
3249             * @param groupId the group ID
3250             * @param status the status
3251             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3252             * @return the last matching wiki node, or <code>null</code> if a matching wiki node could not be found
3253             * @throws SystemException if a system exception occurred
3254             */
3255            public WikiNode fetchByG_S_Last(long groupId, int status,
3256                    OrderByComparator orderByComparator) throws SystemException {
3257                    int count = countByG_S(groupId, status);
3258    
3259                    List<WikiNode> list = findByG_S(groupId, status, count - 1, count,
3260                                    orderByComparator);
3261    
3262                    if (!list.isEmpty()) {
3263                            return list.get(0);
3264                    }
3265    
3266                    return null;
3267            }
3268    
3269            /**
3270             * Returns the wiki nodes before and after the current wiki node in the ordered set where groupId = &#63; and status = &#63;.
3271             *
3272             * @param nodeId the primary key of the current wiki node
3273             * @param groupId the group ID
3274             * @param status the status
3275             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3276             * @return the previous, current, and next wiki node
3277             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
3278             * @throws SystemException if a system exception occurred
3279             */
3280            public WikiNode[] findByG_S_PrevAndNext(long nodeId, long groupId,
3281                    int status, OrderByComparator orderByComparator)
3282                    throws NoSuchNodeException, SystemException {
3283                    WikiNode wikiNode = findByPrimaryKey(nodeId);
3284    
3285                    Session session = null;
3286    
3287                    try {
3288                            session = openSession();
3289    
3290                            WikiNode[] array = new WikiNodeImpl[3];
3291    
3292                            array[0] = getByG_S_PrevAndNext(session, wikiNode, groupId, status,
3293                                            orderByComparator, true);
3294    
3295                            array[1] = wikiNode;
3296    
3297                            array[2] = getByG_S_PrevAndNext(session, wikiNode, groupId, status,
3298                                            orderByComparator, false);
3299    
3300                            return array;
3301                    }
3302                    catch (Exception e) {
3303                            throw processException(e);
3304                    }
3305                    finally {
3306                            closeSession(session);
3307                    }
3308            }
3309    
3310            protected WikiNode getByG_S_PrevAndNext(Session session, WikiNode wikiNode,
3311                    long groupId, int status, OrderByComparator orderByComparator,
3312                    boolean previous) {
3313                    StringBundler query = null;
3314    
3315                    if (orderByComparator != null) {
3316                            query = new StringBundler(6 +
3317                                            (orderByComparator.getOrderByFields().length * 6));
3318                    }
3319                    else {
3320                            query = new StringBundler(3);
3321                    }
3322    
3323                    query.append(_SQL_SELECT_WIKINODE_WHERE);
3324    
3325                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3326    
3327                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
3328    
3329                    if (orderByComparator != null) {
3330                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3331    
3332                            if (orderByConditionFields.length > 0) {
3333                                    query.append(WHERE_AND);
3334                            }
3335    
3336                            for (int i = 0; i < orderByConditionFields.length; i++) {
3337                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3338                                    query.append(orderByConditionFields[i]);
3339    
3340                                    if ((i + 1) < orderByConditionFields.length) {
3341                                            if (orderByComparator.isAscending() ^ previous) {
3342                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3343                                            }
3344                                            else {
3345                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3346                                            }
3347                                    }
3348                                    else {
3349                                            if (orderByComparator.isAscending() ^ previous) {
3350                                                    query.append(WHERE_GREATER_THAN);
3351                                            }
3352                                            else {
3353                                                    query.append(WHERE_LESSER_THAN);
3354                                            }
3355                                    }
3356                            }
3357    
3358                            query.append(ORDER_BY_CLAUSE);
3359    
3360                            String[] orderByFields = orderByComparator.getOrderByFields();
3361    
3362                            for (int i = 0; i < orderByFields.length; i++) {
3363                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3364                                    query.append(orderByFields[i]);
3365    
3366                                    if ((i + 1) < orderByFields.length) {
3367                                            if (orderByComparator.isAscending() ^ previous) {
3368                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3369                                            }
3370                                            else {
3371                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3372                                            }
3373                                    }
3374                                    else {
3375                                            if (orderByComparator.isAscending() ^ previous) {
3376                                                    query.append(ORDER_BY_ASC);
3377                                            }
3378                                            else {
3379                                                    query.append(ORDER_BY_DESC);
3380                                            }
3381                                    }
3382                            }
3383                    }
3384                    else {
3385                            query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
3386                    }
3387    
3388                    String sql = query.toString();
3389    
3390                    Query q = session.createQuery(sql);
3391    
3392                    q.setFirstResult(0);
3393                    q.setMaxResults(2);
3394    
3395                    QueryPos qPos = QueryPos.getInstance(q);
3396    
3397                    qPos.add(groupId);
3398    
3399                    qPos.add(status);
3400    
3401                    if (orderByComparator != null) {
3402                            Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
3403    
3404                            for (Object value : values) {
3405                                    qPos.add(value);
3406                            }
3407                    }
3408    
3409                    List<WikiNode> list = q.list();
3410    
3411                    if (list.size() == 2) {
3412                            return list.get(1);
3413                    }
3414                    else {
3415                            return null;
3416                    }
3417            }
3418    
3419            /**
3420             * Returns all the wiki nodes that the user has permission to view where groupId = &#63; and status = &#63;.
3421             *
3422             * @param groupId the group ID
3423             * @param status the status
3424             * @return the matching wiki nodes that the user has permission to view
3425             * @throws SystemException if a system exception occurred
3426             */
3427            public List<WikiNode> filterFindByG_S(long groupId, int status)
3428                    throws SystemException {
3429                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
3430                            QueryUtil.ALL_POS, null);
3431            }
3432    
3433            /**
3434             * Returns a range of all the wiki nodes that the user has permission to view where groupId = &#63; and status = &#63;.
3435             *
3436             * <p>
3437             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3438             * </p>
3439             *
3440             * @param groupId the group ID
3441             * @param status the status
3442             * @param start the lower bound of the range of wiki nodes
3443             * @param end the upper bound of the range of wiki nodes (not inclusive)
3444             * @return the range of matching wiki nodes that the user has permission to view
3445             * @throws SystemException if a system exception occurred
3446             */
3447            public List<WikiNode> filterFindByG_S(long groupId, int status, int start,
3448                    int end) throws SystemException {
3449                    return filterFindByG_S(groupId, status, start, end, null);
3450            }
3451    
3452            /**
3453             * Returns an ordered range of all the wiki nodes that the user has permissions to view where groupId = &#63; and status = &#63;.
3454             *
3455             * <p>
3456             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3457             * </p>
3458             *
3459             * @param groupId the group ID
3460             * @param status the status
3461             * @param start the lower bound of the range of wiki nodes
3462             * @param end the upper bound of the range of wiki nodes (not inclusive)
3463             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3464             * @return the ordered range of matching wiki nodes that the user has permission to view
3465             * @throws SystemException if a system exception occurred
3466             */
3467            public List<WikiNode> filterFindByG_S(long groupId, int status, int start,
3468                    int end, OrderByComparator orderByComparator) throws SystemException {
3469                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3470                            return findByG_S(groupId, status, start, end, orderByComparator);
3471                    }
3472    
3473                    StringBundler query = null;
3474    
3475                    if (orderByComparator != null) {
3476                            query = new StringBundler(4 +
3477                                            (orderByComparator.getOrderByFields().length * 3));
3478                    }
3479                    else {
3480                            query = new StringBundler(4);
3481                    }
3482    
3483                    if (getDB().isSupportsInlineDistinct()) {
3484                            query.append(_FILTER_SQL_SELECT_WIKINODE_WHERE);
3485                    }
3486                    else {
3487                            query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_1);
3488                    }
3489    
3490                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3491    
3492                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
3493    
3494                    if (!getDB().isSupportsInlineDistinct()) {
3495                            query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_2);
3496                    }
3497    
3498                    if (orderByComparator != null) {
3499                            if (getDB().isSupportsInlineDistinct()) {
3500                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3501                                            orderByComparator);
3502                            }
3503                            else {
3504                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3505                                            orderByComparator);
3506                            }
3507                    }
3508                    else {
3509                            if (getDB().isSupportsInlineDistinct()) {
3510                                    query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
3511                            }
3512                            else {
3513                                    query.append(WikiNodeModelImpl.ORDER_BY_SQL);
3514                            }
3515                    }
3516    
3517                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3518                                    WikiNode.class.getName(),
3519                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3520    
3521                    Session session = null;
3522    
3523                    try {
3524                            session = openSession();
3525    
3526                            SQLQuery q = session.createSQLQuery(sql);
3527    
3528                            if (getDB().isSupportsInlineDistinct()) {
3529                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiNodeImpl.class);
3530                            }
3531                            else {
3532                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiNodeImpl.class);
3533                            }
3534    
3535                            QueryPos qPos = QueryPos.getInstance(q);
3536    
3537                            qPos.add(groupId);
3538    
3539                            qPos.add(status);
3540    
3541                            return (List<WikiNode>)QueryUtil.list(q, getDialect(), start, end);
3542                    }
3543                    catch (Exception e) {
3544                            throw processException(e);
3545                    }
3546                    finally {
3547                            closeSession(session);
3548                    }
3549            }
3550    
3551            /**
3552             * Returns the wiki nodes before and after the current wiki node in the ordered set of wiki nodes that the user has permission to view where groupId = &#63; and status = &#63;.
3553             *
3554             * @param nodeId the primary key of the current wiki node
3555             * @param groupId the group ID
3556             * @param status the status
3557             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3558             * @return the previous, current, and next wiki node
3559             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
3560             * @throws SystemException if a system exception occurred
3561             */
3562            public WikiNode[] filterFindByG_S_PrevAndNext(long nodeId, long groupId,
3563                    int status, OrderByComparator orderByComparator)
3564                    throws NoSuchNodeException, SystemException {
3565                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3566                            return findByG_S_PrevAndNext(nodeId, groupId, status,
3567                                    orderByComparator);
3568                    }
3569    
3570                    WikiNode wikiNode = findByPrimaryKey(nodeId);
3571    
3572                    Session session = null;
3573    
3574                    try {
3575                            session = openSession();
3576    
3577                            WikiNode[] array = new WikiNodeImpl[3];
3578    
3579                            array[0] = filterGetByG_S_PrevAndNext(session, wikiNode, groupId,
3580                                            status, orderByComparator, true);
3581    
3582                            array[1] = wikiNode;
3583    
3584                            array[2] = filterGetByG_S_PrevAndNext(session, wikiNode, groupId,
3585                                            status, orderByComparator, false);
3586    
3587                            return array;
3588                    }
3589                    catch (Exception e) {
3590                            throw processException(e);
3591                    }
3592                    finally {
3593                            closeSession(session);
3594                    }
3595            }
3596    
3597            protected WikiNode filterGetByG_S_PrevAndNext(Session session,
3598                    WikiNode wikiNode, long groupId, int status,
3599                    OrderByComparator orderByComparator, boolean previous) {
3600                    StringBundler query = null;
3601    
3602                    if (orderByComparator != null) {
3603                            query = new StringBundler(6 +
3604                                            (orderByComparator.getOrderByFields().length * 6));
3605                    }
3606                    else {
3607                            query = new StringBundler(3);
3608                    }
3609    
3610                    if (getDB().isSupportsInlineDistinct()) {
3611                            query.append(_FILTER_SQL_SELECT_WIKINODE_WHERE);
3612                    }
3613                    else {
3614                            query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_1);
3615                    }
3616    
3617                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3618    
3619                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
3620    
3621                    if (!getDB().isSupportsInlineDistinct()) {
3622                            query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_2);
3623                    }
3624    
3625                    if (orderByComparator != null) {
3626                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3627    
3628                            if (orderByConditionFields.length > 0) {
3629                                    query.append(WHERE_AND);
3630                            }
3631    
3632                            for (int i = 0; i < orderByConditionFields.length; i++) {
3633                                    if (getDB().isSupportsInlineDistinct()) {
3634                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3635                                    }
3636                                    else {
3637                                            query.append(_ORDER_BY_ENTITY_TABLE);
3638                                    }
3639    
3640                                    query.append(orderByConditionFields[i]);
3641    
3642                                    if ((i + 1) < orderByConditionFields.length) {
3643                                            if (orderByComparator.isAscending() ^ previous) {
3644                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3645                                            }
3646                                            else {
3647                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3648                                            }
3649                                    }
3650                                    else {
3651                                            if (orderByComparator.isAscending() ^ previous) {
3652                                                    query.append(WHERE_GREATER_THAN);
3653                                            }
3654                                            else {
3655                                                    query.append(WHERE_LESSER_THAN);
3656                                            }
3657                                    }
3658                            }
3659    
3660                            query.append(ORDER_BY_CLAUSE);
3661    
3662                            String[] orderByFields = orderByComparator.getOrderByFields();
3663    
3664                            for (int i = 0; i < orderByFields.length; i++) {
3665                                    if (getDB().isSupportsInlineDistinct()) {
3666                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3667                                    }
3668                                    else {
3669                                            query.append(_ORDER_BY_ENTITY_TABLE);
3670                                    }
3671    
3672                                    query.append(orderByFields[i]);
3673    
3674                                    if ((i + 1) < orderByFields.length) {
3675                                            if (orderByComparator.isAscending() ^ previous) {
3676                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3677                                            }
3678                                            else {
3679                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3680                                            }
3681                                    }
3682                                    else {
3683                                            if (orderByComparator.isAscending() ^ previous) {
3684                                                    query.append(ORDER_BY_ASC);
3685                                            }
3686                                            else {
3687                                                    query.append(ORDER_BY_DESC);
3688                                            }
3689                                    }
3690                            }
3691                    }
3692                    else {
3693                            if (getDB().isSupportsInlineDistinct()) {
3694                                    query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
3695                            }
3696                            else {
3697                                    query.append(WikiNodeModelImpl.ORDER_BY_SQL);
3698                            }
3699                    }
3700    
3701                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3702                                    WikiNode.class.getName(),
3703                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3704    
3705                    SQLQuery q = session.createSQLQuery(sql);
3706    
3707                    q.setFirstResult(0);
3708                    q.setMaxResults(2);
3709    
3710                    if (getDB().isSupportsInlineDistinct()) {
3711                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiNodeImpl.class);
3712                    }
3713                    else {
3714                            q.addEntity(_FILTER_ENTITY_TABLE, WikiNodeImpl.class);
3715                    }
3716    
3717                    QueryPos qPos = QueryPos.getInstance(q);
3718    
3719                    qPos.add(groupId);
3720    
3721                    qPos.add(status);
3722    
3723                    if (orderByComparator != null) {
3724                            Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
3725    
3726                            for (Object value : values) {
3727                                    qPos.add(value);
3728                            }
3729                    }
3730    
3731                    List<WikiNode> list = q.list();
3732    
3733                    if (list.size() == 2) {
3734                            return list.get(1);
3735                    }
3736                    else {
3737                            return null;
3738                    }
3739            }
3740    
3741            /**
3742             * Removes all the wiki nodes where groupId = &#63; and status = &#63; from the database.
3743             *
3744             * @param groupId the group ID
3745             * @param status the status
3746             * @throws SystemException if a system exception occurred
3747             */
3748            public void removeByG_S(long groupId, int status) throws SystemException {
3749                    for (WikiNode wikiNode : findByG_S(groupId, status, QueryUtil.ALL_POS,
3750                                    QueryUtil.ALL_POS, null)) {
3751                            remove(wikiNode);
3752                    }
3753            }
3754    
3755            /**
3756             * Returns the number of wiki nodes where groupId = &#63; and status = &#63;.
3757             *
3758             * @param groupId the group ID
3759             * @param status the status
3760             * @return the number of matching wiki nodes
3761             * @throws SystemException if a system exception occurred
3762             */
3763            public int countByG_S(long groupId, int status) throws SystemException {
3764                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
3765    
3766                    Object[] finderArgs = new Object[] { groupId, status };
3767    
3768                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3769                                    this);
3770    
3771                    if (count == null) {
3772                            StringBundler query = new StringBundler(3);
3773    
3774                            query.append(_SQL_COUNT_WIKINODE_WHERE);
3775    
3776                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3777    
3778                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
3779    
3780                            String sql = query.toString();
3781    
3782                            Session session = null;
3783    
3784                            try {
3785                                    session = openSession();
3786    
3787                                    Query q = session.createQuery(sql);
3788    
3789                                    QueryPos qPos = QueryPos.getInstance(q);
3790    
3791                                    qPos.add(groupId);
3792    
3793                                    qPos.add(status);
3794    
3795                                    count = (Long)q.uniqueResult();
3796    
3797                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3798                            }
3799                            catch (Exception e) {
3800                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3801    
3802                                    throw processException(e);
3803                            }
3804                            finally {
3805                                    closeSession(session);
3806                            }
3807                    }
3808    
3809                    return count.intValue();
3810            }
3811    
3812            /**
3813             * Returns the number of wiki nodes that the user has permission to view where groupId = &#63; and status = &#63;.
3814             *
3815             * @param groupId the group ID
3816             * @param status the status
3817             * @return the number of matching wiki nodes that the user has permission to view
3818             * @throws SystemException if a system exception occurred
3819             */
3820            public int filterCountByG_S(long groupId, int status)
3821                    throws SystemException {
3822                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3823                            return countByG_S(groupId, status);
3824                    }
3825    
3826                    StringBundler query = new StringBundler(3);
3827    
3828                    query.append(_FILTER_SQL_COUNT_WIKINODE_WHERE);
3829    
3830                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3831    
3832                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
3833    
3834                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3835                                    WikiNode.class.getName(),
3836                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3837    
3838                    Session session = null;
3839    
3840                    try {
3841                            session = openSession();
3842    
3843                            SQLQuery q = session.createSQLQuery(sql);
3844    
3845                            q.addScalar(COUNT_COLUMN_NAME,
3846                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3847    
3848                            QueryPos qPos = QueryPos.getInstance(q);
3849    
3850                            qPos.add(groupId);
3851    
3852                            qPos.add(status);
3853    
3854                            Long count = (Long)q.uniqueResult();
3855    
3856                            return count.intValue();
3857                    }
3858                    catch (Exception e) {
3859                            throw processException(e);
3860                    }
3861                    finally {
3862                            closeSession(session);
3863                    }
3864            }
3865    
3866            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "wikiNode.groupId = ? AND ";
3867            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "wikiNode.status = ?";
3868            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
3869                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
3870                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
3871                            new String[] {
3872                                    Long.class.getName(), Integer.class.getName(),
3873                                    
3874                            Integer.class.getName(), Integer.class.getName(),
3875                                    OrderByComparator.class.getName()
3876                            });
3877            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
3878                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
3879                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
3880                            new String[] { Long.class.getName(), Integer.class.getName() },
3881                            WikiNodeModelImpl.COMPANYID_COLUMN_BITMASK |
3882                            WikiNodeModelImpl.STATUS_COLUMN_BITMASK |
3883                            WikiNodeModelImpl.NAME_COLUMN_BITMASK);
3884            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
3885                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
3886                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
3887                            new String[] { Long.class.getName(), Integer.class.getName() });
3888    
3889            /**
3890             * Returns all the wiki nodes where companyId = &#63; and status = &#63;.
3891             *
3892             * @param companyId the company ID
3893             * @param status the status
3894             * @return the matching wiki nodes
3895             * @throws SystemException if a system exception occurred
3896             */
3897            public List<WikiNode> findByC_S(long companyId, int status)
3898                    throws SystemException {
3899                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
3900                            QueryUtil.ALL_POS, null);
3901            }
3902    
3903            /**
3904             * Returns a range of all the wiki nodes where companyId = &#63; and status = &#63;.
3905             *
3906             * <p>
3907             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3908             * </p>
3909             *
3910             * @param companyId the company ID
3911             * @param status the status
3912             * @param start the lower bound of the range of wiki nodes
3913             * @param end the upper bound of the range of wiki nodes (not inclusive)
3914             * @return the range of matching wiki nodes
3915             * @throws SystemException if a system exception occurred
3916             */
3917            public List<WikiNode> findByC_S(long companyId, int status, int start,
3918                    int end) throws SystemException {
3919                    return findByC_S(companyId, status, start, end, null);
3920            }
3921    
3922            /**
3923             * Returns an ordered range of all the wiki nodes where companyId = &#63; and status = &#63;.
3924             *
3925             * <p>
3926             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3927             * </p>
3928             *
3929             * @param companyId the company ID
3930             * @param status the status
3931             * @param start the lower bound of the range of wiki nodes
3932             * @param end the upper bound of the range of wiki nodes (not inclusive)
3933             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3934             * @return the ordered range of matching wiki nodes
3935             * @throws SystemException if a system exception occurred
3936             */
3937            public List<WikiNode> findByC_S(long companyId, int status, int start,
3938                    int end, OrderByComparator orderByComparator) throws SystemException {
3939                    boolean pagination = true;
3940                    FinderPath finderPath = null;
3941                    Object[] finderArgs = null;
3942    
3943                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3944                                    (orderByComparator == null)) {
3945                            pagination = false;
3946                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
3947                            finderArgs = new Object[] { companyId, status };
3948                    }
3949                    else {
3950                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
3951                            finderArgs = new Object[] {
3952                                            companyId, status,
3953                                            
3954                                            start, end, orderByComparator
3955                                    };
3956                    }
3957    
3958                    List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
3959                                    finderArgs, this);
3960    
3961                    if ((list != null) && !list.isEmpty()) {
3962                            for (WikiNode wikiNode : list) {
3963                                    if ((companyId != wikiNode.getCompanyId()) ||
3964                                                    (status != wikiNode.getStatus())) {
3965                                            list = null;
3966    
3967                                            break;
3968                                    }
3969                            }
3970                    }
3971    
3972                    if (list == null) {
3973                            StringBundler query = null;
3974    
3975                            if (orderByComparator != null) {
3976                                    query = new StringBundler(4 +
3977                                                    (orderByComparator.getOrderByFields().length * 3));
3978                            }
3979                            else {
3980                                    query = new StringBundler(4);
3981                            }
3982    
3983                            query.append(_SQL_SELECT_WIKINODE_WHERE);
3984    
3985                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
3986    
3987                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
3988    
3989                            if (orderByComparator != null) {
3990                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3991                                            orderByComparator);
3992                            }
3993                            else
3994                             if (pagination) {
3995                                    query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
3996                            }
3997    
3998                            String sql = query.toString();
3999    
4000                            Session session = null;
4001    
4002                            try {
4003                                    session = openSession();
4004    
4005                                    Query q = session.createQuery(sql);
4006    
4007                                    QueryPos qPos = QueryPos.getInstance(q);
4008    
4009                                    qPos.add(companyId);
4010    
4011                                    qPos.add(status);
4012    
4013                                    if (!pagination) {
4014                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
4015                                                            start, end, false);
4016    
4017                                            Collections.sort(list);
4018    
4019                                            list = new UnmodifiableList<WikiNode>(list);
4020                                    }
4021                                    else {
4022                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
4023                                                            start, end);
4024                                    }
4025    
4026                                    cacheResult(list);
4027    
4028                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4029                            }
4030                            catch (Exception e) {
4031                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4032    
4033                                    throw processException(e);
4034                            }
4035                            finally {
4036                                    closeSession(session);
4037                            }
4038                    }
4039    
4040                    return list;
4041            }
4042    
4043            /**
4044             * Returns the first wiki node in the ordered set where companyId = &#63; and status = &#63;.
4045             *
4046             * @param companyId the company ID
4047             * @param status the status
4048             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4049             * @return the first matching wiki node
4050             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
4051             * @throws SystemException if a system exception occurred
4052             */
4053            public WikiNode findByC_S_First(long companyId, int status,
4054                    OrderByComparator orderByComparator)
4055                    throws NoSuchNodeException, SystemException {
4056                    WikiNode wikiNode = fetchByC_S_First(companyId, status,
4057                                    orderByComparator);
4058    
4059                    if (wikiNode != null) {
4060                            return wikiNode;
4061                    }
4062    
4063                    StringBundler msg = new StringBundler(6);
4064    
4065                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4066    
4067                    msg.append("companyId=");
4068                    msg.append(companyId);
4069    
4070                    msg.append(", status=");
4071                    msg.append(status);
4072    
4073                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4074    
4075                    throw new NoSuchNodeException(msg.toString());
4076            }
4077    
4078            /**
4079             * Returns the first wiki node in the ordered set where companyId = &#63; and status = &#63;.
4080             *
4081             * @param companyId the company ID
4082             * @param status the status
4083             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4084             * @return the first matching wiki node, or <code>null</code> if a matching wiki node could not be found
4085             * @throws SystemException if a system exception occurred
4086             */
4087            public WikiNode fetchByC_S_First(long companyId, int status,
4088                    OrderByComparator orderByComparator) throws SystemException {
4089                    List<WikiNode> list = findByC_S(companyId, status, 0, 1,
4090                                    orderByComparator);
4091    
4092                    if (!list.isEmpty()) {
4093                            return list.get(0);
4094                    }
4095    
4096                    return null;
4097            }
4098    
4099            /**
4100             * Returns the last wiki node in the ordered set where companyId = &#63; and status = &#63;.
4101             *
4102             * @param companyId the company ID
4103             * @param status the status
4104             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4105             * @return the last matching wiki node
4106             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
4107             * @throws SystemException if a system exception occurred
4108             */
4109            public WikiNode findByC_S_Last(long companyId, int status,
4110                    OrderByComparator orderByComparator)
4111                    throws NoSuchNodeException, SystemException {
4112                    WikiNode wikiNode = fetchByC_S_Last(companyId, status, orderByComparator);
4113    
4114                    if (wikiNode != null) {
4115                            return wikiNode;
4116                    }
4117    
4118                    StringBundler msg = new StringBundler(6);
4119    
4120                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4121    
4122                    msg.append("companyId=");
4123                    msg.append(companyId);
4124    
4125                    msg.append(", status=");
4126                    msg.append(status);
4127    
4128                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4129    
4130                    throw new NoSuchNodeException(msg.toString());
4131            }
4132    
4133            /**
4134             * Returns the last wiki node in the ordered set where companyId = &#63; and status = &#63;.
4135             *
4136             * @param companyId the company ID
4137             * @param status the status
4138             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4139             * @return the last matching wiki node, or <code>null</code> if a matching wiki node could not be found
4140             * @throws SystemException if a system exception occurred
4141             */
4142            public WikiNode fetchByC_S_Last(long companyId, int status,
4143                    OrderByComparator orderByComparator) throws SystemException {
4144                    int count = countByC_S(companyId, status);
4145    
4146                    List<WikiNode> list = findByC_S(companyId, status, count - 1, count,
4147                                    orderByComparator);
4148    
4149                    if (!list.isEmpty()) {
4150                            return list.get(0);
4151                    }
4152    
4153                    return null;
4154            }
4155    
4156            /**
4157             * Returns the wiki nodes before and after the current wiki node in the ordered set where companyId = &#63; and status = &#63;.
4158             *
4159             * @param nodeId the primary key of the current wiki node
4160             * @param companyId the company ID
4161             * @param status the status
4162             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4163             * @return the previous, current, and next wiki node
4164             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
4165             * @throws SystemException if a system exception occurred
4166             */
4167            public WikiNode[] findByC_S_PrevAndNext(long nodeId, long companyId,
4168                    int status, OrderByComparator orderByComparator)
4169                    throws NoSuchNodeException, SystemException {
4170                    WikiNode wikiNode = findByPrimaryKey(nodeId);
4171    
4172                    Session session = null;
4173    
4174                    try {
4175                            session = openSession();
4176    
4177                            WikiNode[] array = new WikiNodeImpl[3];
4178    
4179                            array[0] = getByC_S_PrevAndNext(session, wikiNode, companyId,
4180                                            status, orderByComparator, true);
4181    
4182                            array[1] = wikiNode;
4183    
4184                            array[2] = getByC_S_PrevAndNext(session, wikiNode, companyId,
4185                                            status, orderByComparator, false);
4186    
4187                            return array;
4188                    }
4189                    catch (Exception e) {
4190                            throw processException(e);
4191                    }
4192                    finally {
4193                            closeSession(session);
4194                    }
4195            }
4196    
4197            protected WikiNode getByC_S_PrevAndNext(Session session, WikiNode wikiNode,
4198                    long companyId, int status, OrderByComparator orderByComparator,
4199                    boolean previous) {
4200                    StringBundler query = null;
4201    
4202                    if (orderByComparator != null) {
4203                            query = new StringBundler(6 +
4204                                            (orderByComparator.getOrderByFields().length * 6));
4205                    }
4206                    else {
4207                            query = new StringBundler(3);
4208                    }
4209    
4210                    query.append(_SQL_SELECT_WIKINODE_WHERE);
4211    
4212                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
4213    
4214                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
4215    
4216                    if (orderByComparator != null) {
4217                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4218    
4219                            if (orderByConditionFields.length > 0) {
4220                                    query.append(WHERE_AND);
4221                            }
4222    
4223                            for (int i = 0; i < orderByConditionFields.length; i++) {
4224                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4225                                    query.append(orderByConditionFields[i]);
4226    
4227                                    if ((i + 1) < orderByConditionFields.length) {
4228                                            if (orderByComparator.isAscending() ^ previous) {
4229                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4230                                            }
4231                                            else {
4232                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4233                                            }
4234                                    }
4235                                    else {
4236                                            if (orderByComparator.isAscending() ^ previous) {
4237                                                    query.append(WHERE_GREATER_THAN);
4238                                            }
4239                                            else {
4240                                                    query.append(WHERE_LESSER_THAN);
4241                                            }
4242                                    }
4243                            }
4244    
4245                            query.append(ORDER_BY_CLAUSE);
4246    
4247                            String[] orderByFields = orderByComparator.getOrderByFields();
4248    
4249                            for (int i = 0; i < orderByFields.length; i++) {
4250                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4251                                    query.append(orderByFields[i]);
4252    
4253                                    if ((i + 1) < orderByFields.length) {
4254                                            if (orderByComparator.isAscending() ^ previous) {
4255                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4256                                            }
4257                                            else {
4258                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4259                                            }
4260                                    }
4261                                    else {
4262                                            if (orderByComparator.isAscending() ^ previous) {
4263                                                    query.append(ORDER_BY_ASC);
4264                                            }
4265                                            else {
4266                                                    query.append(ORDER_BY_DESC);
4267                                            }
4268                                    }
4269                            }
4270                    }
4271                    else {
4272                            query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
4273                    }
4274    
4275                    String sql = query.toString();
4276    
4277                    Query q = session.createQuery(sql);
4278    
4279                    q.setFirstResult(0);
4280                    q.setMaxResults(2);
4281    
4282                    QueryPos qPos = QueryPos.getInstance(q);
4283    
4284                    qPos.add(companyId);
4285    
4286                    qPos.add(status);
4287    
4288                    if (orderByComparator != null) {
4289                            Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
4290    
4291                            for (Object value : values) {
4292                                    qPos.add(value);
4293                            }
4294                    }
4295    
4296                    List<WikiNode> list = q.list();
4297    
4298                    if (list.size() == 2) {
4299                            return list.get(1);
4300                    }
4301                    else {
4302                            return null;
4303                    }
4304            }
4305    
4306            /**
4307             * Removes all the wiki nodes where companyId = &#63; and status = &#63; from the database.
4308             *
4309             * @param companyId the company ID
4310             * @param status the status
4311             * @throws SystemException if a system exception occurred
4312             */
4313            public void removeByC_S(long companyId, int status)
4314                    throws SystemException {
4315                    for (WikiNode wikiNode : findByC_S(companyId, status,
4316                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4317                            remove(wikiNode);
4318                    }
4319            }
4320    
4321            /**
4322             * Returns the number of wiki nodes where companyId = &#63; and status = &#63;.
4323             *
4324             * @param companyId the company ID
4325             * @param status the status
4326             * @return the number of matching wiki nodes
4327             * @throws SystemException if a system exception occurred
4328             */
4329            public int countByC_S(long companyId, int status) throws SystemException {
4330                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
4331    
4332                    Object[] finderArgs = new Object[] { companyId, status };
4333    
4334                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4335                                    this);
4336    
4337                    if (count == null) {
4338                            StringBundler query = new StringBundler(3);
4339    
4340                            query.append(_SQL_COUNT_WIKINODE_WHERE);
4341    
4342                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
4343    
4344                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
4345    
4346                            String sql = query.toString();
4347    
4348                            Session session = null;
4349    
4350                            try {
4351                                    session = openSession();
4352    
4353                                    Query q = session.createQuery(sql);
4354    
4355                                    QueryPos qPos = QueryPos.getInstance(q);
4356    
4357                                    qPos.add(companyId);
4358    
4359                                    qPos.add(status);
4360    
4361                                    count = (Long)q.uniqueResult();
4362    
4363                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4364                            }
4365                            catch (Exception e) {
4366                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4367    
4368                                    throw processException(e);
4369                            }
4370                            finally {
4371                                    closeSession(session);
4372                            }
4373                    }
4374    
4375                    return count.intValue();
4376            }
4377    
4378            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "wikiNode.companyId = ? AND ";
4379            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "wikiNode.status = ?";
4380    
4381            /**
4382             * Caches the wiki node in the entity cache if it is enabled.
4383             *
4384             * @param wikiNode the wiki node
4385             */
4386            public void cacheResult(WikiNode wikiNode) {
4387                    EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
4388                            WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
4389    
4390                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
4391                            new Object[] { wikiNode.getUuid(), wikiNode.getGroupId() }, wikiNode);
4392    
4393                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
4394                            new Object[] { wikiNode.getGroupId(), wikiNode.getName() }, wikiNode);
4395    
4396                    wikiNode.resetOriginalValues();
4397            }
4398    
4399            /**
4400             * Caches the wiki nodes in the entity cache if it is enabled.
4401             *
4402             * @param wikiNodes the wiki nodes
4403             */
4404            public void cacheResult(List<WikiNode> wikiNodes) {
4405                    for (WikiNode wikiNode : wikiNodes) {
4406                            if (EntityCacheUtil.getResult(
4407                                                    WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
4408                                                    WikiNodeImpl.class, wikiNode.getPrimaryKey()) == null) {
4409                                    cacheResult(wikiNode);
4410                            }
4411                            else {
4412                                    wikiNode.resetOriginalValues();
4413                            }
4414                    }
4415            }
4416    
4417            /**
4418             * Clears the cache for all wiki nodes.
4419             *
4420             * <p>
4421             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4422             * </p>
4423             */
4424            @Override
4425            public void clearCache() {
4426                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
4427                            CacheRegistryUtil.clear(WikiNodeImpl.class.getName());
4428                    }
4429    
4430                    EntityCacheUtil.clearCache(WikiNodeImpl.class.getName());
4431    
4432                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
4433                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4434                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4435            }
4436    
4437            /**
4438             * Clears the cache for the wiki node.
4439             *
4440             * <p>
4441             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4442             * </p>
4443             */
4444            @Override
4445            public void clearCache(WikiNode wikiNode) {
4446                    EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
4447                            WikiNodeImpl.class, wikiNode.getPrimaryKey());
4448    
4449                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4450                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4451    
4452                    clearUniqueFindersCache(wikiNode);
4453            }
4454    
4455            @Override
4456            public void clearCache(List<WikiNode> wikiNodes) {
4457                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4458                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4459    
4460                    for (WikiNode wikiNode : wikiNodes) {
4461                            EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
4462                                    WikiNodeImpl.class, wikiNode.getPrimaryKey());
4463    
4464                            clearUniqueFindersCache(wikiNode);
4465                    }
4466            }
4467    
4468            protected void cacheUniqueFindersCache(WikiNode wikiNode) {
4469                    if (wikiNode.isNew()) {
4470                            Object[] args = new Object[] {
4471                                            wikiNode.getUuid(), wikiNode.getGroupId()
4472                                    };
4473    
4474                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4475                                    Long.valueOf(1));
4476                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4477                                    wikiNode);
4478    
4479                            args = new Object[] { wikiNode.getGroupId(), wikiNode.getName() };
4480    
4481                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
4482                                    Long.valueOf(1));
4483                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args, wikiNode);
4484                    }
4485                    else {
4486                            WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
4487    
4488                            if ((wikiNodeModelImpl.getColumnBitmask() &
4489                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4490                                    Object[] args = new Object[] {
4491                                                    wikiNode.getUuid(), wikiNode.getGroupId()
4492                                            };
4493    
4494                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4495                                            Long.valueOf(1));
4496                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4497                                            wikiNode);
4498                            }
4499    
4500                            if ((wikiNodeModelImpl.getColumnBitmask() &
4501                                            FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
4502                                    Object[] args = new Object[] {
4503                                                    wikiNode.getGroupId(), wikiNode.getName()
4504                                            };
4505    
4506                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
4507                                            Long.valueOf(1));
4508                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args,
4509                                            wikiNode);
4510                            }
4511                    }
4512            }
4513    
4514            protected void clearUniqueFindersCache(WikiNode wikiNode) {
4515                    WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
4516    
4517                    Object[] args = new Object[] { wikiNode.getUuid(), wikiNode.getGroupId() };
4518    
4519                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4520                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4521    
4522                    if ((wikiNodeModelImpl.getColumnBitmask() &
4523                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4524                            args = new Object[] {
4525                                            wikiNodeModelImpl.getOriginalUuid(),
4526                                            wikiNodeModelImpl.getOriginalGroupId()
4527                                    };
4528    
4529                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4530                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4531                    }
4532    
4533                    args = new Object[] { wikiNode.getGroupId(), wikiNode.getName() };
4534    
4535                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
4536                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
4537    
4538                    if ((wikiNodeModelImpl.getColumnBitmask() &
4539                                    FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
4540                            args = new Object[] {
4541                                            wikiNodeModelImpl.getOriginalGroupId(),
4542                                            wikiNodeModelImpl.getOriginalName()
4543                                    };
4544    
4545                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
4546                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
4547                    }
4548            }
4549    
4550            /**
4551             * Creates a new wiki node with the primary key. Does not add the wiki node to the database.
4552             *
4553             * @param nodeId the primary key for the new wiki node
4554             * @return the new wiki node
4555             */
4556            public WikiNode create(long nodeId) {
4557                    WikiNode wikiNode = new WikiNodeImpl();
4558    
4559                    wikiNode.setNew(true);
4560                    wikiNode.setPrimaryKey(nodeId);
4561    
4562                    String uuid = PortalUUIDUtil.generate();
4563    
4564                    wikiNode.setUuid(uuid);
4565    
4566                    return wikiNode;
4567            }
4568    
4569            /**
4570             * Removes the wiki node with the primary key from the database. Also notifies the appropriate model listeners.
4571             *
4572             * @param nodeId the primary key of the wiki node
4573             * @return the wiki node that was removed
4574             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
4575             * @throws SystemException if a system exception occurred
4576             */
4577            public WikiNode remove(long nodeId)
4578                    throws NoSuchNodeException, SystemException {
4579                    return remove((Serializable)nodeId);
4580            }
4581    
4582            /**
4583             * Removes the wiki node with the primary key from the database. Also notifies the appropriate model listeners.
4584             *
4585             * @param primaryKey the primary key of the wiki node
4586             * @return the wiki node that was removed
4587             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
4588             * @throws SystemException if a system exception occurred
4589             */
4590            @Override
4591            public WikiNode remove(Serializable primaryKey)
4592                    throws NoSuchNodeException, SystemException {
4593                    Session session = null;
4594    
4595                    try {
4596                            session = openSession();
4597    
4598                            WikiNode wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
4599                                            primaryKey);
4600    
4601                            if (wikiNode == null) {
4602                                    if (_log.isWarnEnabled()) {
4603                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4604                                    }
4605    
4606                                    throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4607                                            primaryKey);
4608                            }
4609    
4610                            return remove(wikiNode);
4611                    }
4612                    catch (NoSuchNodeException nsee) {
4613                            throw nsee;
4614                    }
4615                    catch (Exception e) {
4616                            throw processException(e);
4617                    }
4618                    finally {
4619                            closeSession(session);
4620                    }
4621            }
4622    
4623            @Override
4624            protected WikiNode removeImpl(WikiNode wikiNode) throws SystemException {
4625                    wikiNode = toUnwrappedModel(wikiNode);
4626    
4627                    Session session = null;
4628    
4629                    try {
4630                            session = openSession();
4631    
4632                            if (!session.contains(wikiNode)) {
4633                                    wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
4634                                                    wikiNode.getPrimaryKeyObj());
4635                            }
4636    
4637                            if (wikiNode != null) {
4638                                    session.delete(wikiNode);
4639                            }
4640                    }
4641                    catch (Exception e) {
4642                            throw processException(e);
4643                    }
4644                    finally {
4645                            closeSession(session);
4646                    }
4647    
4648                    if (wikiNode != null) {
4649                            clearCache(wikiNode);
4650                    }
4651    
4652                    return wikiNode;
4653            }
4654    
4655            @Override
4656            public WikiNode updateImpl(com.liferay.portlet.wiki.model.WikiNode wikiNode)
4657                    throws SystemException {
4658                    wikiNode = toUnwrappedModel(wikiNode);
4659    
4660                    boolean isNew = wikiNode.isNew();
4661    
4662                    WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
4663    
4664                    if (Validator.isNull(wikiNode.getUuid())) {
4665                            String uuid = PortalUUIDUtil.generate();
4666    
4667                            wikiNode.setUuid(uuid);
4668                    }
4669    
4670                    Session session = null;
4671    
4672                    try {
4673                            session = openSession();
4674    
4675                            if (wikiNode.isNew()) {
4676                                    session.save(wikiNode);
4677    
4678                                    wikiNode.setNew(false);
4679                            }
4680                            else {
4681                                    session.merge(wikiNode);
4682                            }
4683                    }
4684                    catch (Exception e) {
4685                            throw processException(e);
4686                    }
4687                    finally {
4688                            closeSession(session);
4689                    }
4690    
4691                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4692    
4693                    if (isNew || !WikiNodeModelImpl.COLUMN_BITMASK_ENABLED) {
4694                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4695                    }
4696    
4697                    else {
4698                            if ((wikiNodeModelImpl.getColumnBitmask() &
4699                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4700                                    Object[] args = new Object[] { wikiNodeModelImpl.getOriginalUuid() };
4701    
4702                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4703                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4704                                            args);
4705    
4706                                    args = new Object[] { wikiNodeModelImpl.getUuid() };
4707    
4708                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4709                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4710                                            args);
4711                            }
4712    
4713                            if ((wikiNodeModelImpl.getColumnBitmask() &
4714                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4715                                    Object[] args = new Object[] {
4716                                                    wikiNodeModelImpl.getOriginalUuid(),
4717                                                    wikiNodeModelImpl.getOriginalCompanyId()
4718                                            };
4719    
4720                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4721                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4722                                            args);
4723    
4724                                    args = new Object[] {
4725                                                    wikiNodeModelImpl.getUuid(),
4726                                                    wikiNodeModelImpl.getCompanyId()
4727                                            };
4728    
4729                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4730                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4731                                            args);
4732                            }
4733    
4734                            if ((wikiNodeModelImpl.getColumnBitmask() &
4735                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
4736                                    Object[] args = new Object[] {
4737                                                    wikiNodeModelImpl.getOriginalGroupId()
4738                                            };
4739    
4740                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
4741                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
4742                                            args);
4743    
4744                                    args = new Object[] { wikiNodeModelImpl.getGroupId() };
4745    
4746                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
4747                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
4748                                            args);
4749                            }
4750    
4751                            if ((wikiNodeModelImpl.getColumnBitmask() &
4752                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
4753                                    Object[] args = new Object[] {
4754                                                    wikiNodeModelImpl.getOriginalCompanyId()
4755                                            };
4756    
4757                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4758                                            args);
4759                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4760                                            args);
4761    
4762                                    args = new Object[] { wikiNodeModelImpl.getCompanyId() };
4763    
4764                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4765                                            args);
4766                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4767                                            args);
4768                            }
4769    
4770                            if ((wikiNodeModelImpl.getColumnBitmask() &
4771                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
4772                                    Object[] args = new Object[] {
4773                                                    wikiNodeModelImpl.getOriginalGroupId(),
4774                                                    wikiNodeModelImpl.getOriginalStatus()
4775                                            };
4776    
4777                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
4778                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
4779                                            args);
4780    
4781                                    args = new Object[] {
4782                                                    wikiNodeModelImpl.getGroupId(),
4783                                                    wikiNodeModelImpl.getStatus()
4784                                            };
4785    
4786                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
4787                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
4788                                            args);
4789                            }
4790    
4791                            if ((wikiNodeModelImpl.getColumnBitmask() &
4792                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
4793                                    Object[] args = new Object[] {
4794                                                    wikiNodeModelImpl.getOriginalCompanyId(),
4795                                                    wikiNodeModelImpl.getOriginalStatus()
4796                                            };
4797    
4798                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
4799                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
4800                                            args);
4801    
4802                                    args = new Object[] {
4803                                                    wikiNodeModelImpl.getCompanyId(),
4804                                                    wikiNodeModelImpl.getStatus()
4805                                            };
4806    
4807                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
4808                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
4809                                            args);
4810                            }
4811                    }
4812    
4813                    EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
4814                            WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
4815    
4816                    clearUniqueFindersCache(wikiNode);
4817                    cacheUniqueFindersCache(wikiNode);
4818    
4819                    return wikiNode;
4820            }
4821    
4822            protected WikiNode toUnwrappedModel(WikiNode wikiNode) {
4823                    if (wikiNode instanceof WikiNodeImpl) {
4824                            return wikiNode;
4825                    }
4826    
4827                    WikiNodeImpl wikiNodeImpl = new WikiNodeImpl();
4828    
4829                    wikiNodeImpl.setNew(wikiNode.isNew());
4830                    wikiNodeImpl.setPrimaryKey(wikiNode.getPrimaryKey());
4831    
4832                    wikiNodeImpl.setUuid(wikiNode.getUuid());
4833                    wikiNodeImpl.setNodeId(wikiNode.getNodeId());
4834                    wikiNodeImpl.setGroupId(wikiNode.getGroupId());
4835                    wikiNodeImpl.setCompanyId(wikiNode.getCompanyId());
4836                    wikiNodeImpl.setUserId(wikiNode.getUserId());
4837                    wikiNodeImpl.setUserName(wikiNode.getUserName());
4838                    wikiNodeImpl.setCreateDate(wikiNode.getCreateDate());
4839                    wikiNodeImpl.setModifiedDate(wikiNode.getModifiedDate());
4840                    wikiNodeImpl.setName(wikiNode.getName());
4841                    wikiNodeImpl.setDescription(wikiNode.getDescription());
4842                    wikiNodeImpl.setLastPostDate(wikiNode.getLastPostDate());
4843                    wikiNodeImpl.setStatus(wikiNode.getStatus());
4844                    wikiNodeImpl.setStatusByUserId(wikiNode.getStatusByUserId());
4845                    wikiNodeImpl.setStatusByUserName(wikiNode.getStatusByUserName());
4846                    wikiNodeImpl.setStatusDate(wikiNode.getStatusDate());
4847    
4848                    return wikiNodeImpl;
4849            }
4850    
4851            /**
4852             * Returns the wiki node with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
4853             *
4854             * @param primaryKey the primary key of the wiki node
4855             * @return the wiki node
4856             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
4857             * @throws SystemException if a system exception occurred
4858             */
4859            @Override
4860            public WikiNode findByPrimaryKey(Serializable primaryKey)
4861                    throws NoSuchNodeException, SystemException {
4862                    WikiNode wikiNode = fetchByPrimaryKey(primaryKey);
4863    
4864                    if (wikiNode == null) {
4865                            if (_log.isWarnEnabled()) {
4866                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4867                            }
4868    
4869                            throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4870                                    primaryKey);
4871                    }
4872    
4873                    return wikiNode;
4874            }
4875    
4876            /**
4877             * Returns the wiki node with the primary key or throws a {@link com.liferay.portlet.wiki.NoSuchNodeException} if it could not be found.
4878             *
4879             * @param nodeId the primary key of the wiki node
4880             * @return the wiki node
4881             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
4882             * @throws SystemException if a system exception occurred
4883             */
4884            public WikiNode findByPrimaryKey(long nodeId)
4885                    throws NoSuchNodeException, SystemException {
4886                    return findByPrimaryKey((Serializable)nodeId);
4887            }
4888    
4889            /**
4890             * Returns the wiki node with the primary key or returns <code>null</code> if it could not be found.
4891             *
4892             * @param primaryKey the primary key of the wiki node
4893             * @return the wiki node, or <code>null</code> if a wiki node with the primary key could not be found
4894             * @throws SystemException if a system exception occurred
4895             */
4896            @Override
4897            public WikiNode fetchByPrimaryKey(Serializable primaryKey)
4898                    throws SystemException {
4899                    WikiNode wikiNode = (WikiNode)EntityCacheUtil.getResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
4900                                    WikiNodeImpl.class, primaryKey);
4901    
4902                    if (wikiNode == _nullWikiNode) {
4903                            return null;
4904                    }
4905    
4906                    if (wikiNode == null) {
4907                            Session session = null;
4908    
4909                            try {
4910                                    session = openSession();
4911    
4912                                    wikiNode = (WikiNode)session.get(WikiNodeImpl.class, primaryKey);
4913    
4914                                    if (wikiNode != null) {
4915                                            cacheResult(wikiNode);
4916                                    }
4917                                    else {
4918                                            EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
4919                                                    WikiNodeImpl.class, primaryKey, _nullWikiNode);
4920                                    }
4921                            }
4922                            catch (Exception e) {
4923                                    EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
4924                                            WikiNodeImpl.class, primaryKey);
4925    
4926                                    throw processException(e);
4927                            }
4928                            finally {
4929                                    closeSession(session);
4930                            }
4931                    }
4932    
4933                    return wikiNode;
4934            }
4935    
4936            /**
4937             * Returns the wiki node with the primary key or returns <code>null</code> if it could not be found.
4938             *
4939             * @param nodeId the primary key of the wiki node
4940             * @return the wiki node, or <code>null</code> if a wiki node with the primary key could not be found
4941             * @throws SystemException if a system exception occurred
4942             */
4943            public WikiNode fetchByPrimaryKey(long nodeId) throws SystemException {
4944                    return fetchByPrimaryKey((Serializable)nodeId);
4945            }
4946    
4947            /**
4948             * Returns all the wiki nodes.
4949             *
4950             * @return the wiki nodes
4951             * @throws SystemException if a system exception occurred
4952             */
4953            public List<WikiNode> findAll() throws SystemException {
4954                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4955            }
4956    
4957            /**
4958             * Returns a range of all the wiki nodes.
4959             *
4960             * <p>
4961             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4962             * </p>
4963             *
4964             * @param start the lower bound of the range of wiki nodes
4965             * @param end the upper bound of the range of wiki nodes (not inclusive)
4966             * @return the range of wiki nodes
4967             * @throws SystemException if a system exception occurred
4968             */
4969            public List<WikiNode> findAll(int start, int end) throws SystemException {
4970                    return findAll(start, end, null);
4971            }
4972    
4973            /**
4974             * Returns an ordered range of all the wiki nodes.
4975             *
4976             * <p>
4977             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4978             * </p>
4979             *
4980             * @param start the lower bound of the range of wiki nodes
4981             * @param end the upper bound of the range of wiki nodes (not inclusive)
4982             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4983             * @return the ordered range of wiki nodes
4984             * @throws SystemException if a system exception occurred
4985             */
4986            public List<WikiNode> findAll(int start, int end,
4987                    OrderByComparator orderByComparator) throws SystemException {
4988                    boolean pagination = true;
4989                    FinderPath finderPath = null;
4990                    Object[] finderArgs = null;
4991    
4992                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4993                                    (orderByComparator == null)) {
4994                            pagination = false;
4995                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4996                            finderArgs = FINDER_ARGS_EMPTY;
4997                    }
4998                    else {
4999                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5000                            finderArgs = new Object[] { start, end, orderByComparator };
5001                    }
5002    
5003                    List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
5004                                    finderArgs, this);
5005    
5006                    if (list == null) {
5007                            StringBundler query = null;
5008                            String sql = null;
5009    
5010                            if (orderByComparator != null) {
5011                                    query = new StringBundler(2 +
5012                                                    (orderByComparator.getOrderByFields().length * 3));
5013    
5014                                    query.append(_SQL_SELECT_WIKINODE);
5015    
5016                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5017                                            orderByComparator);
5018    
5019                                    sql = query.toString();
5020                            }
5021                            else {
5022                                    sql = _SQL_SELECT_WIKINODE;
5023    
5024                                    if (pagination) {
5025                                            sql = sql.concat(WikiNodeModelImpl.ORDER_BY_JPQL);
5026                                    }
5027                            }
5028    
5029                            Session session = null;
5030    
5031                            try {
5032                                    session = openSession();
5033    
5034                                    Query q = session.createQuery(sql);
5035    
5036                                    if (!pagination) {
5037                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
5038                                                            start, end, false);
5039    
5040                                            Collections.sort(list);
5041    
5042                                            list = new UnmodifiableList<WikiNode>(list);
5043                                    }
5044                                    else {
5045                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
5046                                                            start, end);
5047                                    }
5048    
5049                                    cacheResult(list);
5050    
5051                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5052                            }
5053                            catch (Exception e) {
5054                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5055    
5056                                    throw processException(e);
5057                            }
5058                            finally {
5059                                    closeSession(session);
5060                            }
5061                    }
5062    
5063                    return list;
5064            }
5065    
5066            /**
5067             * Removes all the wiki nodes from the database.
5068             *
5069             * @throws SystemException if a system exception occurred
5070             */
5071            public void removeAll() throws SystemException {
5072                    for (WikiNode wikiNode : findAll()) {
5073                            remove(wikiNode);
5074                    }
5075            }
5076    
5077            /**
5078             * Returns the number of wiki nodes.
5079             *
5080             * @return the number of wiki nodes
5081             * @throws SystemException if a system exception occurred
5082             */
5083            public int countAll() throws SystemException {
5084                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5085                                    FINDER_ARGS_EMPTY, this);
5086    
5087                    if (count == null) {
5088                            Session session = null;
5089    
5090                            try {
5091                                    session = openSession();
5092    
5093                                    Query q = session.createQuery(_SQL_COUNT_WIKINODE);
5094    
5095                                    count = (Long)q.uniqueResult();
5096    
5097                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5098                                            FINDER_ARGS_EMPTY, count);
5099                            }
5100                            catch (Exception e) {
5101                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
5102                                            FINDER_ARGS_EMPTY);
5103    
5104                                    throw processException(e);
5105                            }
5106                            finally {
5107                                    closeSession(session);
5108                            }
5109                    }
5110    
5111                    return count.intValue();
5112            }
5113    
5114            /**
5115             * Initializes the wiki node persistence.
5116             */
5117            public void afterPropertiesSet() {
5118                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5119                                            com.liferay.portal.util.PropsUtil.get(
5120                                                    "value.object.listener.com.liferay.portlet.wiki.model.WikiNode")));
5121    
5122                    if (listenerClassNames.length > 0) {
5123                            try {
5124                                    List<ModelListener<WikiNode>> listenersList = new ArrayList<ModelListener<WikiNode>>();
5125    
5126                                    for (String listenerClassName : listenerClassNames) {
5127                                            listenersList.add((ModelListener<WikiNode>)InstanceFactory.newInstance(
5128                                                            listenerClassName));
5129                                    }
5130    
5131                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5132                            }
5133                            catch (Exception e) {
5134                                    _log.error(e);
5135                            }
5136                    }
5137            }
5138    
5139            public void destroy() {
5140                    EntityCacheUtil.removeCache(WikiNodeImpl.class.getName());
5141                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5142                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5143                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5144            }
5145    
5146            private static final String _SQL_SELECT_WIKINODE = "SELECT wikiNode FROM WikiNode wikiNode";
5147            private static final String _SQL_SELECT_WIKINODE_WHERE = "SELECT wikiNode FROM WikiNode wikiNode WHERE ";
5148            private static final String _SQL_COUNT_WIKINODE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode";
5149            private static final String _SQL_COUNT_WIKINODE_WHERE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode WHERE ";
5150            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "wikiNode.nodeId";
5151            private static final String _FILTER_SQL_SELECT_WIKINODE_WHERE = "SELECT DISTINCT {wikiNode.*} FROM WikiNode wikiNode WHERE ";
5152            private static final String _FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_1 =
5153                    "SELECT {WikiNode.*} FROM (SELECT DISTINCT wikiNode.nodeId FROM WikiNode wikiNode WHERE ";
5154            private static final String _FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_2 =
5155                    ") TEMP_TABLE INNER JOIN WikiNode ON TEMP_TABLE.nodeId = WikiNode.nodeId";
5156            private static final String _FILTER_SQL_COUNT_WIKINODE_WHERE = "SELECT COUNT(DISTINCT wikiNode.nodeId) AS COUNT_VALUE FROM WikiNode wikiNode WHERE ";
5157            private static final String _FILTER_ENTITY_ALIAS = "wikiNode";
5158            private static final String _FILTER_ENTITY_TABLE = "WikiNode";
5159            private static final String _ORDER_BY_ENTITY_ALIAS = "wikiNode.";
5160            private static final String _ORDER_BY_ENTITY_TABLE = "WikiNode.";
5161            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiNode exists with the primary key ";
5162            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiNode exists with the key {";
5163            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5164            private static Log _log = LogFactoryUtil.getLog(WikiNodePersistenceImpl.class);
5165            private static WikiNode _nullWikiNode = new WikiNodeImpl() {
5166                            @Override
5167                            public Object clone() {
5168                                    return this;
5169                            }
5170    
5171                            @Override
5172                            public CacheModel<WikiNode> toCacheModel() {
5173                                    return _nullWikiNodeCacheModel;
5174                            }
5175                    };
5176    
5177            private static CacheModel<WikiNode> _nullWikiNodeCacheModel = new CacheModel<WikiNode>() {
5178                            public WikiNode toEntityModel() {
5179                                    return _nullWikiNode;
5180                            }
5181                    };
5182    }