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