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            public WikiNodePersistenceImpl() {
4488                    setModelClass(WikiNode.class);
4489            }
4490    
4491            /**
4492             * Caches the wiki node in the entity cache if it is enabled.
4493             *
4494             * @param wikiNode the wiki node
4495             */
4496            @Override
4497            public void cacheResult(WikiNode wikiNode) {
4498                    EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
4499                            WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
4500    
4501                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
4502                            new Object[] { wikiNode.getUuid(), wikiNode.getGroupId() }, wikiNode);
4503    
4504                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
4505                            new Object[] { wikiNode.getGroupId(), wikiNode.getName() }, wikiNode);
4506    
4507                    wikiNode.resetOriginalValues();
4508            }
4509    
4510            /**
4511             * Caches the wiki nodes in the entity cache if it is enabled.
4512             *
4513             * @param wikiNodes the wiki nodes
4514             */
4515            @Override
4516            public void cacheResult(List<WikiNode> wikiNodes) {
4517                    for (WikiNode wikiNode : wikiNodes) {
4518                            if (EntityCacheUtil.getResult(
4519                                                    WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
4520                                                    WikiNodeImpl.class, wikiNode.getPrimaryKey()) == null) {
4521                                    cacheResult(wikiNode);
4522                            }
4523                            else {
4524                                    wikiNode.resetOriginalValues();
4525                            }
4526                    }
4527            }
4528    
4529            /**
4530             * Clears the cache for all wiki nodes.
4531             *
4532             * <p>
4533             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4534             * </p>
4535             */
4536            @Override
4537            public void clearCache() {
4538                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
4539                            CacheRegistryUtil.clear(WikiNodeImpl.class.getName());
4540                    }
4541    
4542                    EntityCacheUtil.clearCache(WikiNodeImpl.class.getName());
4543    
4544                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
4545                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4546                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4547            }
4548    
4549            /**
4550             * Clears the cache for the wiki node.
4551             *
4552             * <p>
4553             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4554             * </p>
4555             */
4556            @Override
4557            public void clearCache(WikiNode wikiNode) {
4558                    EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
4559                            WikiNodeImpl.class, wikiNode.getPrimaryKey());
4560    
4561                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4562                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4563    
4564                    clearUniqueFindersCache(wikiNode);
4565            }
4566    
4567            @Override
4568            public void clearCache(List<WikiNode> wikiNodes) {
4569                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4570                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4571    
4572                    for (WikiNode wikiNode : wikiNodes) {
4573                            EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
4574                                    WikiNodeImpl.class, wikiNode.getPrimaryKey());
4575    
4576                            clearUniqueFindersCache(wikiNode);
4577                    }
4578            }
4579    
4580            protected void cacheUniqueFindersCache(WikiNode wikiNode) {
4581                    if (wikiNode.isNew()) {
4582                            Object[] args = new Object[] {
4583                                            wikiNode.getUuid(), wikiNode.getGroupId()
4584                                    };
4585    
4586                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4587                                    Long.valueOf(1));
4588                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4589                                    wikiNode);
4590    
4591                            args = new Object[] { wikiNode.getGroupId(), wikiNode.getName() };
4592    
4593                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
4594                                    Long.valueOf(1));
4595                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args, wikiNode);
4596                    }
4597                    else {
4598                            WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
4599    
4600                            if ((wikiNodeModelImpl.getColumnBitmask() &
4601                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4602                                    Object[] args = new Object[] {
4603                                                    wikiNode.getUuid(), wikiNode.getGroupId()
4604                                            };
4605    
4606                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4607                                            Long.valueOf(1));
4608                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4609                                            wikiNode);
4610                            }
4611    
4612                            if ((wikiNodeModelImpl.getColumnBitmask() &
4613                                            FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
4614                                    Object[] args = new Object[] {
4615                                                    wikiNode.getGroupId(), wikiNode.getName()
4616                                            };
4617    
4618                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
4619                                            Long.valueOf(1));
4620                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args,
4621                                            wikiNode);
4622                            }
4623                    }
4624            }
4625    
4626            protected void clearUniqueFindersCache(WikiNode wikiNode) {
4627                    WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
4628    
4629                    Object[] args = new Object[] { wikiNode.getUuid(), wikiNode.getGroupId() };
4630    
4631                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4632                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4633    
4634                    if ((wikiNodeModelImpl.getColumnBitmask() &
4635                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4636                            args = new Object[] {
4637                                            wikiNodeModelImpl.getOriginalUuid(),
4638                                            wikiNodeModelImpl.getOriginalGroupId()
4639                                    };
4640    
4641                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4642                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4643                    }
4644    
4645                    args = new Object[] { wikiNode.getGroupId(), wikiNode.getName() };
4646    
4647                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
4648                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
4649    
4650                    if ((wikiNodeModelImpl.getColumnBitmask() &
4651                                    FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
4652                            args = new Object[] {
4653                                            wikiNodeModelImpl.getOriginalGroupId(),
4654                                            wikiNodeModelImpl.getOriginalName()
4655                                    };
4656    
4657                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
4658                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
4659                    }
4660            }
4661    
4662            /**
4663             * Creates a new wiki node with the primary key. Does not add the wiki node to the database.
4664             *
4665             * @param nodeId the primary key for the new wiki node
4666             * @return the new wiki node
4667             */
4668            @Override
4669            public WikiNode create(long nodeId) {
4670                    WikiNode wikiNode = new WikiNodeImpl();
4671    
4672                    wikiNode.setNew(true);
4673                    wikiNode.setPrimaryKey(nodeId);
4674    
4675                    String uuid = PortalUUIDUtil.generate();
4676    
4677                    wikiNode.setUuid(uuid);
4678    
4679                    return wikiNode;
4680            }
4681    
4682            /**
4683             * Removes the wiki node with the primary key from the database. Also notifies the appropriate model listeners.
4684             *
4685             * @param nodeId the primary key of the wiki node
4686             * @return the wiki node that was removed
4687             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
4688             * @throws SystemException if a system exception occurred
4689             */
4690            @Override
4691            public WikiNode remove(long nodeId)
4692                    throws NoSuchNodeException, SystemException {
4693                    return remove((Serializable)nodeId);
4694            }
4695    
4696            /**
4697             * Removes the wiki node with the primary key from the database. Also notifies the appropriate model listeners.
4698             *
4699             * @param primaryKey the primary key of the wiki node
4700             * @return the wiki node that was removed
4701             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
4702             * @throws SystemException if a system exception occurred
4703             */
4704            @Override
4705            public WikiNode remove(Serializable primaryKey)
4706                    throws NoSuchNodeException, SystemException {
4707                    Session session = null;
4708    
4709                    try {
4710                            session = openSession();
4711    
4712                            WikiNode wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
4713                                            primaryKey);
4714    
4715                            if (wikiNode == null) {
4716                                    if (_log.isWarnEnabled()) {
4717                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4718                                    }
4719    
4720                                    throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4721                                            primaryKey);
4722                            }
4723    
4724                            return remove(wikiNode);
4725                    }
4726                    catch (NoSuchNodeException nsee) {
4727                            throw nsee;
4728                    }
4729                    catch (Exception e) {
4730                            throw processException(e);
4731                    }
4732                    finally {
4733                            closeSession(session);
4734                    }
4735            }
4736    
4737            @Override
4738            protected WikiNode removeImpl(WikiNode wikiNode) throws SystemException {
4739                    wikiNode = toUnwrappedModel(wikiNode);
4740    
4741                    Session session = null;
4742    
4743                    try {
4744                            session = openSession();
4745    
4746                            if (!session.contains(wikiNode)) {
4747                                    wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
4748                                                    wikiNode.getPrimaryKeyObj());
4749                            }
4750    
4751                            if (wikiNode != null) {
4752                                    session.delete(wikiNode);
4753                            }
4754                    }
4755                    catch (Exception e) {
4756                            throw processException(e);
4757                    }
4758                    finally {
4759                            closeSession(session);
4760                    }
4761    
4762                    if (wikiNode != null) {
4763                            clearCache(wikiNode);
4764                    }
4765    
4766                    return wikiNode;
4767            }
4768    
4769            @Override
4770            public WikiNode updateImpl(com.liferay.portlet.wiki.model.WikiNode wikiNode)
4771                    throws SystemException {
4772                    wikiNode = toUnwrappedModel(wikiNode);
4773    
4774                    boolean isNew = wikiNode.isNew();
4775    
4776                    WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
4777    
4778                    if (Validator.isNull(wikiNode.getUuid())) {
4779                            String uuid = PortalUUIDUtil.generate();
4780    
4781                            wikiNode.setUuid(uuid);
4782                    }
4783    
4784                    Session session = null;
4785    
4786                    try {
4787                            session = openSession();
4788    
4789                            if (wikiNode.isNew()) {
4790                                    session.save(wikiNode);
4791    
4792                                    wikiNode.setNew(false);
4793                            }
4794                            else {
4795                                    session.merge(wikiNode);
4796                            }
4797                    }
4798                    catch (Exception e) {
4799                            throw processException(e);
4800                    }
4801                    finally {
4802                            closeSession(session);
4803                    }
4804    
4805                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4806    
4807                    if (isNew || !WikiNodeModelImpl.COLUMN_BITMASK_ENABLED) {
4808                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4809                    }
4810    
4811                    else {
4812                            if ((wikiNodeModelImpl.getColumnBitmask() &
4813                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4814                                    Object[] args = new Object[] { wikiNodeModelImpl.getOriginalUuid() };
4815    
4816                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4817                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4818                                            args);
4819    
4820                                    args = new Object[] { wikiNodeModelImpl.getUuid() };
4821    
4822                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4823                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4824                                            args);
4825                            }
4826    
4827                            if ((wikiNodeModelImpl.getColumnBitmask() &
4828                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4829                                    Object[] args = new Object[] {
4830                                                    wikiNodeModelImpl.getOriginalUuid(),
4831                                                    wikiNodeModelImpl.getOriginalCompanyId()
4832                                            };
4833    
4834                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4835                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4836                                            args);
4837    
4838                                    args = new Object[] {
4839                                                    wikiNodeModelImpl.getUuid(),
4840                                                    wikiNodeModelImpl.getCompanyId()
4841                                            };
4842    
4843                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4844                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4845                                            args);
4846                            }
4847    
4848                            if ((wikiNodeModelImpl.getColumnBitmask() &
4849                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
4850                                    Object[] args = new Object[] {
4851                                                    wikiNodeModelImpl.getOriginalGroupId()
4852                                            };
4853    
4854                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
4855                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
4856                                            args);
4857    
4858                                    args = new Object[] { wikiNodeModelImpl.getGroupId() };
4859    
4860                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
4861                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
4862                                            args);
4863                            }
4864    
4865                            if ((wikiNodeModelImpl.getColumnBitmask() &
4866                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
4867                                    Object[] args = new Object[] {
4868                                                    wikiNodeModelImpl.getOriginalCompanyId()
4869                                            };
4870    
4871                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4872                                            args);
4873                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4874                                            args);
4875    
4876                                    args = new Object[] { wikiNodeModelImpl.getCompanyId() };
4877    
4878                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4879                                            args);
4880                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4881                                            args);
4882                            }
4883    
4884                            if ((wikiNodeModelImpl.getColumnBitmask() &
4885                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
4886                                    Object[] args = new Object[] {
4887                                                    wikiNodeModelImpl.getOriginalGroupId(),
4888                                                    wikiNodeModelImpl.getOriginalStatus()
4889                                            };
4890    
4891                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
4892                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
4893                                            args);
4894    
4895                                    args = new Object[] {
4896                                                    wikiNodeModelImpl.getGroupId(),
4897                                                    wikiNodeModelImpl.getStatus()
4898                                            };
4899    
4900                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
4901                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
4902                                            args);
4903                            }
4904    
4905                            if ((wikiNodeModelImpl.getColumnBitmask() &
4906                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
4907                                    Object[] args = new Object[] {
4908                                                    wikiNodeModelImpl.getOriginalCompanyId(),
4909                                                    wikiNodeModelImpl.getOriginalStatus()
4910                                            };
4911    
4912                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
4913                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
4914                                            args);
4915    
4916                                    args = new Object[] {
4917                                                    wikiNodeModelImpl.getCompanyId(),
4918                                                    wikiNodeModelImpl.getStatus()
4919                                            };
4920    
4921                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
4922                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
4923                                            args);
4924                            }
4925                    }
4926    
4927                    EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
4928                            WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
4929    
4930                    clearUniqueFindersCache(wikiNode);
4931                    cacheUniqueFindersCache(wikiNode);
4932    
4933                    return wikiNode;
4934            }
4935    
4936            protected WikiNode toUnwrappedModel(WikiNode wikiNode) {
4937                    if (wikiNode instanceof WikiNodeImpl) {
4938                            return wikiNode;
4939                    }
4940    
4941                    WikiNodeImpl wikiNodeImpl = new WikiNodeImpl();
4942    
4943                    wikiNodeImpl.setNew(wikiNode.isNew());
4944                    wikiNodeImpl.setPrimaryKey(wikiNode.getPrimaryKey());
4945    
4946                    wikiNodeImpl.setUuid(wikiNode.getUuid());
4947                    wikiNodeImpl.setNodeId(wikiNode.getNodeId());
4948                    wikiNodeImpl.setGroupId(wikiNode.getGroupId());
4949                    wikiNodeImpl.setCompanyId(wikiNode.getCompanyId());
4950                    wikiNodeImpl.setUserId(wikiNode.getUserId());
4951                    wikiNodeImpl.setUserName(wikiNode.getUserName());
4952                    wikiNodeImpl.setCreateDate(wikiNode.getCreateDate());
4953                    wikiNodeImpl.setModifiedDate(wikiNode.getModifiedDate());
4954                    wikiNodeImpl.setName(wikiNode.getName());
4955                    wikiNodeImpl.setDescription(wikiNode.getDescription());
4956                    wikiNodeImpl.setLastPostDate(wikiNode.getLastPostDate());
4957                    wikiNodeImpl.setStatus(wikiNode.getStatus());
4958                    wikiNodeImpl.setStatusByUserId(wikiNode.getStatusByUserId());
4959                    wikiNodeImpl.setStatusByUserName(wikiNode.getStatusByUserName());
4960                    wikiNodeImpl.setStatusDate(wikiNode.getStatusDate());
4961    
4962                    return wikiNodeImpl;
4963            }
4964    
4965            /**
4966             * Returns the wiki node with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
4967             *
4968             * @param primaryKey the primary key of the wiki node
4969             * @return the wiki node
4970             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
4971             * @throws SystemException if a system exception occurred
4972             */
4973            @Override
4974            public WikiNode findByPrimaryKey(Serializable primaryKey)
4975                    throws NoSuchNodeException, SystemException {
4976                    WikiNode wikiNode = fetchByPrimaryKey(primaryKey);
4977    
4978                    if (wikiNode == null) {
4979                            if (_log.isWarnEnabled()) {
4980                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4981                            }
4982    
4983                            throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4984                                    primaryKey);
4985                    }
4986    
4987                    return wikiNode;
4988            }
4989    
4990            /**
4991             * Returns the wiki node with the primary key or throws a {@link com.liferay.portlet.wiki.NoSuchNodeException} if it could not be found.
4992             *
4993             * @param nodeId the primary key of the wiki node
4994             * @return the wiki node
4995             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
4996             * @throws SystemException if a system exception occurred
4997             */
4998            @Override
4999            public WikiNode findByPrimaryKey(long nodeId)
5000                    throws NoSuchNodeException, SystemException {
5001                    return findByPrimaryKey((Serializable)nodeId);
5002            }
5003    
5004            /**
5005             * Returns the wiki node with the primary key or returns <code>null</code> if it could not be found.
5006             *
5007             * @param primaryKey the primary key of the wiki node
5008             * @return the wiki node, or <code>null</code> if a wiki node with the primary key could not be found
5009             * @throws SystemException if a system exception occurred
5010             */
5011            @Override
5012            public WikiNode fetchByPrimaryKey(Serializable primaryKey)
5013                    throws SystemException {
5014                    WikiNode wikiNode = (WikiNode)EntityCacheUtil.getResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
5015                                    WikiNodeImpl.class, primaryKey);
5016    
5017                    if (wikiNode == _nullWikiNode) {
5018                            return null;
5019                    }
5020    
5021                    if (wikiNode == null) {
5022                            Session session = null;
5023    
5024                            try {
5025                                    session = openSession();
5026    
5027                                    wikiNode = (WikiNode)session.get(WikiNodeImpl.class, primaryKey);
5028    
5029                                    if (wikiNode != null) {
5030                                            cacheResult(wikiNode);
5031                                    }
5032                                    else {
5033                                            EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
5034                                                    WikiNodeImpl.class, primaryKey, _nullWikiNode);
5035                                    }
5036                            }
5037                            catch (Exception e) {
5038                                    EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
5039                                            WikiNodeImpl.class, primaryKey);
5040    
5041                                    throw processException(e);
5042                            }
5043                            finally {
5044                                    closeSession(session);
5045                            }
5046                    }
5047    
5048                    return wikiNode;
5049            }
5050    
5051            /**
5052             * Returns the wiki node with the primary key or returns <code>null</code> if it could not be found.
5053             *
5054             * @param nodeId the primary key of the wiki node
5055             * @return the wiki node, or <code>null</code> if a wiki node with the primary key could not be found
5056             * @throws SystemException if a system exception occurred
5057             */
5058            @Override
5059            public WikiNode fetchByPrimaryKey(long nodeId) throws SystemException {
5060                    return fetchByPrimaryKey((Serializable)nodeId);
5061            }
5062    
5063            /**
5064             * Returns all the wiki nodes.
5065             *
5066             * @return the wiki nodes
5067             * @throws SystemException if a system exception occurred
5068             */
5069            @Override
5070            public List<WikiNode> findAll() throws SystemException {
5071                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5072            }
5073    
5074            /**
5075             * Returns a range of all the wiki nodes.
5076             *
5077             * <p>
5078             * 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.
5079             * </p>
5080             *
5081             * @param start the lower bound of the range of wiki nodes
5082             * @param end the upper bound of the range of wiki nodes (not inclusive)
5083             * @return the range of wiki nodes
5084             * @throws SystemException if a system exception occurred
5085             */
5086            @Override
5087            public List<WikiNode> findAll(int start, int end) throws SystemException {
5088                    return findAll(start, end, null);
5089            }
5090    
5091            /**
5092             * Returns an ordered range of all the wiki nodes.
5093             *
5094             * <p>
5095             * 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.
5096             * </p>
5097             *
5098             * @param start the lower bound of the range of wiki nodes
5099             * @param end the upper bound of the range of wiki nodes (not inclusive)
5100             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5101             * @return the ordered range of wiki nodes
5102             * @throws SystemException if a system exception occurred
5103             */
5104            @Override
5105            public List<WikiNode> findAll(int start, int end,
5106                    OrderByComparator orderByComparator) throws SystemException {
5107                    boolean pagination = true;
5108                    FinderPath finderPath = null;
5109                    Object[] finderArgs = null;
5110    
5111                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5112                                    (orderByComparator == null)) {
5113                            pagination = false;
5114                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5115                            finderArgs = FINDER_ARGS_EMPTY;
5116                    }
5117                    else {
5118                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5119                            finderArgs = new Object[] { start, end, orderByComparator };
5120                    }
5121    
5122                    List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
5123                                    finderArgs, this);
5124    
5125                    if (list == null) {
5126                            StringBundler query = null;
5127                            String sql = null;
5128    
5129                            if (orderByComparator != null) {
5130                                    query = new StringBundler(2 +
5131                                                    (orderByComparator.getOrderByFields().length * 3));
5132    
5133                                    query.append(_SQL_SELECT_WIKINODE);
5134    
5135                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5136                                            orderByComparator);
5137    
5138                                    sql = query.toString();
5139                            }
5140                            else {
5141                                    sql = _SQL_SELECT_WIKINODE;
5142    
5143                                    if (pagination) {
5144                                            sql = sql.concat(WikiNodeModelImpl.ORDER_BY_JPQL);
5145                                    }
5146                            }
5147    
5148                            Session session = null;
5149    
5150                            try {
5151                                    session = openSession();
5152    
5153                                    Query q = session.createQuery(sql);
5154    
5155                                    if (!pagination) {
5156                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
5157                                                            start, end, false);
5158    
5159                                            Collections.sort(list);
5160    
5161                                            list = new UnmodifiableList<WikiNode>(list);
5162                                    }
5163                                    else {
5164                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
5165                                                            start, end);
5166                                    }
5167    
5168                                    cacheResult(list);
5169    
5170                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5171                            }
5172                            catch (Exception e) {
5173                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5174    
5175                                    throw processException(e);
5176                            }
5177                            finally {
5178                                    closeSession(session);
5179                            }
5180                    }
5181    
5182                    return list;
5183            }
5184    
5185            /**
5186             * Removes all the wiki nodes from the database.
5187             *
5188             * @throws SystemException if a system exception occurred
5189             */
5190            @Override
5191            public void removeAll() throws SystemException {
5192                    for (WikiNode wikiNode : findAll()) {
5193                            remove(wikiNode);
5194                    }
5195            }
5196    
5197            /**
5198             * Returns the number of wiki nodes.
5199             *
5200             * @return the number of wiki nodes
5201             * @throws SystemException if a system exception occurred
5202             */
5203            @Override
5204            public int countAll() throws SystemException {
5205                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5206                                    FINDER_ARGS_EMPTY, this);
5207    
5208                    if (count == null) {
5209                            Session session = null;
5210    
5211                            try {
5212                                    session = openSession();
5213    
5214                                    Query q = session.createQuery(_SQL_COUNT_WIKINODE);
5215    
5216                                    count = (Long)q.uniqueResult();
5217    
5218                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5219                                            FINDER_ARGS_EMPTY, count);
5220                            }
5221                            catch (Exception e) {
5222                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
5223                                            FINDER_ARGS_EMPTY);
5224    
5225                                    throw processException(e);
5226                            }
5227                            finally {
5228                                    closeSession(session);
5229                            }
5230                    }
5231    
5232                    return count.intValue();
5233            }
5234    
5235            @Override
5236            protected Set<String> getBadColumnNames() {
5237                    return _badColumnNames;
5238            }
5239    
5240            /**
5241             * Initializes the wiki node persistence.
5242             */
5243            public void afterPropertiesSet() {
5244                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5245                                            com.liferay.portal.util.PropsUtil.get(
5246                                                    "value.object.listener.com.liferay.portlet.wiki.model.WikiNode")));
5247    
5248                    if (listenerClassNames.length > 0) {
5249                            try {
5250                                    List<ModelListener<WikiNode>> listenersList = new ArrayList<ModelListener<WikiNode>>();
5251    
5252                                    for (String listenerClassName : listenerClassNames) {
5253                                            listenersList.add((ModelListener<WikiNode>)InstanceFactory.newInstance(
5254                                                            getClassLoader(), listenerClassName));
5255                                    }
5256    
5257                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5258                            }
5259                            catch (Exception e) {
5260                                    _log.error(e);
5261                            }
5262                    }
5263            }
5264    
5265            public void destroy() {
5266                    EntityCacheUtil.removeCache(WikiNodeImpl.class.getName());
5267                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5268                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5269                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5270            }
5271    
5272            private static final String _SQL_SELECT_WIKINODE = "SELECT wikiNode FROM WikiNode wikiNode";
5273            private static final String _SQL_SELECT_WIKINODE_WHERE = "SELECT wikiNode FROM WikiNode wikiNode WHERE ";
5274            private static final String _SQL_COUNT_WIKINODE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode";
5275            private static final String _SQL_COUNT_WIKINODE_WHERE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode WHERE ";
5276            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "wikiNode.nodeId";
5277            private static final String _FILTER_SQL_SELECT_WIKINODE_WHERE = "SELECT DISTINCT {wikiNode.*} FROM WikiNode wikiNode WHERE ";
5278            private static final String _FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_1 =
5279                    "SELECT {WikiNode.*} FROM (SELECT DISTINCT wikiNode.nodeId FROM WikiNode wikiNode WHERE ";
5280            private static final String _FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_2 =
5281                    ") TEMP_TABLE INNER JOIN WikiNode ON TEMP_TABLE.nodeId = WikiNode.nodeId";
5282            private static final String _FILTER_SQL_COUNT_WIKINODE_WHERE = "SELECT COUNT(DISTINCT wikiNode.nodeId) AS COUNT_VALUE FROM WikiNode wikiNode WHERE ";
5283            private static final String _FILTER_ENTITY_ALIAS = "wikiNode";
5284            private static final String _FILTER_ENTITY_TABLE = "WikiNode";
5285            private static final String _ORDER_BY_ENTITY_ALIAS = "wikiNode.";
5286            private static final String _ORDER_BY_ENTITY_TABLE = "WikiNode.";
5287            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiNode exists with the primary key ";
5288            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiNode exists with the key {";
5289            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5290            private static Log _log = LogFactoryUtil.getLog(WikiNodePersistenceImpl.class);
5291            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
5292                                    "uuid"
5293                            });
5294            private static WikiNode _nullWikiNode = new WikiNodeImpl() {
5295                            @Override
5296                            public Object clone() {
5297                                    return this;
5298                            }
5299    
5300                            @Override
5301                            public CacheModel<WikiNode> toCacheModel() {
5302                                    return _nullWikiNodeCacheModel;
5303                            }
5304                    };
5305    
5306            private static CacheModel<WikiNode> _nullWikiNodeCacheModel = new CacheModel<WikiNode>() {
5307                            @Override
5308                            public WikiNode toEntityModel() {
5309                                    return _nullWikiNode;
5310                            }
5311                    };
5312    }