001    /**
002     * Copyright (c) 2000-2011 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.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
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.BatchSessionUtil;
043    import com.liferay.portal.service.persistence.GroupPersistence;
044    import com.liferay.portal.service.persistence.ResourcePersistence;
045    import com.liferay.portal.service.persistence.SubscriptionPersistence;
046    import com.liferay.portal.service.persistence.UserPersistence;
047    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048    
049    import com.liferay.portlet.wiki.NoSuchNodeException;
050    import com.liferay.portlet.wiki.model.WikiNode;
051    import com.liferay.portlet.wiki.model.impl.WikiNodeImpl;
052    import com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl;
053    
054    import java.io.Serializable;
055    
056    import java.util.ArrayList;
057    import java.util.Collections;
058    import java.util.List;
059    
060    /**
061     * The persistence implementation for the wiki node service.
062     *
063     * <p>
064     * Caching information and settings can be found in <code>portal.properties</code>
065     * </p>
066     *
067     * @author Brian Wing Shun Chan
068     * @see WikiNodePersistence
069     * @see WikiNodeUtil
070     * @generated
071     */
072    public class WikiNodePersistenceImpl extends BasePersistenceImpl<WikiNode>
073            implements WikiNodePersistence {
074            /*
075             * NOTE FOR DEVELOPERS:
076             *
077             * 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.
078             */
079            public static final String FINDER_CLASS_NAME_ENTITY = WikiNodeImpl.class.getName();
080            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List1";
082            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List2";
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
085                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
087                            new String[] {
088                                    String.class.getName(),
089                                    
090                            "java.lang.Integer", "java.lang.Integer",
091                                    "com.liferay.portal.kernel.util.OrderByComparator"
092                            });
093            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
094                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
096                            new String[] { String.class.getName() },
097                            WikiNodeModelImpl.UUID_COLUMN_BITMASK);
098            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
099                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
101                            new String[] { String.class.getName() });
102            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
103                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
104                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
105                            new String[] { String.class.getName(), Long.class.getName() },
106                            WikiNodeModelImpl.UUID_COLUMN_BITMASK |
107                            WikiNodeModelImpl.GROUPID_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
109                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
111                            new String[] { String.class.getName(), Long.class.getName() });
112            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
113                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
114                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
115                            new String[] {
116                                    Long.class.getName(),
117                                    
118                            "java.lang.Integer", "java.lang.Integer",
119                                    "com.liferay.portal.kernel.util.OrderByComparator"
120                            });
121            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
122                    new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
123                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
124                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
125                            new String[] { Long.class.getName() },
126                            WikiNodeModelImpl.GROUPID_COLUMN_BITMASK);
127            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
128                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
129                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
130                            new String[] { Long.class.getName() });
131            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
132                    new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
133                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
134                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
135                            new String[] {
136                                    Long.class.getName(),
137                                    
138                            "java.lang.Integer", "java.lang.Integer",
139                                    "com.liferay.portal.kernel.util.OrderByComparator"
140                            });
141            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
142                    new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
143                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
144                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
145                            new String[] { Long.class.getName() },
146                            WikiNodeModelImpl.COMPANYID_COLUMN_BITMASK);
147            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
148                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
149                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
150                            new String[] { Long.class.getName() });
151            public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
152                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
153                            FINDER_CLASS_NAME_ENTITY, "fetchByG_N",
154                            new String[] { Long.class.getName(), String.class.getName() },
155                            WikiNodeModelImpl.GROUPID_COLUMN_BITMASK |
156                            WikiNodeModelImpl.NAME_COLUMN_BITMASK);
157            public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
158                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
159                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N",
160                            new String[] { Long.class.getName(), String.class.getName() });
161            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
162                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
163                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
164            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
165                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, WikiNodeImpl.class,
166                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
167            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
168                            WikiNodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
169                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
170    
171            /**
172             * Caches the wiki node in the entity cache if it is enabled.
173             *
174             * @param wikiNode the wiki node
175             */
176            public void cacheResult(WikiNode wikiNode) {
177                    EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
178                            WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
179    
180                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
181                            new Object[] { wikiNode.getUuid(), Long.valueOf(
182                                            wikiNode.getGroupId()) }, wikiNode);
183    
184                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
185                            new Object[] { Long.valueOf(wikiNode.getGroupId()), wikiNode.getName() },
186                            wikiNode);
187    
188                    wikiNode.resetOriginalValues();
189            }
190    
191            /**
192             * Caches the wiki nodes in the entity cache if it is enabled.
193             *
194             * @param wikiNodes the wiki nodes
195             */
196            public void cacheResult(List<WikiNode> wikiNodes) {
197                    for (WikiNode wikiNode : wikiNodes) {
198                            if (EntityCacheUtil.getResult(
199                                                    WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
200                                                    WikiNodeImpl.class, wikiNode.getPrimaryKey()) == null) {
201                                    cacheResult(wikiNode);
202                            }
203                            else {
204                                    wikiNode.resetOriginalValues();
205                            }
206                    }
207            }
208    
209            /**
210             * Clears the cache for all wiki nodes.
211             *
212             * <p>
213             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
214             * </p>
215             */
216            @Override
217            public void clearCache() {
218                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
219                            CacheRegistryUtil.clear(WikiNodeImpl.class.getName());
220                    }
221    
222                    EntityCacheUtil.clearCache(WikiNodeImpl.class.getName());
223    
224                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
225                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
226                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
227            }
228    
229            /**
230             * Clears the cache for the wiki node.
231             *
232             * <p>
233             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
234             * </p>
235             */
236            @Override
237            public void clearCache(WikiNode wikiNode) {
238                    EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
239                            WikiNodeImpl.class, wikiNode.getPrimaryKey());
240    
241                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
242                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
243    
244                    clearUniqueFindersCache(wikiNode);
245            }
246    
247            @Override
248            public void clearCache(List<WikiNode> wikiNodes) {
249                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
250                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
251    
252                    for (WikiNode wikiNode : wikiNodes) {
253                            EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
254                                    WikiNodeImpl.class, wikiNode.getPrimaryKey());
255    
256                            clearUniqueFindersCache(wikiNode);
257                    }
258            }
259    
260            protected void clearUniqueFindersCache(WikiNode wikiNode) {
261                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
262                            new Object[] { wikiNode.getUuid(), Long.valueOf(
263                                            wikiNode.getGroupId()) });
264    
265                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
266                            new Object[] { Long.valueOf(wikiNode.getGroupId()), wikiNode.getName() });
267            }
268    
269            /**
270             * Creates a new wiki node with the primary key. Does not add the wiki node to the database.
271             *
272             * @param nodeId the primary key for the new wiki node
273             * @return the new wiki node
274             */
275            public WikiNode create(long nodeId) {
276                    WikiNode wikiNode = new WikiNodeImpl();
277    
278                    wikiNode.setNew(true);
279                    wikiNode.setPrimaryKey(nodeId);
280    
281                    String uuid = PortalUUIDUtil.generate();
282    
283                    wikiNode.setUuid(uuid);
284    
285                    return wikiNode;
286            }
287    
288            /**
289             * Removes the wiki node with the primary key from the database. Also notifies the appropriate model listeners.
290             *
291             * @param nodeId the primary key of the wiki node
292             * @return the wiki node that was removed
293             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
294             * @throws SystemException if a system exception occurred
295             */
296            public WikiNode remove(long nodeId)
297                    throws NoSuchNodeException, SystemException {
298                    return remove(Long.valueOf(nodeId));
299            }
300    
301            /**
302             * Removes the wiki node with the primary key from the database. Also notifies the appropriate model listeners.
303             *
304             * @param primaryKey the primary key of the wiki node
305             * @return the wiki node that was removed
306             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
307             * @throws SystemException if a system exception occurred
308             */
309            @Override
310            public WikiNode remove(Serializable primaryKey)
311                    throws NoSuchNodeException, SystemException {
312                    Session session = null;
313    
314                    try {
315                            session = openSession();
316    
317                            WikiNode wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
318                                            primaryKey);
319    
320                            if (wikiNode == null) {
321                                    if (_log.isWarnEnabled()) {
322                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
323                                    }
324    
325                                    throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
326                                            primaryKey);
327                            }
328    
329                            return remove(wikiNode);
330                    }
331                    catch (NoSuchNodeException nsee) {
332                            throw nsee;
333                    }
334                    catch (Exception e) {
335                            throw processException(e);
336                    }
337                    finally {
338                            closeSession(session);
339                    }
340            }
341    
342            @Override
343            protected WikiNode removeImpl(WikiNode wikiNode) throws SystemException {
344                    wikiNode = toUnwrappedModel(wikiNode);
345    
346                    Session session = null;
347    
348                    try {
349                            session = openSession();
350    
351                            BatchSessionUtil.delete(session, wikiNode);
352                    }
353                    catch (Exception e) {
354                            throw processException(e);
355                    }
356                    finally {
357                            closeSession(session);
358                    }
359    
360                    clearCache(wikiNode);
361    
362                    return wikiNode;
363            }
364    
365            @Override
366            public WikiNode updateImpl(
367                    com.liferay.portlet.wiki.model.WikiNode wikiNode, boolean merge)
368                    throws SystemException {
369                    wikiNode = toUnwrappedModel(wikiNode);
370    
371                    boolean isNew = wikiNode.isNew();
372    
373                    WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
374    
375                    if (Validator.isNull(wikiNode.getUuid())) {
376                            String uuid = PortalUUIDUtil.generate();
377    
378                            wikiNode.setUuid(uuid);
379                    }
380    
381                    Session session = null;
382    
383                    try {
384                            session = openSession();
385    
386                            BatchSessionUtil.update(session, wikiNode, merge);
387    
388                            wikiNode.setNew(false);
389                    }
390                    catch (Exception e) {
391                            throw processException(e);
392                    }
393                    finally {
394                            closeSession(session);
395                    }
396    
397                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
398    
399                    if (isNew || !WikiNodeModelImpl.COLUMN_BITMASK_ENABLED) {
400                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
401                    }
402    
403                    else {
404                            if ((wikiNodeModelImpl.getColumnBitmask() &
405                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
406                                    Object[] args = new Object[] { wikiNodeModelImpl.getOriginalUuid() };
407    
408                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
409                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
410                                            args);
411    
412                                    args = new Object[] { wikiNodeModelImpl.getUuid() };
413    
414                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
415                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
416                                            args);
417                            }
418    
419                            if ((wikiNodeModelImpl.getColumnBitmask() &
420                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
421                                    Object[] args = new Object[] {
422                                                    Long.valueOf(wikiNodeModelImpl.getOriginalGroupId())
423                                            };
424    
425                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
426                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
427                                            args);
428    
429                                    args = new Object[] { Long.valueOf(wikiNodeModelImpl.getGroupId()) };
430    
431                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
432                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
433                                            args);
434                            }
435    
436                            if ((wikiNodeModelImpl.getColumnBitmask() &
437                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
438                                    Object[] args = new Object[] {
439                                                    Long.valueOf(wikiNodeModelImpl.getOriginalCompanyId())
440                                            };
441    
442                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
443                                            args);
444                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
445                                            args);
446    
447                                    args = new Object[] {
448                                                    Long.valueOf(wikiNodeModelImpl.getCompanyId())
449                                            };
450    
451                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
452                                            args);
453                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
454                                            args);
455                            }
456                    }
457    
458                    EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
459                            WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
460    
461                    if (isNew) {
462                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
463                                    new Object[] {
464                                            wikiNode.getUuid(), Long.valueOf(wikiNode.getGroupId())
465                                    }, wikiNode);
466    
467                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
468                                    new Object[] {
469                                            Long.valueOf(wikiNode.getGroupId()),
470                                            
471                                    wikiNode.getName()
472                                    }, wikiNode);
473                    }
474                    else {
475                            if ((wikiNodeModelImpl.getColumnBitmask() &
476                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
477                                    Object[] args = new Object[] {
478                                                    wikiNodeModelImpl.getOriginalUuid(),
479                                                    Long.valueOf(wikiNodeModelImpl.getOriginalGroupId())
480                                            };
481    
482                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
483                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
484    
485                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
486                                            new Object[] {
487                                                    wikiNode.getUuid(), Long.valueOf(wikiNode.getGroupId())
488                                            }, wikiNode);
489                            }
490    
491                            if ((wikiNodeModelImpl.getColumnBitmask() &
492                                            FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
493                                    Object[] args = new Object[] {
494                                                    Long.valueOf(wikiNodeModelImpl.getOriginalGroupId()),
495                                                    
496                                                    wikiNodeModelImpl.getOriginalName()
497                                            };
498    
499                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
500                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
501    
502                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
503                                            new Object[] {
504                                                    Long.valueOf(wikiNode.getGroupId()),
505                                                    
506                                            wikiNode.getName()
507                                            }, wikiNode);
508                            }
509                    }
510    
511                    return wikiNode;
512            }
513    
514            protected WikiNode toUnwrappedModel(WikiNode wikiNode) {
515                    if (wikiNode instanceof WikiNodeImpl) {
516                            return wikiNode;
517                    }
518    
519                    WikiNodeImpl wikiNodeImpl = new WikiNodeImpl();
520    
521                    wikiNodeImpl.setNew(wikiNode.isNew());
522                    wikiNodeImpl.setPrimaryKey(wikiNode.getPrimaryKey());
523    
524                    wikiNodeImpl.setUuid(wikiNode.getUuid());
525                    wikiNodeImpl.setNodeId(wikiNode.getNodeId());
526                    wikiNodeImpl.setGroupId(wikiNode.getGroupId());
527                    wikiNodeImpl.setCompanyId(wikiNode.getCompanyId());
528                    wikiNodeImpl.setUserId(wikiNode.getUserId());
529                    wikiNodeImpl.setUserName(wikiNode.getUserName());
530                    wikiNodeImpl.setCreateDate(wikiNode.getCreateDate());
531                    wikiNodeImpl.setModifiedDate(wikiNode.getModifiedDate());
532                    wikiNodeImpl.setName(wikiNode.getName());
533                    wikiNodeImpl.setDescription(wikiNode.getDescription());
534                    wikiNodeImpl.setLastPostDate(wikiNode.getLastPostDate());
535    
536                    return wikiNodeImpl;
537            }
538    
539            /**
540             * Returns the wiki node with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
541             *
542             * @param primaryKey the primary key of the wiki node
543             * @return the wiki node
544             * @throws com.liferay.portal.NoSuchModelException if a wiki node with the primary key could not be found
545             * @throws SystemException if a system exception occurred
546             */
547            @Override
548            public WikiNode findByPrimaryKey(Serializable primaryKey)
549                    throws NoSuchModelException, SystemException {
550                    return findByPrimaryKey(((Long)primaryKey).longValue());
551            }
552    
553            /**
554             * Returns the wiki node with the primary key or throws a {@link com.liferay.portlet.wiki.NoSuchNodeException} if it could not be found.
555             *
556             * @param nodeId the primary key of the wiki node
557             * @return the wiki node
558             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
559             * @throws SystemException if a system exception occurred
560             */
561            public WikiNode findByPrimaryKey(long nodeId)
562                    throws NoSuchNodeException, SystemException {
563                    WikiNode wikiNode = fetchByPrimaryKey(nodeId);
564    
565                    if (wikiNode == null) {
566                            if (_log.isWarnEnabled()) {
567                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + nodeId);
568                            }
569    
570                            throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
571                                    nodeId);
572                    }
573    
574                    return wikiNode;
575            }
576    
577            /**
578             * Returns the wiki node with the primary key or returns <code>null</code> if it could not be found.
579             *
580             * @param primaryKey the primary key of the wiki node
581             * @return the wiki node, or <code>null</code> if a wiki node with the primary key could not be found
582             * @throws SystemException if a system exception occurred
583             */
584            @Override
585            public WikiNode fetchByPrimaryKey(Serializable primaryKey)
586                    throws SystemException {
587                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
588            }
589    
590            /**
591             * Returns the wiki node with the primary key or returns <code>null</code> if it could not be found.
592             *
593             * @param nodeId the primary key of the wiki node
594             * @return the wiki node, or <code>null</code> if a wiki node with the primary key could not be found
595             * @throws SystemException if a system exception occurred
596             */
597            public WikiNode fetchByPrimaryKey(long nodeId) throws SystemException {
598                    WikiNode wikiNode = (WikiNode)EntityCacheUtil.getResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
599                                    WikiNodeImpl.class, nodeId);
600    
601                    if (wikiNode == _nullWikiNode) {
602                            return null;
603                    }
604    
605                    if (wikiNode == null) {
606                            Session session = null;
607    
608                            boolean hasException = false;
609    
610                            try {
611                                    session = openSession();
612    
613                                    wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
614                                                    Long.valueOf(nodeId));
615                            }
616                            catch (Exception e) {
617                                    hasException = true;
618    
619                                    throw processException(e);
620                            }
621                            finally {
622                                    if (wikiNode != null) {
623                                            cacheResult(wikiNode);
624                                    }
625                                    else if (!hasException) {
626                                            EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
627                                                    WikiNodeImpl.class, nodeId, _nullWikiNode);
628                                    }
629    
630                                    closeSession(session);
631                            }
632                    }
633    
634                    return wikiNode;
635            }
636    
637            /**
638             * Returns all the wiki nodes where uuid = &#63;.
639             *
640             * @param uuid the uuid
641             * @return the matching wiki nodes
642             * @throws SystemException if a system exception occurred
643             */
644            public List<WikiNode> findByUuid(String uuid) throws SystemException {
645                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
646            }
647    
648            /**
649             * Returns a range of all the wiki nodes where uuid = &#63;.
650             *
651             * <p>
652             * 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.
653             * </p>
654             *
655             * @param uuid the uuid
656             * @param start the lower bound of the range of wiki nodes
657             * @param end the upper bound of the range of wiki nodes (not inclusive)
658             * @return the range of matching wiki nodes
659             * @throws SystemException if a system exception occurred
660             */
661            public List<WikiNode> findByUuid(String uuid, int start, int end)
662                    throws SystemException {
663                    return findByUuid(uuid, start, end, null);
664            }
665    
666            /**
667             * Returns an ordered range of all the wiki nodes where uuid = &#63;.
668             *
669             * <p>
670             * 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.
671             * </p>
672             *
673             * @param uuid the uuid
674             * @param start the lower bound of the range of wiki nodes
675             * @param end the upper bound of the range of wiki nodes (not inclusive)
676             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
677             * @return the ordered range of matching wiki nodes
678             * @throws SystemException if a system exception occurred
679             */
680            public List<WikiNode> findByUuid(String uuid, int start, int end,
681                    OrderByComparator orderByComparator) throws SystemException {
682                    FinderPath finderPath = null;
683                    Object[] finderArgs = null;
684    
685                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
686                                    (orderByComparator == null)) {
687                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
688                            finderArgs = new Object[] { uuid };
689                    }
690                    else {
691                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
692                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
693                    }
694    
695                    List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
696                                    finderArgs, this);
697    
698                    if (list == null) {
699                            StringBundler query = null;
700    
701                            if (orderByComparator != null) {
702                                    query = new StringBundler(3 +
703                                                    (orderByComparator.getOrderByFields().length * 3));
704                            }
705                            else {
706                                    query = new StringBundler(3);
707                            }
708    
709                            query.append(_SQL_SELECT_WIKINODE_WHERE);
710    
711                            if (uuid == null) {
712                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
713                            }
714                            else {
715                                    if (uuid.equals(StringPool.BLANK)) {
716                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
717                                    }
718                                    else {
719                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
720                                    }
721                            }
722    
723                            if (orderByComparator != null) {
724                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
725                                            orderByComparator);
726                            }
727    
728                            else {
729                                    query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
730                            }
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 (uuid != null) {
744                                            qPos.add(uuid);
745                                    }
746    
747                                    list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
748                                                    end);
749                            }
750                            catch (Exception e) {
751                                    throw processException(e);
752                            }
753                            finally {
754                                    if (list == null) {
755                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
756                                    }
757                                    else {
758                                            cacheResult(list);
759    
760                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
761                                    }
762    
763                                    closeSession(session);
764                            }
765                    }
766    
767                    return list;
768            }
769    
770            /**
771             * Returns the first wiki node in the ordered set where uuid = &#63;.
772             *
773             * <p>
774             * 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.
775             * </p>
776             *
777             * @param uuid the uuid
778             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
779             * @return the first matching wiki node
780             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
781             * @throws SystemException if a system exception occurred
782             */
783            public WikiNode findByUuid_First(String uuid,
784                    OrderByComparator orderByComparator)
785                    throws NoSuchNodeException, SystemException {
786                    List<WikiNode> list = findByUuid(uuid, 0, 1, orderByComparator);
787    
788                    if (list.isEmpty()) {
789                            StringBundler msg = new StringBundler(4);
790    
791                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
792    
793                            msg.append("uuid=");
794                            msg.append(uuid);
795    
796                            msg.append(StringPool.CLOSE_CURLY_BRACE);
797    
798                            throw new NoSuchNodeException(msg.toString());
799                    }
800                    else {
801                            return list.get(0);
802                    }
803            }
804    
805            /**
806             * Returns the last wiki node in the ordered set where uuid = &#63;.
807             *
808             * <p>
809             * 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.
810             * </p>
811             *
812             * @param uuid the uuid
813             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
814             * @return the last matching wiki node
815             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
816             * @throws SystemException if a system exception occurred
817             */
818            public WikiNode findByUuid_Last(String uuid,
819                    OrderByComparator orderByComparator)
820                    throws NoSuchNodeException, SystemException {
821                    int count = countByUuid(uuid);
822    
823                    List<WikiNode> list = findByUuid(uuid, count - 1, count,
824                                    orderByComparator);
825    
826                    if (list.isEmpty()) {
827                            StringBundler msg = new StringBundler(4);
828    
829                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
830    
831                            msg.append("uuid=");
832                            msg.append(uuid);
833    
834                            msg.append(StringPool.CLOSE_CURLY_BRACE);
835    
836                            throw new NoSuchNodeException(msg.toString());
837                    }
838                    else {
839                            return list.get(0);
840                    }
841            }
842    
843            /**
844             * Returns the wiki nodes before and after the current wiki node in the ordered set where uuid = &#63;.
845             *
846             * <p>
847             * 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.
848             * </p>
849             *
850             * @param nodeId the primary key of the current wiki node
851             * @param uuid the uuid
852             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
853             * @return the previous, current, and next wiki node
854             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
855             * @throws SystemException if a system exception occurred
856             */
857            public WikiNode[] findByUuid_PrevAndNext(long nodeId, String uuid,
858                    OrderByComparator orderByComparator)
859                    throws NoSuchNodeException, SystemException {
860                    WikiNode wikiNode = findByPrimaryKey(nodeId);
861    
862                    Session session = null;
863    
864                    try {
865                            session = openSession();
866    
867                            WikiNode[] array = new WikiNodeImpl[3];
868    
869                            array[0] = getByUuid_PrevAndNext(session, wikiNode, uuid,
870                                            orderByComparator, true);
871    
872                            array[1] = wikiNode;
873    
874                            array[2] = getByUuid_PrevAndNext(session, wikiNode, uuid,
875                                            orderByComparator, false);
876    
877                            return array;
878                    }
879                    catch (Exception e) {
880                            throw processException(e);
881                    }
882                    finally {
883                            closeSession(session);
884                    }
885            }
886    
887            protected WikiNode getByUuid_PrevAndNext(Session session,
888                    WikiNode wikiNode, String uuid, OrderByComparator orderByComparator,
889                    boolean previous) {
890                    StringBundler query = null;
891    
892                    if (orderByComparator != null) {
893                            query = new StringBundler(6 +
894                                            (orderByComparator.getOrderByFields().length * 6));
895                    }
896                    else {
897                            query = new StringBundler(3);
898                    }
899    
900                    query.append(_SQL_SELECT_WIKINODE_WHERE);
901    
902                    if (uuid == null) {
903                            query.append(_FINDER_COLUMN_UUID_UUID_1);
904                    }
905                    else {
906                            if (uuid.equals(StringPool.BLANK)) {
907                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
908                            }
909                            else {
910                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
911                            }
912                    }
913    
914                    if (orderByComparator != null) {
915                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
916    
917                            if (orderByConditionFields.length > 0) {
918                                    query.append(WHERE_AND);
919                            }
920    
921                            for (int i = 0; i < orderByConditionFields.length; i++) {
922                                    query.append(_ORDER_BY_ENTITY_ALIAS);
923                                    query.append(orderByConditionFields[i]);
924    
925                                    if ((i + 1) < orderByConditionFields.length) {
926                                            if (orderByComparator.isAscending() ^ previous) {
927                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
928                                            }
929                                            else {
930                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
931                                            }
932                                    }
933                                    else {
934                                            if (orderByComparator.isAscending() ^ previous) {
935                                                    query.append(WHERE_GREATER_THAN);
936                                            }
937                                            else {
938                                                    query.append(WHERE_LESSER_THAN);
939                                            }
940                                    }
941                            }
942    
943                            query.append(ORDER_BY_CLAUSE);
944    
945                            String[] orderByFields = orderByComparator.getOrderByFields();
946    
947                            for (int i = 0; i < orderByFields.length; i++) {
948                                    query.append(_ORDER_BY_ENTITY_ALIAS);
949                                    query.append(orderByFields[i]);
950    
951                                    if ((i + 1) < orderByFields.length) {
952                                            if (orderByComparator.isAscending() ^ previous) {
953                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
954                                            }
955                                            else {
956                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
957                                            }
958                                    }
959                                    else {
960                                            if (orderByComparator.isAscending() ^ previous) {
961                                                    query.append(ORDER_BY_ASC);
962                                            }
963                                            else {
964                                                    query.append(ORDER_BY_DESC);
965                                            }
966                                    }
967                            }
968                    }
969    
970                    else {
971                            query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
972                    }
973    
974                    String sql = query.toString();
975    
976                    Query q = session.createQuery(sql);
977    
978                    q.setFirstResult(0);
979                    q.setMaxResults(2);
980    
981                    QueryPos qPos = QueryPos.getInstance(q);
982    
983                    if (uuid != null) {
984                            qPos.add(uuid);
985                    }
986    
987                    if (orderByComparator != null) {
988                            Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
989    
990                            for (Object value : values) {
991                                    qPos.add(value);
992                            }
993                    }
994    
995                    List<WikiNode> list = q.list();
996    
997                    if (list.size() == 2) {
998                            return list.get(1);
999                    }
1000                    else {
1001                            return null;
1002                    }
1003            }
1004    
1005            /**
1006             * 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.
1007             *
1008             * @param uuid the uuid
1009             * @param groupId the group ID
1010             * @return the matching wiki node
1011             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
1012             * @throws SystemException if a system exception occurred
1013             */
1014            public WikiNode findByUUID_G(String uuid, long groupId)
1015                    throws NoSuchNodeException, SystemException {
1016                    WikiNode wikiNode = fetchByUUID_G(uuid, groupId);
1017    
1018                    if (wikiNode == null) {
1019                            StringBundler msg = new StringBundler(6);
1020    
1021                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1022    
1023                            msg.append("uuid=");
1024                            msg.append(uuid);
1025    
1026                            msg.append(", groupId=");
1027                            msg.append(groupId);
1028    
1029                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1030    
1031                            if (_log.isWarnEnabled()) {
1032                                    _log.warn(msg.toString());
1033                            }
1034    
1035                            throw new NoSuchNodeException(msg.toString());
1036                    }
1037    
1038                    return wikiNode;
1039            }
1040    
1041            /**
1042             * 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.
1043             *
1044             * @param uuid the uuid
1045             * @param groupId the group ID
1046             * @return the matching wiki node, or <code>null</code> if a matching wiki node could not be found
1047             * @throws SystemException if a system exception occurred
1048             */
1049            public WikiNode fetchByUUID_G(String uuid, long groupId)
1050                    throws SystemException {
1051                    return fetchByUUID_G(uuid, groupId, true);
1052            }
1053    
1054            /**
1055             * 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.
1056             *
1057             * @param uuid the uuid
1058             * @param groupId the group ID
1059             * @param retrieveFromCache whether to use the finder cache
1060             * @return the matching wiki node, or <code>null</code> if a matching wiki node could not be found
1061             * @throws SystemException if a system exception occurred
1062             */
1063            public WikiNode fetchByUUID_G(String uuid, long groupId,
1064                    boolean retrieveFromCache) throws SystemException {
1065                    Object[] finderArgs = new Object[] { uuid, groupId };
1066    
1067                    Object result = null;
1068    
1069                    if (retrieveFromCache) {
1070                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1071                                            finderArgs, this);
1072                    }
1073    
1074                    if (result == null) {
1075                            StringBundler query = new StringBundler(4);
1076    
1077                            query.append(_SQL_SELECT_WIKINODE_WHERE);
1078    
1079                            if (uuid == null) {
1080                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1081                            }
1082                            else {
1083                                    if (uuid.equals(StringPool.BLANK)) {
1084                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1085                                    }
1086                                    else {
1087                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1088                                    }
1089                            }
1090    
1091                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1092    
1093                            query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1094    
1095                            String sql = query.toString();
1096    
1097                            Session session = null;
1098    
1099                            try {
1100                                    session = openSession();
1101    
1102                                    Query q = session.createQuery(sql);
1103    
1104                                    QueryPos qPos = QueryPos.getInstance(q);
1105    
1106                                    if (uuid != null) {
1107                                            qPos.add(uuid);
1108                                    }
1109    
1110                                    qPos.add(groupId);
1111    
1112                                    List<WikiNode> list = q.list();
1113    
1114                                    result = list;
1115    
1116                                    WikiNode wikiNode = null;
1117    
1118                                    if (list.isEmpty()) {
1119                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1120                                                    finderArgs, list);
1121                                    }
1122                                    else {
1123                                            wikiNode = list.get(0);
1124    
1125                                            cacheResult(wikiNode);
1126    
1127                                            if ((wikiNode.getUuid() == null) ||
1128                                                            !wikiNode.getUuid().equals(uuid) ||
1129                                                            (wikiNode.getGroupId() != groupId)) {
1130                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1131                                                            finderArgs, wikiNode);
1132                                            }
1133                                    }
1134    
1135                                    return wikiNode;
1136                            }
1137                            catch (Exception e) {
1138                                    throw processException(e);
1139                            }
1140                            finally {
1141                                    if (result == null) {
1142                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1143                                                    finderArgs);
1144                                    }
1145    
1146                                    closeSession(session);
1147                            }
1148                    }
1149                    else {
1150                            if (result instanceof List<?>) {
1151                                    return null;
1152                            }
1153                            else {
1154                                    return (WikiNode)result;
1155                            }
1156                    }
1157            }
1158    
1159            /**
1160             * Returns all the wiki nodes where groupId = &#63;.
1161             *
1162             * @param groupId the group ID
1163             * @return the matching wiki nodes
1164             * @throws SystemException if a system exception occurred
1165             */
1166            public List<WikiNode> findByGroupId(long groupId) throws SystemException {
1167                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1168            }
1169    
1170            /**
1171             * Returns a range of all the wiki nodes where groupId = &#63;.
1172             *
1173             * <p>
1174             * 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.
1175             * </p>
1176             *
1177             * @param groupId the group ID
1178             * @param start the lower bound of the range of wiki nodes
1179             * @param end the upper bound of the range of wiki nodes (not inclusive)
1180             * @return the range of matching wiki nodes
1181             * @throws SystemException if a system exception occurred
1182             */
1183            public List<WikiNode> findByGroupId(long groupId, int start, int end)
1184                    throws SystemException {
1185                    return findByGroupId(groupId, start, end, null);
1186            }
1187    
1188            /**
1189             * Returns an ordered range of all the wiki nodes where groupId = &#63;.
1190             *
1191             * <p>
1192             * 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.
1193             * </p>
1194             *
1195             * @param groupId the group ID
1196             * @param start the lower bound of the range of wiki nodes
1197             * @param end the upper bound of the range of wiki nodes (not inclusive)
1198             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1199             * @return the ordered range of matching wiki nodes
1200             * @throws SystemException if a system exception occurred
1201             */
1202            public List<WikiNode> findByGroupId(long groupId, int start, int end,
1203                    OrderByComparator orderByComparator) throws SystemException {
1204                    FinderPath finderPath = null;
1205                    Object[] finderArgs = null;
1206    
1207                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1208                                    (orderByComparator == null)) {
1209                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1210                            finderArgs = new Object[] { groupId };
1211                    }
1212                    else {
1213                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1214                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1215                    }
1216    
1217                    List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
1218                                    finderArgs, this);
1219    
1220                    if (list == null) {
1221                            StringBundler query = null;
1222    
1223                            if (orderByComparator != null) {
1224                                    query = new StringBundler(3 +
1225                                                    (orderByComparator.getOrderByFields().length * 3));
1226                            }
1227                            else {
1228                                    query = new StringBundler(3);
1229                            }
1230    
1231                            query.append(_SQL_SELECT_WIKINODE_WHERE);
1232    
1233                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1234    
1235                            if (orderByComparator != null) {
1236                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1237                                            orderByComparator);
1238                            }
1239    
1240                            else {
1241                                    query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1242                            }
1243    
1244                            String sql = query.toString();
1245    
1246                            Session session = null;
1247    
1248                            try {
1249                                    session = openSession();
1250    
1251                                    Query q = session.createQuery(sql);
1252    
1253                                    QueryPos qPos = QueryPos.getInstance(q);
1254    
1255                                    qPos.add(groupId);
1256    
1257                                    list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
1258                                                    end);
1259                            }
1260                            catch (Exception e) {
1261                                    throw processException(e);
1262                            }
1263                            finally {
1264                                    if (list == null) {
1265                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1266                                    }
1267                                    else {
1268                                            cacheResult(list);
1269    
1270                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1271                                    }
1272    
1273                                    closeSession(session);
1274                            }
1275                    }
1276    
1277                    return list;
1278            }
1279    
1280            /**
1281             * Returns the first wiki node in the ordered set where groupId = &#63;.
1282             *
1283             * <p>
1284             * 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.
1285             * </p>
1286             *
1287             * @param groupId the group ID
1288             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1289             * @return the first matching wiki node
1290             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
1291             * @throws SystemException if a system exception occurred
1292             */
1293            public WikiNode findByGroupId_First(long groupId,
1294                    OrderByComparator orderByComparator)
1295                    throws NoSuchNodeException, SystemException {
1296                    List<WikiNode> list = findByGroupId(groupId, 0, 1, orderByComparator);
1297    
1298                    if (list.isEmpty()) {
1299                            StringBundler msg = new StringBundler(4);
1300    
1301                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1302    
1303                            msg.append("groupId=");
1304                            msg.append(groupId);
1305    
1306                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1307    
1308                            throw new NoSuchNodeException(msg.toString());
1309                    }
1310                    else {
1311                            return list.get(0);
1312                    }
1313            }
1314    
1315            /**
1316             * Returns the last wiki node in the ordered set where groupId = &#63;.
1317             *
1318             * <p>
1319             * 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.
1320             * </p>
1321             *
1322             * @param groupId the group ID
1323             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1324             * @return the last matching wiki node
1325             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
1326             * @throws SystemException if a system exception occurred
1327             */
1328            public WikiNode findByGroupId_Last(long groupId,
1329                    OrderByComparator orderByComparator)
1330                    throws NoSuchNodeException, SystemException {
1331                    int count = countByGroupId(groupId);
1332    
1333                    List<WikiNode> list = findByGroupId(groupId, count - 1, count,
1334                                    orderByComparator);
1335    
1336                    if (list.isEmpty()) {
1337                            StringBundler msg = new StringBundler(4);
1338    
1339                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1340    
1341                            msg.append("groupId=");
1342                            msg.append(groupId);
1343    
1344                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1345    
1346                            throw new NoSuchNodeException(msg.toString());
1347                    }
1348                    else {
1349                            return list.get(0);
1350                    }
1351            }
1352    
1353            /**
1354             * Returns the wiki nodes before and after the current wiki node in the ordered set where groupId = &#63;.
1355             *
1356             * <p>
1357             * 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.
1358             * </p>
1359             *
1360             * @param nodeId the primary key of the current wiki node
1361             * @param groupId the group ID
1362             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1363             * @return the previous, current, and next wiki node
1364             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
1365             * @throws SystemException if a system exception occurred
1366             */
1367            public WikiNode[] findByGroupId_PrevAndNext(long nodeId, long groupId,
1368                    OrderByComparator orderByComparator)
1369                    throws NoSuchNodeException, SystemException {
1370                    WikiNode wikiNode = findByPrimaryKey(nodeId);
1371    
1372                    Session session = null;
1373    
1374                    try {
1375                            session = openSession();
1376    
1377                            WikiNode[] array = new WikiNodeImpl[3];
1378    
1379                            array[0] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
1380                                            orderByComparator, true);
1381    
1382                            array[1] = wikiNode;
1383    
1384                            array[2] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
1385                                            orderByComparator, false);
1386    
1387                            return array;
1388                    }
1389                    catch (Exception e) {
1390                            throw processException(e);
1391                    }
1392                    finally {
1393                            closeSession(session);
1394                    }
1395            }
1396    
1397            protected WikiNode getByGroupId_PrevAndNext(Session session,
1398                    WikiNode wikiNode, long groupId, OrderByComparator orderByComparator,
1399                    boolean previous) {
1400                    StringBundler query = null;
1401    
1402                    if (orderByComparator != null) {
1403                            query = new StringBundler(6 +
1404                                            (orderByComparator.getOrderByFields().length * 6));
1405                    }
1406                    else {
1407                            query = new StringBundler(3);
1408                    }
1409    
1410                    query.append(_SQL_SELECT_WIKINODE_WHERE);
1411    
1412                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1413    
1414                    if (orderByComparator != null) {
1415                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1416    
1417                            if (orderByConditionFields.length > 0) {
1418                                    query.append(WHERE_AND);
1419                            }
1420    
1421                            for (int i = 0; i < orderByConditionFields.length; i++) {
1422                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1423                                    query.append(orderByConditionFields[i]);
1424    
1425                                    if ((i + 1) < orderByConditionFields.length) {
1426                                            if (orderByComparator.isAscending() ^ previous) {
1427                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1428                                            }
1429                                            else {
1430                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1431                                            }
1432                                    }
1433                                    else {
1434                                            if (orderByComparator.isAscending() ^ previous) {
1435                                                    query.append(WHERE_GREATER_THAN);
1436                                            }
1437                                            else {
1438                                                    query.append(WHERE_LESSER_THAN);
1439                                            }
1440                                    }
1441                            }
1442    
1443                            query.append(ORDER_BY_CLAUSE);
1444    
1445                            String[] orderByFields = orderByComparator.getOrderByFields();
1446    
1447                            for (int i = 0; i < orderByFields.length; i++) {
1448                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1449                                    query.append(orderByFields[i]);
1450    
1451                                    if ((i + 1) < orderByFields.length) {
1452                                            if (orderByComparator.isAscending() ^ previous) {
1453                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1454                                            }
1455                                            else {
1456                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1457                                            }
1458                                    }
1459                                    else {
1460                                            if (orderByComparator.isAscending() ^ previous) {
1461                                                    query.append(ORDER_BY_ASC);
1462                                            }
1463                                            else {
1464                                                    query.append(ORDER_BY_DESC);
1465                                            }
1466                                    }
1467                            }
1468                    }
1469    
1470                    else {
1471                            query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1472                    }
1473    
1474                    String sql = query.toString();
1475    
1476                    Query q = session.createQuery(sql);
1477    
1478                    q.setFirstResult(0);
1479                    q.setMaxResults(2);
1480    
1481                    QueryPos qPos = QueryPos.getInstance(q);
1482    
1483                    qPos.add(groupId);
1484    
1485                    if (orderByComparator != null) {
1486                            Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
1487    
1488                            for (Object value : values) {
1489                                    qPos.add(value);
1490                            }
1491                    }
1492    
1493                    List<WikiNode> list = q.list();
1494    
1495                    if (list.size() == 2) {
1496                            return list.get(1);
1497                    }
1498                    else {
1499                            return null;
1500                    }
1501            }
1502    
1503            /**
1504             * Returns all the wiki nodes that the user has permission to view where groupId = &#63;.
1505             *
1506             * @param groupId the group ID
1507             * @return the matching wiki nodes that the user has permission to view
1508             * @throws SystemException if a system exception occurred
1509             */
1510            public List<WikiNode> filterFindByGroupId(long groupId)
1511                    throws SystemException {
1512                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1513                            QueryUtil.ALL_POS, null);
1514            }
1515    
1516            /**
1517             * Returns a range of all the wiki nodes that the user has permission to view where groupId = &#63;.
1518             *
1519             * <p>
1520             * 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.
1521             * </p>
1522             *
1523             * @param groupId the group ID
1524             * @param start the lower bound of the range of wiki nodes
1525             * @param end the upper bound of the range of wiki nodes (not inclusive)
1526             * @return the range of matching wiki nodes that the user has permission to view
1527             * @throws SystemException if a system exception occurred
1528             */
1529            public List<WikiNode> filterFindByGroupId(long groupId, int start, int end)
1530                    throws SystemException {
1531                    return filterFindByGroupId(groupId, start, end, null);
1532            }
1533    
1534            /**
1535             * Returns an ordered range of all the wiki nodes that the user has permissions to view where groupId = &#63;.
1536             *
1537             * <p>
1538             * 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.
1539             * </p>
1540             *
1541             * @param groupId the group ID
1542             * @param start the lower bound of the range of wiki nodes
1543             * @param end the upper bound of the range of wiki nodes (not inclusive)
1544             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1545             * @return the ordered range of matching wiki nodes that the user has permission to view
1546             * @throws SystemException if a system exception occurred
1547             */
1548            public List<WikiNode> filterFindByGroupId(long groupId, int start, int end,
1549                    OrderByComparator orderByComparator) throws SystemException {
1550                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1551                            return findByGroupId(groupId, start, end, orderByComparator);
1552                    }
1553    
1554                    StringBundler query = null;
1555    
1556                    if (orderByComparator != null) {
1557                            query = new StringBundler(3 +
1558                                            (orderByComparator.getOrderByFields().length * 3));
1559                    }
1560                    else {
1561                            query = new StringBundler(3);
1562                    }
1563    
1564                    if (getDB().isSupportsInlineDistinct()) {
1565                            query.append(_FILTER_SQL_SELECT_WIKINODE_WHERE);
1566                    }
1567                    else {
1568                            query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_1);
1569                    }
1570    
1571                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1572    
1573                    if (!getDB().isSupportsInlineDistinct()) {
1574                            query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_2);
1575                    }
1576    
1577                    if (orderByComparator != null) {
1578                            if (getDB().isSupportsInlineDistinct()) {
1579                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1580                                            orderByComparator);
1581                            }
1582                            else {
1583                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1584                                            orderByComparator);
1585                            }
1586                    }
1587    
1588                    else {
1589                            if (getDB().isSupportsInlineDistinct()) {
1590                                    query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1591                            }
1592                            else {
1593                                    query.append(WikiNodeModelImpl.ORDER_BY_SQL);
1594                            }
1595                    }
1596    
1597                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1598                                    WikiNode.class.getName(),
1599                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1600    
1601                    Session session = null;
1602    
1603                    try {
1604                            session = openSession();
1605    
1606                            SQLQuery q = session.createSQLQuery(sql);
1607    
1608                            if (getDB().isSupportsInlineDistinct()) {
1609                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiNodeImpl.class);
1610                            }
1611                            else {
1612                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiNodeImpl.class);
1613                            }
1614    
1615                            QueryPos qPos = QueryPos.getInstance(q);
1616    
1617                            qPos.add(groupId);
1618    
1619                            return (List<WikiNode>)QueryUtil.list(q, getDialect(), start, end);
1620                    }
1621                    catch (Exception e) {
1622                            throw processException(e);
1623                    }
1624                    finally {
1625                            closeSession(session);
1626                    }
1627            }
1628    
1629            /**
1630             * 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;.
1631             *
1632             * @param nodeId the primary key of the current wiki node
1633             * @param groupId the group ID
1634             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1635             * @return the previous, current, and next wiki node
1636             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
1637             * @throws SystemException if a system exception occurred
1638             */
1639            public WikiNode[] filterFindByGroupId_PrevAndNext(long nodeId,
1640                    long groupId, OrderByComparator orderByComparator)
1641                    throws NoSuchNodeException, SystemException {
1642                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1643                            return findByGroupId_PrevAndNext(nodeId, groupId, orderByComparator);
1644                    }
1645    
1646                    WikiNode wikiNode = findByPrimaryKey(nodeId);
1647    
1648                    Session session = null;
1649    
1650                    try {
1651                            session = openSession();
1652    
1653                            WikiNode[] array = new WikiNodeImpl[3];
1654    
1655                            array[0] = filterGetByGroupId_PrevAndNext(session, wikiNode,
1656                                            groupId, orderByComparator, true);
1657    
1658                            array[1] = wikiNode;
1659    
1660                            array[2] = filterGetByGroupId_PrevAndNext(session, wikiNode,
1661                                            groupId, orderByComparator, false);
1662    
1663                            return array;
1664                    }
1665                    catch (Exception e) {
1666                            throw processException(e);
1667                    }
1668                    finally {
1669                            closeSession(session);
1670                    }
1671            }
1672    
1673            protected WikiNode filterGetByGroupId_PrevAndNext(Session session,
1674                    WikiNode wikiNode, long groupId, OrderByComparator orderByComparator,
1675                    boolean previous) {
1676                    StringBundler query = null;
1677    
1678                    if (orderByComparator != null) {
1679                            query = new StringBundler(6 +
1680                                            (orderByComparator.getOrderByFields().length * 6));
1681                    }
1682                    else {
1683                            query = new StringBundler(3);
1684                    }
1685    
1686                    if (getDB().isSupportsInlineDistinct()) {
1687                            query.append(_FILTER_SQL_SELECT_WIKINODE_WHERE);
1688                    }
1689                    else {
1690                            query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_1);
1691                    }
1692    
1693                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1694    
1695                    if (!getDB().isSupportsInlineDistinct()) {
1696                            query.append(_FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_2);
1697                    }
1698    
1699                    if (orderByComparator != null) {
1700                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1701    
1702                            if (orderByConditionFields.length > 0) {
1703                                    query.append(WHERE_AND);
1704                            }
1705    
1706                            for (int i = 0; i < orderByConditionFields.length; i++) {
1707                                    if (getDB().isSupportsInlineDistinct()) {
1708                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1709                                    }
1710                                    else {
1711                                            query.append(_ORDER_BY_ENTITY_TABLE);
1712                                    }
1713    
1714                                    query.append(orderByConditionFields[i]);
1715    
1716                                    if ((i + 1) < orderByConditionFields.length) {
1717                                            if (orderByComparator.isAscending() ^ previous) {
1718                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1719                                            }
1720                                            else {
1721                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1722                                            }
1723                                    }
1724                                    else {
1725                                            if (orderByComparator.isAscending() ^ previous) {
1726                                                    query.append(WHERE_GREATER_THAN);
1727                                            }
1728                                            else {
1729                                                    query.append(WHERE_LESSER_THAN);
1730                                            }
1731                                    }
1732                            }
1733    
1734                            query.append(ORDER_BY_CLAUSE);
1735    
1736                            String[] orderByFields = orderByComparator.getOrderByFields();
1737    
1738                            for (int i = 0; i < orderByFields.length; i++) {
1739                                    if (getDB().isSupportsInlineDistinct()) {
1740                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1741                                    }
1742                                    else {
1743                                            query.append(_ORDER_BY_ENTITY_TABLE);
1744                                    }
1745    
1746                                    query.append(orderByFields[i]);
1747    
1748                                    if ((i + 1) < orderByFields.length) {
1749                                            if (orderByComparator.isAscending() ^ previous) {
1750                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1751                                            }
1752                                            else {
1753                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1754                                            }
1755                                    }
1756                                    else {
1757                                            if (orderByComparator.isAscending() ^ previous) {
1758                                                    query.append(ORDER_BY_ASC);
1759                                            }
1760                                            else {
1761                                                    query.append(ORDER_BY_DESC);
1762                                            }
1763                                    }
1764                            }
1765                    }
1766    
1767                    else {
1768                            if (getDB().isSupportsInlineDistinct()) {
1769                                    query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1770                            }
1771                            else {
1772                                    query.append(WikiNodeModelImpl.ORDER_BY_SQL);
1773                            }
1774                    }
1775    
1776                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1777                                    WikiNode.class.getName(),
1778                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1779    
1780                    SQLQuery q = session.createSQLQuery(sql);
1781    
1782                    q.setFirstResult(0);
1783                    q.setMaxResults(2);
1784    
1785                    if (getDB().isSupportsInlineDistinct()) {
1786                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiNodeImpl.class);
1787                    }
1788                    else {
1789                            q.addEntity(_FILTER_ENTITY_TABLE, WikiNodeImpl.class);
1790                    }
1791    
1792                    QueryPos qPos = QueryPos.getInstance(q);
1793    
1794                    qPos.add(groupId);
1795    
1796                    if (orderByComparator != null) {
1797                            Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
1798    
1799                            for (Object value : values) {
1800                                    qPos.add(value);
1801                            }
1802                    }
1803    
1804                    List<WikiNode> list = q.list();
1805    
1806                    if (list.size() == 2) {
1807                            return list.get(1);
1808                    }
1809                    else {
1810                            return null;
1811                    }
1812            }
1813    
1814            /**
1815             * Returns all the wiki nodes where companyId = &#63;.
1816             *
1817             * @param companyId the company ID
1818             * @return the matching wiki nodes
1819             * @throws SystemException if a system exception occurred
1820             */
1821            public List<WikiNode> findByCompanyId(long companyId)
1822                    throws SystemException {
1823                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1824                            null);
1825            }
1826    
1827            /**
1828             * Returns a range of all the wiki nodes where companyId = &#63;.
1829             *
1830             * <p>
1831             * 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.
1832             * </p>
1833             *
1834             * @param companyId the company ID
1835             * @param start the lower bound of the range of wiki nodes
1836             * @param end the upper bound of the range of wiki nodes (not inclusive)
1837             * @return the range of matching wiki nodes
1838             * @throws SystemException if a system exception occurred
1839             */
1840            public List<WikiNode> findByCompanyId(long companyId, int start, int end)
1841                    throws SystemException {
1842                    return findByCompanyId(companyId, start, end, null);
1843            }
1844    
1845            /**
1846             * Returns an ordered range of all the wiki nodes where companyId = &#63;.
1847             *
1848             * <p>
1849             * 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.
1850             * </p>
1851             *
1852             * @param companyId the company ID
1853             * @param start the lower bound of the range of wiki nodes
1854             * @param end the upper bound of the range of wiki nodes (not inclusive)
1855             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1856             * @return the ordered range of matching wiki nodes
1857             * @throws SystemException if a system exception occurred
1858             */
1859            public List<WikiNode> findByCompanyId(long companyId, int start, int end,
1860                    OrderByComparator orderByComparator) throws SystemException {
1861                    FinderPath finderPath = null;
1862                    Object[] finderArgs = null;
1863    
1864                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1865                                    (orderByComparator == null)) {
1866                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1867                            finderArgs = new Object[] { companyId };
1868                    }
1869                    else {
1870                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1871                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1872                    }
1873    
1874                    List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
1875                                    finderArgs, this);
1876    
1877                    if (list == null) {
1878                            StringBundler query = null;
1879    
1880                            if (orderByComparator != null) {
1881                                    query = new StringBundler(3 +
1882                                                    (orderByComparator.getOrderByFields().length * 3));
1883                            }
1884                            else {
1885                                    query = new StringBundler(3);
1886                            }
1887    
1888                            query.append(_SQL_SELECT_WIKINODE_WHERE);
1889    
1890                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1891    
1892                            if (orderByComparator != null) {
1893                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1894                                            orderByComparator);
1895                            }
1896    
1897                            else {
1898                                    query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1899                            }
1900    
1901                            String sql = query.toString();
1902    
1903                            Session session = null;
1904    
1905                            try {
1906                                    session = openSession();
1907    
1908                                    Query q = session.createQuery(sql);
1909    
1910                                    QueryPos qPos = QueryPos.getInstance(q);
1911    
1912                                    qPos.add(companyId);
1913    
1914                                    list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
1915                                                    end);
1916                            }
1917                            catch (Exception e) {
1918                                    throw processException(e);
1919                            }
1920                            finally {
1921                                    if (list == null) {
1922                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1923                                    }
1924                                    else {
1925                                            cacheResult(list);
1926    
1927                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1928                                    }
1929    
1930                                    closeSession(session);
1931                            }
1932                    }
1933    
1934                    return list;
1935            }
1936    
1937            /**
1938             * Returns the first wiki node in the ordered set where companyId = &#63;.
1939             *
1940             * <p>
1941             * 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.
1942             * </p>
1943             *
1944             * @param companyId the company ID
1945             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1946             * @return the first matching wiki node
1947             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
1948             * @throws SystemException if a system exception occurred
1949             */
1950            public WikiNode findByCompanyId_First(long companyId,
1951                    OrderByComparator orderByComparator)
1952                    throws NoSuchNodeException, SystemException {
1953                    List<WikiNode> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1954    
1955                    if (list.isEmpty()) {
1956                            StringBundler msg = new StringBundler(4);
1957    
1958                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1959    
1960                            msg.append("companyId=");
1961                            msg.append(companyId);
1962    
1963                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1964    
1965                            throw new NoSuchNodeException(msg.toString());
1966                    }
1967                    else {
1968                            return list.get(0);
1969                    }
1970            }
1971    
1972            /**
1973             * Returns the last wiki node in the ordered set where companyId = &#63;.
1974             *
1975             * <p>
1976             * 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.
1977             * </p>
1978             *
1979             * @param companyId the company ID
1980             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1981             * @return the last matching wiki node
1982             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
1983             * @throws SystemException if a system exception occurred
1984             */
1985            public WikiNode findByCompanyId_Last(long companyId,
1986                    OrderByComparator orderByComparator)
1987                    throws NoSuchNodeException, SystemException {
1988                    int count = countByCompanyId(companyId);
1989    
1990                    List<WikiNode> list = findByCompanyId(companyId, count - 1, count,
1991                                    orderByComparator);
1992    
1993                    if (list.isEmpty()) {
1994                            StringBundler msg = new StringBundler(4);
1995    
1996                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1997    
1998                            msg.append("companyId=");
1999                            msg.append(companyId);
2000    
2001                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2002    
2003                            throw new NoSuchNodeException(msg.toString());
2004                    }
2005                    else {
2006                            return list.get(0);
2007                    }
2008            }
2009    
2010            /**
2011             * Returns the wiki nodes before and after the current wiki node in the ordered set where companyId = &#63;.
2012             *
2013             * <p>
2014             * 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.
2015             * </p>
2016             *
2017             * @param nodeId the primary key of the current wiki node
2018             * @param companyId the company ID
2019             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2020             * @return the previous, current, and next wiki node
2021             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a wiki node with the primary key could not be found
2022             * @throws SystemException if a system exception occurred
2023             */
2024            public WikiNode[] findByCompanyId_PrevAndNext(long nodeId, long companyId,
2025                    OrderByComparator orderByComparator)
2026                    throws NoSuchNodeException, SystemException {
2027                    WikiNode wikiNode = findByPrimaryKey(nodeId);
2028    
2029                    Session session = null;
2030    
2031                    try {
2032                            session = openSession();
2033    
2034                            WikiNode[] array = new WikiNodeImpl[3];
2035    
2036                            array[0] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
2037                                            orderByComparator, true);
2038    
2039                            array[1] = wikiNode;
2040    
2041                            array[2] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
2042                                            orderByComparator, false);
2043    
2044                            return array;
2045                    }
2046                    catch (Exception e) {
2047                            throw processException(e);
2048                    }
2049                    finally {
2050                            closeSession(session);
2051                    }
2052            }
2053    
2054            protected WikiNode getByCompanyId_PrevAndNext(Session session,
2055                    WikiNode wikiNode, long companyId, OrderByComparator orderByComparator,
2056                    boolean previous) {
2057                    StringBundler query = null;
2058    
2059                    if (orderByComparator != null) {
2060                            query = new StringBundler(6 +
2061                                            (orderByComparator.getOrderByFields().length * 6));
2062                    }
2063                    else {
2064                            query = new StringBundler(3);
2065                    }
2066    
2067                    query.append(_SQL_SELECT_WIKINODE_WHERE);
2068    
2069                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2070    
2071                    if (orderByComparator != null) {
2072                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2073    
2074                            if (orderByConditionFields.length > 0) {
2075                                    query.append(WHERE_AND);
2076                            }
2077    
2078                            for (int i = 0; i < orderByConditionFields.length; i++) {
2079                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2080                                    query.append(orderByConditionFields[i]);
2081    
2082                                    if ((i + 1) < orderByConditionFields.length) {
2083                                            if (orderByComparator.isAscending() ^ previous) {
2084                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2085                                            }
2086                                            else {
2087                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2088                                            }
2089                                    }
2090                                    else {
2091                                            if (orderByComparator.isAscending() ^ previous) {
2092                                                    query.append(WHERE_GREATER_THAN);
2093                                            }
2094                                            else {
2095                                                    query.append(WHERE_LESSER_THAN);
2096                                            }
2097                                    }
2098                            }
2099    
2100                            query.append(ORDER_BY_CLAUSE);
2101    
2102                            String[] orderByFields = orderByComparator.getOrderByFields();
2103    
2104                            for (int i = 0; i < orderByFields.length; i++) {
2105                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2106                                    query.append(orderByFields[i]);
2107    
2108                                    if ((i + 1) < orderByFields.length) {
2109                                            if (orderByComparator.isAscending() ^ previous) {
2110                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2111                                            }
2112                                            else {
2113                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2114                                            }
2115                                    }
2116                                    else {
2117                                            if (orderByComparator.isAscending() ^ previous) {
2118                                                    query.append(ORDER_BY_ASC);
2119                                            }
2120                                            else {
2121                                                    query.append(ORDER_BY_DESC);
2122                                            }
2123                                    }
2124                            }
2125                    }
2126    
2127                    else {
2128                            query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
2129                    }
2130    
2131                    String sql = query.toString();
2132    
2133                    Query q = session.createQuery(sql);
2134    
2135                    q.setFirstResult(0);
2136                    q.setMaxResults(2);
2137    
2138                    QueryPos qPos = QueryPos.getInstance(q);
2139    
2140                    qPos.add(companyId);
2141    
2142                    if (orderByComparator != null) {
2143                            Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
2144    
2145                            for (Object value : values) {
2146                                    qPos.add(value);
2147                            }
2148                    }
2149    
2150                    List<WikiNode> list = q.list();
2151    
2152                    if (list.size() == 2) {
2153                            return list.get(1);
2154                    }
2155                    else {
2156                            return null;
2157                    }
2158            }
2159    
2160            /**
2161             * 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.
2162             *
2163             * @param groupId the group ID
2164             * @param name the name
2165             * @return the matching wiki node
2166             * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
2167             * @throws SystemException if a system exception occurred
2168             */
2169            public WikiNode findByG_N(long groupId, String name)
2170                    throws NoSuchNodeException, SystemException {
2171                    WikiNode wikiNode = fetchByG_N(groupId, name);
2172    
2173                    if (wikiNode == null) {
2174                            StringBundler msg = new StringBundler(6);
2175    
2176                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2177    
2178                            msg.append("groupId=");
2179                            msg.append(groupId);
2180    
2181                            msg.append(", name=");
2182                            msg.append(name);
2183    
2184                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2185    
2186                            if (_log.isWarnEnabled()) {
2187                                    _log.warn(msg.toString());
2188                            }
2189    
2190                            throw new NoSuchNodeException(msg.toString());
2191                    }
2192    
2193                    return wikiNode;
2194            }
2195    
2196            /**
2197             * 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.
2198             *
2199             * @param groupId the group ID
2200             * @param name the name
2201             * @return the matching wiki node, or <code>null</code> if a matching wiki node could not be found
2202             * @throws SystemException if a system exception occurred
2203             */
2204            public WikiNode fetchByG_N(long groupId, String name)
2205                    throws SystemException {
2206                    return fetchByG_N(groupId, name, true);
2207            }
2208    
2209            /**
2210             * 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.
2211             *
2212             * @param groupId the group ID
2213             * @param name the name
2214             * @param retrieveFromCache whether to use the finder cache
2215             * @return the matching wiki node, or <code>null</code> if a matching wiki node could not be found
2216             * @throws SystemException if a system exception occurred
2217             */
2218            public WikiNode fetchByG_N(long groupId, String name,
2219                    boolean retrieveFromCache) throws SystemException {
2220                    Object[] finderArgs = new Object[] { groupId, name };
2221    
2222                    Object result = null;
2223    
2224                    if (retrieveFromCache) {
2225                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
2226                                            finderArgs, this);
2227                    }
2228    
2229                    if (result == null) {
2230                            StringBundler query = new StringBundler(4);
2231    
2232                            query.append(_SQL_SELECT_WIKINODE_WHERE);
2233    
2234                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2235    
2236                            if (name == null) {
2237                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
2238                            }
2239                            else {
2240                                    if (name.equals(StringPool.BLANK)) {
2241                                            query.append(_FINDER_COLUMN_G_N_NAME_3);
2242                                    }
2243                                    else {
2244                                            query.append(_FINDER_COLUMN_G_N_NAME_2);
2245                                    }
2246                            }
2247    
2248                            query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
2249    
2250                            String sql = query.toString();
2251    
2252                            Session session = null;
2253    
2254                            try {
2255                                    session = openSession();
2256    
2257                                    Query q = session.createQuery(sql);
2258    
2259                                    QueryPos qPos = QueryPos.getInstance(q);
2260    
2261                                    qPos.add(groupId);
2262    
2263                                    if (name != null) {
2264                                            qPos.add(name);
2265                                    }
2266    
2267                                    List<WikiNode> list = q.list();
2268    
2269                                    result = list;
2270    
2271                                    WikiNode wikiNode = null;
2272    
2273                                    if (list.isEmpty()) {
2274                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
2275                                                    finderArgs, list);
2276                                    }
2277                                    else {
2278                                            wikiNode = list.get(0);
2279    
2280                                            cacheResult(wikiNode);
2281    
2282                                            if ((wikiNode.getGroupId() != groupId) ||
2283                                                            (wikiNode.getName() == null) ||
2284                                                            !wikiNode.getName().equals(name)) {
2285                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
2286                                                            finderArgs, wikiNode);
2287                                            }
2288                                    }
2289    
2290                                    return wikiNode;
2291                            }
2292                            catch (Exception e) {
2293                                    throw processException(e);
2294                            }
2295                            finally {
2296                                    if (result == null) {
2297                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
2298                                                    finderArgs);
2299                                    }
2300    
2301                                    closeSession(session);
2302                            }
2303                    }
2304                    else {
2305                            if (result instanceof List<?>) {
2306                                    return null;
2307                            }
2308                            else {
2309                                    return (WikiNode)result;
2310                            }
2311                    }
2312            }
2313    
2314            /**
2315             * Returns all the wiki nodes.
2316             *
2317             * @return the wiki nodes
2318             * @throws SystemException if a system exception occurred
2319             */
2320            public List<WikiNode> findAll() throws SystemException {
2321                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2322            }
2323    
2324            /**
2325             * Returns a range of all the wiki nodes.
2326             *
2327             * <p>
2328             * 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.
2329             * </p>
2330             *
2331             * @param start the lower bound of the range of wiki nodes
2332             * @param end the upper bound of the range of wiki nodes (not inclusive)
2333             * @return the range of wiki nodes
2334             * @throws SystemException if a system exception occurred
2335             */
2336            public List<WikiNode> findAll(int start, int end) throws SystemException {
2337                    return findAll(start, end, null);
2338            }
2339    
2340            /**
2341             * Returns an ordered range of all the wiki nodes.
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.
2345             * </p>
2346             *
2347             * @param start the lower bound of the range of wiki nodes
2348             * @param end the upper bound of the range of wiki nodes (not inclusive)
2349             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2350             * @return the ordered range of wiki nodes
2351             * @throws SystemException if a system exception occurred
2352             */
2353            public List<WikiNode> findAll(int start, int end,
2354                    OrderByComparator orderByComparator) throws SystemException {
2355                    FinderPath finderPath = null;
2356                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
2357    
2358                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2359                                    (orderByComparator == null)) {
2360                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2361                            finderArgs = FINDER_ARGS_EMPTY;
2362                    }
2363                    else {
2364                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2365                            finderArgs = new Object[] { start, end, orderByComparator };
2366                    }
2367    
2368                    List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(finderPath,
2369                                    finderArgs, this);
2370    
2371                    if (list == null) {
2372                            StringBundler query = null;
2373                            String sql = null;
2374    
2375                            if (orderByComparator != null) {
2376                                    query = new StringBundler(2 +
2377                                                    (orderByComparator.getOrderByFields().length * 3));
2378    
2379                                    query.append(_SQL_SELECT_WIKINODE);
2380    
2381                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2382                                            orderByComparator);
2383    
2384                                    sql = query.toString();
2385                            }
2386                            else {
2387                                    sql = _SQL_SELECT_WIKINODE.concat(WikiNodeModelImpl.ORDER_BY_JPQL);
2388                            }
2389    
2390                            Session session = null;
2391    
2392                            try {
2393                                    session = openSession();
2394    
2395                                    Query q = session.createQuery(sql);
2396    
2397                                    if (orderByComparator == null) {
2398                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
2399                                                            start, end, false);
2400    
2401                                            Collections.sort(list);
2402                                    }
2403                                    else {
2404                                            list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
2405                                                            start, end);
2406                                    }
2407                            }
2408                            catch (Exception e) {
2409                                    throw processException(e);
2410                            }
2411                            finally {
2412                                    if (list == null) {
2413                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2414                                    }
2415                                    else {
2416                                            cacheResult(list);
2417    
2418                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2419                                    }
2420    
2421                                    closeSession(session);
2422                            }
2423                    }
2424    
2425                    return list;
2426            }
2427    
2428            /**
2429             * Removes all the wiki nodes where uuid = &#63; from the database.
2430             *
2431             * @param uuid the uuid
2432             * @throws SystemException if a system exception occurred
2433             */
2434            public void removeByUuid(String uuid) throws SystemException {
2435                    for (WikiNode wikiNode : findByUuid(uuid)) {
2436                            remove(wikiNode);
2437                    }
2438            }
2439    
2440            /**
2441             * Removes the wiki node where uuid = &#63; and groupId = &#63; from the database.
2442             *
2443             * @param uuid the uuid
2444             * @param groupId the group ID
2445             * @throws SystemException if a system exception occurred
2446             */
2447            public void removeByUUID_G(String uuid, long groupId)
2448                    throws NoSuchNodeException, SystemException {
2449                    WikiNode wikiNode = findByUUID_G(uuid, groupId);
2450    
2451                    remove(wikiNode);
2452            }
2453    
2454            /**
2455             * Removes all the wiki nodes where groupId = &#63; from the database.
2456             *
2457             * @param groupId the group ID
2458             * @throws SystemException if a system exception occurred
2459             */
2460            public void removeByGroupId(long groupId) throws SystemException {
2461                    for (WikiNode wikiNode : findByGroupId(groupId)) {
2462                            remove(wikiNode);
2463                    }
2464            }
2465    
2466            /**
2467             * Removes all the wiki nodes where companyId = &#63; from the database.
2468             *
2469             * @param companyId the company ID
2470             * @throws SystemException if a system exception occurred
2471             */
2472            public void removeByCompanyId(long companyId) throws SystemException {
2473                    for (WikiNode wikiNode : findByCompanyId(companyId)) {
2474                            remove(wikiNode);
2475                    }
2476            }
2477    
2478            /**
2479             * Removes the wiki node where groupId = &#63; and name = &#63; from the database.
2480             *
2481             * @param groupId the group ID
2482             * @param name the name
2483             * @throws SystemException if a system exception occurred
2484             */
2485            public void removeByG_N(long groupId, String name)
2486                    throws NoSuchNodeException, SystemException {
2487                    WikiNode wikiNode = findByG_N(groupId, name);
2488    
2489                    remove(wikiNode);
2490            }
2491    
2492            /**
2493             * Removes all the wiki nodes from the database.
2494             *
2495             * @throws SystemException if a system exception occurred
2496             */
2497            public void removeAll() throws SystemException {
2498                    for (WikiNode wikiNode : findAll()) {
2499                            remove(wikiNode);
2500                    }
2501            }
2502    
2503            /**
2504             * Returns the number of wiki nodes where uuid = &#63;.
2505             *
2506             * @param uuid the uuid
2507             * @return the number of matching wiki nodes
2508             * @throws SystemException if a system exception occurred
2509             */
2510            public int countByUuid(String uuid) throws SystemException {
2511                    Object[] finderArgs = new Object[] { uuid };
2512    
2513                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2514                                    finderArgs, this);
2515    
2516                    if (count == null) {
2517                            StringBundler query = new StringBundler(2);
2518    
2519                            query.append(_SQL_COUNT_WIKINODE_WHERE);
2520    
2521                            if (uuid == null) {
2522                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
2523                            }
2524                            else {
2525                                    if (uuid.equals(StringPool.BLANK)) {
2526                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
2527                                    }
2528                                    else {
2529                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
2530                                    }
2531                            }
2532    
2533                            String sql = query.toString();
2534    
2535                            Session session = null;
2536    
2537                            try {
2538                                    session = openSession();
2539    
2540                                    Query q = session.createQuery(sql);
2541    
2542                                    QueryPos qPos = QueryPos.getInstance(q);
2543    
2544                                    if (uuid != null) {
2545                                            qPos.add(uuid);
2546                                    }
2547    
2548                                    count = (Long)q.uniqueResult();
2549                            }
2550                            catch (Exception e) {
2551                                    throw processException(e);
2552                            }
2553                            finally {
2554                                    if (count == null) {
2555                                            count = Long.valueOf(0);
2556                                    }
2557    
2558                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2559                                            finderArgs, count);
2560    
2561                                    closeSession(session);
2562                            }
2563                    }
2564    
2565                    return count.intValue();
2566            }
2567    
2568            /**
2569             * Returns the number of wiki nodes where uuid = &#63; and groupId = &#63;.
2570             *
2571             * @param uuid the uuid
2572             * @param groupId the group ID
2573             * @return the number of matching wiki nodes
2574             * @throws SystemException if a system exception occurred
2575             */
2576            public int countByUUID_G(String uuid, long groupId)
2577                    throws SystemException {
2578                    Object[] finderArgs = new Object[] { uuid, groupId };
2579    
2580                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2581                                    finderArgs, this);
2582    
2583                    if (count == null) {
2584                            StringBundler query = new StringBundler(3);
2585    
2586                            query.append(_SQL_COUNT_WIKINODE_WHERE);
2587    
2588                            if (uuid == null) {
2589                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2590                            }
2591                            else {
2592                                    if (uuid.equals(StringPool.BLANK)) {
2593                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2594                                    }
2595                                    else {
2596                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2597                                    }
2598                            }
2599    
2600                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2601    
2602                            String sql = query.toString();
2603    
2604                            Session session = null;
2605    
2606                            try {
2607                                    session = openSession();
2608    
2609                                    Query q = session.createQuery(sql);
2610    
2611                                    QueryPos qPos = QueryPos.getInstance(q);
2612    
2613                                    if (uuid != null) {
2614                                            qPos.add(uuid);
2615                                    }
2616    
2617                                    qPos.add(groupId);
2618    
2619                                    count = (Long)q.uniqueResult();
2620                            }
2621                            catch (Exception e) {
2622                                    throw processException(e);
2623                            }
2624                            finally {
2625                                    if (count == null) {
2626                                            count = Long.valueOf(0);
2627                                    }
2628    
2629                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2630                                            finderArgs, count);
2631    
2632                                    closeSession(session);
2633                            }
2634                    }
2635    
2636                    return count.intValue();
2637            }
2638    
2639            /**
2640             * Returns the number of wiki nodes where groupId = &#63;.
2641             *
2642             * @param groupId the group ID
2643             * @return the number of matching wiki nodes
2644             * @throws SystemException if a system exception occurred
2645             */
2646            public int countByGroupId(long groupId) throws SystemException {
2647                    Object[] finderArgs = new Object[] { groupId };
2648    
2649                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2650                                    finderArgs, this);
2651    
2652                    if (count == null) {
2653                            StringBundler query = new StringBundler(2);
2654    
2655                            query.append(_SQL_COUNT_WIKINODE_WHERE);
2656    
2657                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2658    
2659                            String sql = query.toString();
2660    
2661                            Session session = null;
2662    
2663                            try {
2664                                    session = openSession();
2665    
2666                                    Query q = session.createQuery(sql);
2667    
2668                                    QueryPos qPos = QueryPos.getInstance(q);
2669    
2670                                    qPos.add(groupId);
2671    
2672                                    count = (Long)q.uniqueResult();
2673                            }
2674                            catch (Exception e) {
2675                                    throw processException(e);
2676                            }
2677                            finally {
2678                                    if (count == null) {
2679                                            count = Long.valueOf(0);
2680                                    }
2681    
2682                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2683                                            finderArgs, count);
2684    
2685                                    closeSession(session);
2686                            }
2687                    }
2688    
2689                    return count.intValue();
2690            }
2691    
2692            /**
2693             * Returns the number of wiki nodes that the user has permission to view where groupId = &#63;.
2694             *
2695             * @param groupId the group ID
2696             * @return the number of matching wiki nodes that the user has permission to view
2697             * @throws SystemException if a system exception occurred
2698             */
2699            public int filterCountByGroupId(long groupId) throws SystemException {
2700                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2701                            return countByGroupId(groupId);
2702                    }
2703    
2704                    StringBundler query = new StringBundler(2);
2705    
2706                    query.append(_FILTER_SQL_COUNT_WIKINODE_WHERE);
2707    
2708                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2709    
2710                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2711                                    WikiNode.class.getName(),
2712                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2713    
2714                    Session session = null;
2715    
2716                    try {
2717                            session = openSession();
2718    
2719                            SQLQuery q = session.createSQLQuery(sql);
2720    
2721                            q.addScalar(COUNT_COLUMN_NAME,
2722                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2723    
2724                            QueryPos qPos = QueryPos.getInstance(q);
2725    
2726                            qPos.add(groupId);
2727    
2728                            Long count = (Long)q.uniqueResult();
2729    
2730                            return count.intValue();
2731                    }
2732                    catch (Exception e) {
2733                            throw processException(e);
2734                    }
2735                    finally {
2736                            closeSession(session);
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            public int countByCompanyId(long companyId) throws SystemException {
2748                    Object[] finderArgs = new Object[] { companyId };
2749    
2750                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2751                                    finderArgs, this);
2752    
2753                    if (count == null) {
2754                            StringBundler query = new StringBundler(2);
2755    
2756                            query.append(_SQL_COUNT_WIKINODE_WHERE);
2757    
2758                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2759    
2760                            String sql = query.toString();
2761    
2762                            Session session = null;
2763    
2764                            try {
2765                                    session = openSession();
2766    
2767                                    Query q = session.createQuery(sql);
2768    
2769                                    QueryPos qPos = QueryPos.getInstance(q);
2770    
2771                                    qPos.add(companyId);
2772    
2773                                    count = (Long)q.uniqueResult();
2774                            }
2775                            catch (Exception e) {
2776                                    throw processException(e);
2777                            }
2778                            finally {
2779                                    if (count == null) {
2780                                            count = Long.valueOf(0);
2781                                    }
2782    
2783                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2784                                            finderArgs, count);
2785    
2786                                    closeSession(session);
2787                            }
2788                    }
2789    
2790                    return count.intValue();
2791            }
2792    
2793            /**
2794             * Returns the number of wiki nodes where groupId = &#63; and name = &#63;.
2795             *
2796             * @param groupId the group ID
2797             * @param name the name
2798             * @return the number of matching wiki nodes
2799             * @throws SystemException if a system exception occurred
2800             */
2801            public int countByG_N(long groupId, String name) throws SystemException {
2802                    Object[] finderArgs = new Object[] { groupId, name };
2803    
2804                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
2805                                    finderArgs, this);
2806    
2807                    if (count == null) {
2808                            StringBundler query = new StringBundler(3);
2809    
2810                            query.append(_SQL_COUNT_WIKINODE_WHERE);
2811    
2812                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2813    
2814                            if (name == null) {
2815                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
2816                            }
2817                            else {
2818                                    if (name.equals(StringPool.BLANK)) {
2819                                            query.append(_FINDER_COLUMN_G_N_NAME_3);
2820                                    }
2821                                    else {
2822                                            query.append(_FINDER_COLUMN_G_N_NAME_2);
2823                                    }
2824                            }
2825    
2826                            String sql = query.toString();
2827    
2828                            Session session = null;
2829    
2830                            try {
2831                                    session = openSession();
2832    
2833                                    Query q = session.createQuery(sql);
2834    
2835                                    QueryPos qPos = QueryPos.getInstance(q);
2836    
2837                                    qPos.add(groupId);
2838    
2839                                    if (name != null) {
2840                                            qPos.add(name);
2841                                    }
2842    
2843                                    count = (Long)q.uniqueResult();
2844                            }
2845                            catch (Exception e) {
2846                                    throw processException(e);
2847                            }
2848                            finally {
2849                                    if (count == null) {
2850                                            count = Long.valueOf(0);
2851                                    }
2852    
2853                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
2854                                            count);
2855    
2856                                    closeSession(session);
2857                            }
2858                    }
2859    
2860                    return count.intValue();
2861            }
2862    
2863            /**
2864             * Returns the number of wiki nodes.
2865             *
2866             * @return the number of wiki nodes
2867             * @throws SystemException if a system exception occurred
2868             */
2869            public int countAll() throws SystemException {
2870                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2871                                    FINDER_ARGS_EMPTY, this);
2872    
2873                    if (count == null) {
2874                            Session session = null;
2875    
2876                            try {
2877                                    session = openSession();
2878    
2879                                    Query q = session.createQuery(_SQL_COUNT_WIKINODE);
2880    
2881                                    count = (Long)q.uniqueResult();
2882                            }
2883                            catch (Exception e) {
2884                                    throw processException(e);
2885                            }
2886                            finally {
2887                                    if (count == null) {
2888                                            count = Long.valueOf(0);
2889                                    }
2890    
2891                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2892                                            FINDER_ARGS_EMPTY, count);
2893    
2894                                    closeSession(session);
2895                            }
2896                    }
2897    
2898                    return count.intValue();
2899            }
2900    
2901            /**
2902             * Initializes the wiki node persistence.
2903             */
2904            public void afterPropertiesSet() {
2905                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2906                                            com.liferay.portal.util.PropsUtil.get(
2907                                                    "value.object.listener.com.liferay.portlet.wiki.model.WikiNode")));
2908    
2909                    if (listenerClassNames.length > 0) {
2910                            try {
2911                                    List<ModelListener<WikiNode>> listenersList = new ArrayList<ModelListener<WikiNode>>();
2912    
2913                                    for (String listenerClassName : listenerClassNames) {
2914                                            listenersList.add((ModelListener<WikiNode>)InstanceFactory.newInstance(
2915                                                            listenerClassName));
2916                                    }
2917    
2918                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2919                            }
2920                            catch (Exception e) {
2921                                    _log.error(e);
2922                            }
2923                    }
2924            }
2925    
2926            public void destroy() {
2927                    EntityCacheUtil.removeCache(WikiNodeImpl.class.getName());
2928                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2929                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2930            }
2931    
2932            @BeanReference(type = WikiNodePersistence.class)
2933            protected WikiNodePersistence wikiNodePersistence;
2934            @BeanReference(type = WikiPagePersistence.class)
2935            protected WikiPagePersistence wikiPagePersistence;
2936            @BeanReference(type = WikiPageResourcePersistence.class)
2937            protected WikiPageResourcePersistence wikiPageResourcePersistence;
2938            @BeanReference(type = GroupPersistence.class)
2939            protected GroupPersistence groupPersistence;
2940            @BeanReference(type = ResourcePersistence.class)
2941            protected ResourcePersistence resourcePersistence;
2942            @BeanReference(type = SubscriptionPersistence.class)
2943            protected SubscriptionPersistence subscriptionPersistence;
2944            @BeanReference(type = UserPersistence.class)
2945            protected UserPersistence userPersistence;
2946            private static final String _SQL_SELECT_WIKINODE = "SELECT wikiNode FROM WikiNode wikiNode";
2947            private static final String _SQL_SELECT_WIKINODE_WHERE = "SELECT wikiNode FROM WikiNode wikiNode WHERE ";
2948            private static final String _SQL_COUNT_WIKINODE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode";
2949            private static final String _SQL_COUNT_WIKINODE_WHERE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode WHERE ";
2950            private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiNode.uuid IS NULL";
2951            private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiNode.uuid = ?";
2952            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiNode.uuid IS NULL OR wikiNode.uuid = ?)";
2953            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "wikiNode.uuid IS NULL AND ";
2954            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "wikiNode.uuid = ? AND ";
2955            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(wikiNode.uuid IS NULL OR wikiNode.uuid = ?) AND ";
2956            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "wikiNode.groupId = ?";
2957            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "wikiNode.groupId = ?";
2958            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "wikiNode.companyId = ?";
2959            private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "wikiNode.groupId = ? AND ";
2960            private static final String _FINDER_COLUMN_G_N_NAME_1 = "wikiNode.name IS NULL";
2961            private static final String _FINDER_COLUMN_G_N_NAME_2 = "wikiNode.name = ?";
2962            private static final String _FINDER_COLUMN_G_N_NAME_3 = "(wikiNode.name IS NULL OR wikiNode.name = ?)";
2963            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "wikiNode.nodeId";
2964            private static final String _FILTER_SQL_SELECT_WIKINODE_WHERE = "SELECT DISTINCT {wikiNode.*} FROM WikiNode wikiNode WHERE ";
2965            private static final String _FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_1 =
2966                    "SELECT {WikiNode.*} FROM (SELECT DISTINCT wikiNode.nodeId FROM WikiNode wikiNode WHERE ";
2967            private static final String _FILTER_SQL_SELECT_WIKINODE_NO_INLINE_DISTINCT_WHERE_2 =
2968                    ") TEMP_TABLE INNER JOIN WikiNode ON TEMP_TABLE.nodeId = WikiNode.nodeId";
2969            private static final String _FILTER_SQL_COUNT_WIKINODE_WHERE = "SELECT COUNT(DISTINCT wikiNode.nodeId) AS COUNT_VALUE FROM WikiNode wikiNode WHERE ";
2970            private static final String _FILTER_ENTITY_ALIAS = "wikiNode";
2971            private static final String _FILTER_ENTITY_TABLE = "WikiNode";
2972            private static final String _ORDER_BY_ENTITY_ALIAS = "wikiNode.";
2973            private static final String _ORDER_BY_ENTITY_TABLE = "WikiNode.";
2974            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiNode exists with the primary key ";
2975            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiNode exists with the key {";
2976            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2977            private static Log _log = LogFactoryUtil.getLog(WikiNodePersistenceImpl.class);
2978            private static WikiNode _nullWikiNode = new WikiNodeImpl() {
2979                            @Override
2980                            public Object clone() {
2981                                    return this;
2982                            }
2983    
2984                            @Override
2985                            public CacheModel<WikiNode> toCacheModel() {
2986                                    return _nullWikiNodeCacheModel;
2987                            }
2988                    };
2989    
2990            private static CacheModel<WikiNode> _nullWikiNodeCacheModel = new CacheModel<WikiNode>() {
2991                            public WikiNode toEntityModel() {
2992                                    return _nullWikiNode;
2993                            }
2994                    };
2995    }