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