1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.wiki.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.kernel.annotation.BeanReference;
20  import com.liferay.portal.kernel.cache.CacheRegistry;
21  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderPath;
24  import com.liferay.portal.kernel.dao.orm.Query;
25  import com.liferay.portal.kernel.dao.orm.QueryPos;
26  import com.liferay.portal.kernel.dao.orm.QueryUtil;
27  import com.liferay.portal.kernel.dao.orm.Session;
28  import com.liferay.portal.kernel.log.Log;
29  import com.liferay.portal.kernel.log.LogFactoryUtil;
30  import com.liferay.portal.kernel.util.GetterUtil;
31  import com.liferay.portal.kernel.util.InstanceFactory;
32  import com.liferay.portal.kernel.util.OrderByComparator;
33  import com.liferay.portal.kernel.util.StringBundler;
34  import com.liferay.portal.kernel.util.StringPool;
35  import com.liferay.portal.kernel.util.StringUtil;
36  import com.liferay.portal.kernel.util.Validator;
37  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
38  import com.liferay.portal.model.ModelListener;
39  import com.liferay.portal.service.persistence.BatchSessionUtil;
40  import com.liferay.portal.service.persistence.GroupPersistence;
41  import com.liferay.portal.service.persistence.ResourcePersistence;
42  import com.liferay.portal.service.persistence.SubscriptionPersistence;
43  import com.liferay.portal.service.persistence.UserPersistence;
44  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
45  
46  import com.liferay.portlet.wiki.NoSuchNodeException;
47  import com.liferay.portlet.wiki.model.WikiNode;
48  import com.liferay.portlet.wiki.model.impl.WikiNodeImpl;
49  import com.liferay.portlet.wiki.model.impl.WikiNodeModelImpl;
50  
51  import java.io.Serializable;
52  
53  import java.util.ArrayList;
54  import java.util.Collections;
55  import java.util.List;
56  
57  /**
58   * <a href="WikiNodePersistenceImpl.java.html"><b><i>View Source</i></b></a>
59   *
60   * <p>
61   * ServiceBuilder generated this class. Modifications in this class will be
62   * overwritten the next time is generated.
63   * </p>
64   *
65   * @author    Brian Wing Shun Chan
66   * @see       WikiNodePersistence
67   * @see       WikiNodeUtil
68   * @generated
69   */
70  public class WikiNodePersistenceImpl extends BasePersistenceImpl<WikiNode>
71      implements WikiNodePersistence {
72      public static final String FINDER_CLASS_NAME_ENTITY = WikiNodeImpl.class.getName();
73      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
74          ".List";
75      public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
76              WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
77              "findByUuid",
78              new String[] {
79                  String.class.getName(),
80                  
81              "java.lang.Integer", "java.lang.Integer",
82                  "com.liferay.portal.kernel.util.OrderByComparator"
83              });
84      public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
85              WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
86              "countByUuid", new String[] { String.class.getName() });
87      public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
88              WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
89              "fetchByUUID_G",
90              new String[] { String.class.getName(), Long.class.getName() });
91      public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
92              WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
93              "countByUUID_G",
94              new String[] { String.class.getName(), Long.class.getName() });
95      public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
96              WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
97              "findByGroupId",
98              new String[] {
99                  Long.class.getName(),
100                 
101             "java.lang.Integer", "java.lang.Integer",
102                 "com.liferay.portal.kernel.util.OrderByComparator"
103             });
104     public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
105             WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
106             "countByGroupId", new String[] { Long.class.getName() });
107     public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
108             WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
109             "findByCompanyId",
110             new String[] {
111                 Long.class.getName(),
112                 
113             "java.lang.Integer", "java.lang.Integer",
114                 "com.liferay.portal.kernel.util.OrderByComparator"
115             });
116     public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
117             WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
118             "countByCompanyId", new String[] { Long.class.getName() });
119     public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
120             WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
121             "fetchByG_N",
122             new String[] { Long.class.getName(), String.class.getName() });
123     public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
124             WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
125             "countByG_N",
126             new String[] { Long.class.getName(), String.class.getName() });
127     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
128             WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
129             "findAll", new String[0]);
130     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
131             WikiNodeModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
132             "countAll", new String[0]);
133 
134     public void cacheResult(WikiNode wikiNode) {
135         EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
136             WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
137 
138         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
139             new Object[] { wikiNode.getUuid(), new Long(wikiNode.getGroupId()) },
140             wikiNode);
141 
142         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
143             new Object[] { new Long(wikiNode.getGroupId()), wikiNode.getName() },
144             wikiNode);
145     }
146 
147     public void cacheResult(List<WikiNode> wikiNodes) {
148         for (WikiNode wikiNode : wikiNodes) {
149             if (EntityCacheUtil.getResult(
150                         WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
151                         WikiNodeImpl.class, wikiNode.getPrimaryKey(), this) == null) {
152                 cacheResult(wikiNode);
153             }
154         }
155     }
156 
157     public void clearCache() {
158         CacheRegistry.clear(WikiNodeImpl.class.getName());
159         EntityCacheUtil.clearCache(WikiNodeImpl.class.getName());
160         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
161         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
162     }
163 
164     public void clearCache(WikiNode wikiNode) {
165         EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
166             WikiNodeImpl.class, wikiNode.getPrimaryKey());
167 
168         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
169             new Object[] { wikiNode.getUuid(), new Long(wikiNode.getGroupId()) });
170 
171         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
172             new Object[] { new Long(wikiNode.getGroupId()), wikiNode.getName() });
173     }
174 
175     public WikiNode create(long nodeId) {
176         WikiNode wikiNode = new WikiNodeImpl();
177 
178         wikiNode.setNew(true);
179         wikiNode.setPrimaryKey(nodeId);
180 
181         String uuid = PortalUUIDUtil.generate();
182 
183         wikiNode.setUuid(uuid);
184 
185         return wikiNode;
186     }
187 
188     public WikiNode remove(Serializable primaryKey)
189         throws NoSuchModelException, SystemException {
190         return remove(((Long)primaryKey).longValue());
191     }
192 
193     public WikiNode remove(long nodeId)
194         throws NoSuchNodeException, SystemException {
195         Session session = null;
196 
197         try {
198             session = openSession();
199 
200             WikiNode wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
201                     new Long(nodeId));
202 
203             if (wikiNode == null) {
204                 if (_log.isWarnEnabled()) {
205                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + nodeId);
206                 }
207 
208                 throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
209                     nodeId);
210             }
211 
212             return remove(wikiNode);
213         }
214         catch (NoSuchNodeException nsee) {
215             throw nsee;
216         }
217         catch (Exception e) {
218             throw processException(e);
219         }
220         finally {
221             closeSession(session);
222         }
223     }
224 
225     protected WikiNode removeImpl(WikiNode wikiNode) throws SystemException {
226         wikiNode = toUnwrappedModel(wikiNode);
227 
228         Session session = null;
229 
230         try {
231             session = openSession();
232 
233             BatchSessionUtil.delete(session, wikiNode);
234         }
235         catch (Exception e) {
236             throw processException(e);
237         }
238         finally {
239             closeSession(session);
240         }
241 
242         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
243 
244         WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
245 
246         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
247             new Object[] {
248                 wikiNodeModelImpl.getOriginalUuid(),
249                 new Long(wikiNodeModelImpl.getOriginalGroupId())
250             });
251 
252         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
253             new Object[] {
254                 new Long(wikiNodeModelImpl.getOriginalGroupId()),
255                 
256             wikiNodeModelImpl.getOriginalName()
257             });
258 
259         EntityCacheUtil.removeResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
260             WikiNodeImpl.class, wikiNode.getPrimaryKey());
261 
262         return wikiNode;
263     }
264 
265     /**
266      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
267      */
268     public WikiNode update(WikiNode wikiNode) throws SystemException {
269         if (_log.isWarnEnabled()) {
270             _log.warn(
271                 "Using the deprecated update(WikiNode wikiNode) method. Use update(WikiNode wikiNode, boolean merge) instead.");
272         }
273 
274         return update(wikiNode, false);
275     }
276 
277     public WikiNode updateImpl(
278         com.liferay.portlet.wiki.model.WikiNode wikiNode, boolean merge)
279         throws SystemException {
280         wikiNode = toUnwrappedModel(wikiNode);
281 
282         boolean isNew = wikiNode.isNew();
283 
284         WikiNodeModelImpl wikiNodeModelImpl = (WikiNodeModelImpl)wikiNode;
285 
286         if (Validator.isNull(wikiNode.getUuid())) {
287             String uuid = PortalUUIDUtil.generate();
288 
289             wikiNode.setUuid(uuid);
290         }
291 
292         Session session = null;
293 
294         try {
295             session = openSession();
296 
297             BatchSessionUtil.update(session, wikiNode, merge);
298 
299             wikiNode.setNew(false);
300         }
301         catch (Exception e) {
302             throw processException(e);
303         }
304         finally {
305             closeSession(session);
306         }
307 
308         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
309 
310         EntityCacheUtil.putResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
311             WikiNodeImpl.class, wikiNode.getPrimaryKey(), wikiNode);
312 
313         if (!isNew &&
314                 (!Validator.equals(wikiNode.getUuid(),
315                     wikiNodeModelImpl.getOriginalUuid()) ||
316                 (wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()))) {
317             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
318                 new Object[] {
319                     wikiNodeModelImpl.getOriginalUuid(),
320                     new Long(wikiNodeModelImpl.getOriginalGroupId())
321                 });
322         }
323 
324         if (isNew ||
325                 (!Validator.equals(wikiNode.getUuid(),
326                     wikiNodeModelImpl.getOriginalUuid()) ||
327                 (wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()))) {
328             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
329                 new Object[] { wikiNode.getUuid(), new Long(
330                         wikiNode.getGroupId()) }, wikiNode);
331         }
332 
333         if (!isNew &&
334                 ((wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()) ||
335                 !Validator.equals(wikiNode.getName(),
336                     wikiNodeModelImpl.getOriginalName()))) {
337             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
338                 new Object[] {
339                     new Long(wikiNodeModelImpl.getOriginalGroupId()),
340                     
341                 wikiNodeModelImpl.getOriginalName()
342                 });
343         }
344 
345         if (isNew ||
346                 ((wikiNode.getGroupId() != wikiNodeModelImpl.getOriginalGroupId()) ||
347                 !Validator.equals(wikiNode.getName(),
348                     wikiNodeModelImpl.getOriginalName()))) {
349             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
350                 new Object[] { new Long(wikiNode.getGroupId()), wikiNode.getName() },
351                 wikiNode);
352         }
353 
354         return wikiNode;
355     }
356 
357     protected WikiNode toUnwrappedModel(WikiNode wikiNode) {
358         if (wikiNode instanceof WikiNodeImpl) {
359             return wikiNode;
360         }
361 
362         WikiNodeImpl wikiNodeImpl = new WikiNodeImpl();
363 
364         wikiNodeImpl.setNew(wikiNode.isNew());
365         wikiNodeImpl.setPrimaryKey(wikiNode.getPrimaryKey());
366 
367         wikiNodeImpl.setUuid(wikiNode.getUuid());
368         wikiNodeImpl.setNodeId(wikiNode.getNodeId());
369         wikiNodeImpl.setGroupId(wikiNode.getGroupId());
370         wikiNodeImpl.setCompanyId(wikiNode.getCompanyId());
371         wikiNodeImpl.setUserId(wikiNode.getUserId());
372         wikiNodeImpl.setUserName(wikiNode.getUserName());
373         wikiNodeImpl.setCreateDate(wikiNode.getCreateDate());
374         wikiNodeImpl.setModifiedDate(wikiNode.getModifiedDate());
375         wikiNodeImpl.setName(wikiNode.getName());
376         wikiNodeImpl.setDescription(wikiNode.getDescription());
377         wikiNodeImpl.setLastPostDate(wikiNode.getLastPostDate());
378 
379         return wikiNodeImpl;
380     }
381 
382     public WikiNode findByPrimaryKey(Serializable primaryKey)
383         throws NoSuchModelException, SystemException {
384         return findByPrimaryKey(((Long)primaryKey).longValue());
385     }
386 
387     public WikiNode findByPrimaryKey(long nodeId)
388         throws NoSuchNodeException, SystemException {
389         WikiNode wikiNode = fetchByPrimaryKey(nodeId);
390 
391         if (wikiNode == null) {
392             if (_log.isWarnEnabled()) {
393                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + nodeId);
394             }
395 
396             throw new NoSuchNodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
397                 nodeId);
398         }
399 
400         return wikiNode;
401     }
402 
403     public WikiNode fetchByPrimaryKey(Serializable primaryKey)
404         throws SystemException {
405         return fetchByPrimaryKey(((Long)primaryKey).longValue());
406     }
407 
408     public WikiNode fetchByPrimaryKey(long nodeId) throws SystemException {
409         WikiNode wikiNode = (WikiNode)EntityCacheUtil.getResult(WikiNodeModelImpl.ENTITY_CACHE_ENABLED,
410                 WikiNodeImpl.class, nodeId, this);
411 
412         if (wikiNode == null) {
413             Session session = null;
414 
415             try {
416                 session = openSession();
417 
418                 wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
419                         new Long(nodeId));
420             }
421             catch (Exception e) {
422                 throw processException(e);
423             }
424             finally {
425                 if (wikiNode != null) {
426                     cacheResult(wikiNode);
427                 }
428 
429                 closeSession(session);
430             }
431         }
432 
433         return wikiNode;
434     }
435 
436     public List<WikiNode> findByUuid(String uuid) throws SystemException {
437         return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
438     }
439 
440     public List<WikiNode> findByUuid(String uuid, int start, int end)
441         throws SystemException {
442         return findByUuid(uuid, start, end, null);
443     }
444 
445     public List<WikiNode> findByUuid(String uuid, int start, int end,
446         OrderByComparator orderByComparator) throws SystemException {
447         Object[] finderArgs = new Object[] {
448                 uuid,
449                 
450                 String.valueOf(start), String.valueOf(end),
451                 String.valueOf(orderByComparator)
452             };
453 
454         List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
455                 finderArgs, this);
456 
457         if (list == null) {
458             StringBundler query = null;
459 
460             if (orderByComparator != null) {
461                 query = new StringBundler(3 +
462                         (orderByComparator.getOrderByFields().length * 3));
463             }
464             else {
465                 query = new StringBundler(3);
466             }
467 
468             query.append(_SQL_SELECT_WIKINODE_WHERE);
469 
470             if (uuid == null) {
471                 query.append(_FINDER_COLUMN_UUID_UUID_1);
472             }
473             else {
474                 if (uuid.equals(StringPool.BLANK)) {
475                     query.append(_FINDER_COLUMN_UUID_UUID_3);
476                 }
477                 else {
478                     query.append(_FINDER_COLUMN_UUID_UUID_2);
479                 }
480             }
481 
482             if (orderByComparator != null) {
483                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
484                     orderByComparator);
485             }
486 
487             else {
488                 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
489             }
490 
491             String sql = query.toString();
492 
493             Session session = null;
494 
495             try {
496                 session = openSession();
497 
498                 Query q = session.createQuery(sql);
499 
500                 QueryPos qPos = QueryPos.getInstance(q);
501 
502                 if (uuid != null) {
503                     qPos.add(uuid);
504                 }
505 
506                 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
507                         end);
508             }
509             catch (Exception e) {
510                 throw processException(e);
511             }
512             finally {
513                 if (list == null) {
514                     list = new ArrayList<WikiNode>();
515                 }
516 
517                 cacheResult(list);
518 
519                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
520                     list);
521 
522                 closeSession(session);
523             }
524         }
525 
526         return list;
527     }
528 
529     public WikiNode findByUuid_First(String uuid,
530         OrderByComparator orderByComparator)
531         throws NoSuchNodeException, SystemException {
532         List<WikiNode> list = findByUuid(uuid, 0, 1, orderByComparator);
533 
534         if (list.isEmpty()) {
535             StringBundler msg = new StringBundler(4);
536 
537             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
538 
539             msg.append("uuid=");
540             msg.append(uuid);
541 
542             msg.append(StringPool.CLOSE_CURLY_BRACE);
543 
544             throw new NoSuchNodeException(msg.toString());
545         }
546         else {
547             return list.get(0);
548         }
549     }
550 
551     public WikiNode findByUuid_Last(String uuid,
552         OrderByComparator orderByComparator)
553         throws NoSuchNodeException, SystemException {
554         int count = countByUuid(uuid);
555 
556         List<WikiNode> list = findByUuid(uuid, count - 1, count,
557                 orderByComparator);
558 
559         if (list.isEmpty()) {
560             StringBundler msg = new StringBundler(4);
561 
562             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
563 
564             msg.append("uuid=");
565             msg.append(uuid);
566 
567             msg.append(StringPool.CLOSE_CURLY_BRACE);
568 
569             throw new NoSuchNodeException(msg.toString());
570         }
571         else {
572             return list.get(0);
573         }
574     }
575 
576     public WikiNode[] findByUuid_PrevAndNext(long nodeId, String uuid,
577         OrderByComparator orderByComparator)
578         throws NoSuchNodeException, SystemException {
579         WikiNode wikiNode = findByPrimaryKey(nodeId);
580 
581         Session session = null;
582 
583         try {
584             session = openSession();
585 
586             WikiNode[] array = new WikiNodeImpl[3];
587 
588             array[0] = getByUuid_PrevAndNext(session, wikiNode, uuid,
589                     orderByComparator, true);
590 
591             array[1] = wikiNode;
592 
593             array[2] = getByUuid_PrevAndNext(session, wikiNode, uuid,
594                     orderByComparator, false);
595 
596             return array;
597         }
598         catch (Exception e) {
599             throw processException(e);
600         }
601         finally {
602             closeSession(session);
603         }
604     }
605 
606     protected WikiNode getByUuid_PrevAndNext(Session session,
607         WikiNode wikiNode, String uuid, OrderByComparator orderByComparator,
608         boolean previous) {
609         StringBundler query = null;
610 
611         if (orderByComparator != null) {
612             query = new StringBundler(6 +
613                     (orderByComparator.getOrderByFields().length * 6));
614         }
615         else {
616             query = new StringBundler(3);
617         }
618 
619         query.append(_SQL_SELECT_WIKINODE_WHERE);
620 
621         if (uuid == null) {
622             query.append(_FINDER_COLUMN_UUID_UUID_1);
623         }
624         else {
625             if (uuid.equals(StringPool.BLANK)) {
626                 query.append(_FINDER_COLUMN_UUID_UUID_3);
627             }
628             else {
629                 query.append(_FINDER_COLUMN_UUID_UUID_2);
630             }
631         }
632 
633         if (orderByComparator != null) {
634             String[] orderByFields = orderByComparator.getOrderByFields();
635 
636             if (orderByFields.length > 0) {
637                 query.append(WHERE_AND);
638             }
639 
640             for (int i = 0; i < orderByFields.length; i++) {
641                 query.append(_ORDER_BY_ENTITY_ALIAS);
642                 query.append(orderByFields[i]);
643 
644                 if ((i + 1) < orderByFields.length) {
645                     if (orderByComparator.isAscending() ^ previous) {
646                         query.append(WHERE_GREATER_THAN_HAS_NEXT);
647                     }
648                     else {
649                         query.append(WHERE_LESSER_THAN_HAS_NEXT);
650                     }
651                 }
652                 else {
653                     if (orderByComparator.isAscending() ^ previous) {
654                         query.append(WHERE_GREATER_THAN);
655                     }
656                     else {
657                         query.append(WHERE_LESSER_THAN);
658                     }
659                 }
660             }
661 
662             query.append(ORDER_BY_CLAUSE);
663 
664             for (int i = 0; i < orderByFields.length; i++) {
665                 query.append(_ORDER_BY_ENTITY_ALIAS);
666                 query.append(orderByFields[i]);
667 
668                 if ((i + 1) < orderByFields.length) {
669                     if (orderByComparator.isAscending() ^ previous) {
670                         query.append(ORDER_BY_ASC_HAS_NEXT);
671                     }
672                     else {
673                         query.append(ORDER_BY_DESC_HAS_NEXT);
674                     }
675                 }
676                 else {
677                     if (orderByComparator.isAscending() ^ previous) {
678                         query.append(ORDER_BY_ASC);
679                     }
680                     else {
681                         query.append(ORDER_BY_DESC);
682                     }
683                 }
684             }
685         }
686 
687         else {
688             query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
689         }
690 
691         String sql = query.toString();
692 
693         Query q = session.createQuery(sql);
694 
695         q.setFirstResult(0);
696         q.setMaxResults(2);
697 
698         QueryPos qPos = QueryPos.getInstance(q);
699 
700         if (uuid != null) {
701             qPos.add(uuid);
702         }
703 
704         if (orderByComparator != null) {
705             Object[] values = orderByComparator.getOrderByValues(wikiNode);
706 
707             for (Object value : values) {
708                 qPos.add(value);
709             }
710         }
711 
712         List<WikiNode> list = q.list();
713 
714         if (list.size() == 2) {
715             return list.get(1);
716         }
717         else {
718             return null;
719         }
720     }
721 
722     public WikiNode findByUUID_G(String uuid, long groupId)
723         throws NoSuchNodeException, SystemException {
724         WikiNode wikiNode = fetchByUUID_G(uuid, groupId);
725 
726         if (wikiNode == null) {
727             StringBundler msg = new StringBundler(6);
728 
729             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
730 
731             msg.append("uuid=");
732             msg.append(uuid);
733 
734             msg.append(", groupId=");
735             msg.append(groupId);
736 
737             msg.append(StringPool.CLOSE_CURLY_BRACE);
738 
739             if (_log.isWarnEnabled()) {
740                 _log.warn(msg.toString());
741             }
742 
743             throw new NoSuchNodeException(msg.toString());
744         }
745 
746         return wikiNode;
747     }
748 
749     public WikiNode fetchByUUID_G(String uuid, long groupId)
750         throws SystemException {
751         return fetchByUUID_G(uuid, groupId, true);
752     }
753 
754     public WikiNode fetchByUUID_G(String uuid, long groupId,
755         boolean retrieveFromCache) throws SystemException {
756         Object[] finderArgs = new Object[] { uuid, groupId };
757 
758         Object result = null;
759 
760         if (retrieveFromCache) {
761             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
762                     finderArgs, this);
763         }
764 
765         if (result == null) {
766             StringBundler query = new StringBundler(4);
767 
768             query.append(_SQL_SELECT_WIKINODE_WHERE);
769 
770             if (uuid == null) {
771                 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
772             }
773             else {
774                 if (uuid.equals(StringPool.BLANK)) {
775                     query.append(_FINDER_COLUMN_UUID_G_UUID_3);
776                 }
777                 else {
778                     query.append(_FINDER_COLUMN_UUID_G_UUID_2);
779                 }
780             }
781 
782             query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
783 
784             query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
785 
786             String sql = query.toString();
787 
788             Session session = null;
789 
790             try {
791                 session = openSession();
792 
793                 Query q = session.createQuery(sql);
794 
795                 QueryPos qPos = QueryPos.getInstance(q);
796 
797                 if (uuid != null) {
798                     qPos.add(uuid);
799                 }
800 
801                 qPos.add(groupId);
802 
803                 List<WikiNode> list = q.list();
804 
805                 result = list;
806 
807                 WikiNode wikiNode = null;
808 
809                 if (list.isEmpty()) {
810                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
811                         finderArgs, list);
812                 }
813                 else {
814                     wikiNode = list.get(0);
815 
816                     cacheResult(wikiNode);
817 
818                     if ((wikiNode.getUuid() == null) ||
819                             !wikiNode.getUuid().equals(uuid) ||
820                             (wikiNode.getGroupId() != groupId)) {
821                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
822                             finderArgs, wikiNode);
823                     }
824                 }
825 
826                 return wikiNode;
827             }
828             catch (Exception e) {
829                 throw processException(e);
830             }
831             finally {
832                 if (result == null) {
833                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
834                         finderArgs, new ArrayList<WikiNode>());
835                 }
836 
837                 closeSession(session);
838             }
839         }
840         else {
841             if (result instanceof List<?>) {
842                 return null;
843             }
844             else {
845                 return (WikiNode)result;
846             }
847         }
848     }
849 
850     public List<WikiNode> findByGroupId(long groupId) throws SystemException {
851         return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
852     }
853 
854     public List<WikiNode> findByGroupId(long groupId, int start, int end)
855         throws SystemException {
856         return findByGroupId(groupId, start, end, null);
857     }
858 
859     public List<WikiNode> findByGroupId(long groupId, int start, int end,
860         OrderByComparator orderByComparator) throws SystemException {
861         Object[] finderArgs = new Object[] {
862                 groupId,
863                 
864                 String.valueOf(start), String.valueOf(end),
865                 String.valueOf(orderByComparator)
866             };
867 
868         List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
869                 finderArgs, this);
870 
871         if (list == null) {
872             StringBundler query = null;
873 
874             if (orderByComparator != null) {
875                 query = new StringBundler(3 +
876                         (orderByComparator.getOrderByFields().length * 3));
877             }
878             else {
879                 query = new StringBundler(3);
880             }
881 
882             query.append(_SQL_SELECT_WIKINODE_WHERE);
883 
884             query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
885 
886             if (orderByComparator != null) {
887                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
888                     orderByComparator);
889             }
890 
891             else {
892                 query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
893             }
894 
895             String sql = query.toString();
896 
897             Session session = null;
898 
899             try {
900                 session = openSession();
901 
902                 Query q = session.createQuery(sql);
903 
904                 QueryPos qPos = QueryPos.getInstance(q);
905 
906                 qPos.add(groupId);
907 
908                 list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
909                         end);
910             }
911             catch (Exception e) {
912                 throw processException(e);
913             }
914             finally {
915                 if (list == null) {
916                     list = new ArrayList<WikiNode>();
917                 }
918 
919                 cacheResult(list);
920 
921                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
922                     finderArgs, list);
923 
924                 closeSession(session);
925             }
926         }
927 
928         return list;
929     }
930 
931     public WikiNode findByGroupId_First(long groupId,
932         OrderByComparator orderByComparator)
933         throws NoSuchNodeException, SystemException {
934         List<WikiNode> list = findByGroupId(groupId, 0, 1, orderByComparator);
935 
936         if (list.isEmpty()) {
937             StringBundler msg = new StringBundler(4);
938 
939             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
940 
941             msg.append("groupId=");
942             msg.append(groupId);
943 
944             msg.append(StringPool.CLOSE_CURLY_BRACE);
945 
946             throw new NoSuchNodeException(msg.toString());
947         }
948         else {
949             return list.get(0);
950         }
951     }
952 
953     public WikiNode findByGroupId_Last(long groupId,
954         OrderByComparator orderByComparator)
955         throws NoSuchNodeException, SystemException {
956         int count = countByGroupId(groupId);
957 
958         List<WikiNode> list = findByGroupId(groupId, count - 1, count,
959                 orderByComparator);
960 
961         if (list.isEmpty()) {
962             StringBundler msg = new StringBundler(4);
963 
964             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
965 
966             msg.append("groupId=");
967             msg.append(groupId);
968 
969             msg.append(StringPool.CLOSE_CURLY_BRACE);
970 
971             throw new NoSuchNodeException(msg.toString());
972         }
973         else {
974             return list.get(0);
975         }
976     }
977 
978     public WikiNode[] findByGroupId_PrevAndNext(long nodeId, long groupId,
979         OrderByComparator orderByComparator)
980         throws NoSuchNodeException, SystemException {
981         WikiNode wikiNode = findByPrimaryKey(nodeId);
982 
983         Session session = null;
984 
985         try {
986             session = openSession();
987 
988             WikiNode[] array = new WikiNodeImpl[3];
989 
990             array[0] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
991                     orderByComparator, true);
992 
993             array[1] = wikiNode;
994 
995             array[2] = getByGroupId_PrevAndNext(session, wikiNode, groupId,
996                     orderByComparator, false);
997 
998             return array;
999         }
1000        catch (Exception e) {
1001            throw processException(e);
1002        }
1003        finally {
1004            closeSession(session);
1005        }
1006    }
1007
1008    protected WikiNode getByGroupId_PrevAndNext(Session session,
1009        WikiNode wikiNode, long groupId, OrderByComparator orderByComparator,
1010        boolean previous) {
1011        StringBundler query = null;
1012
1013        if (orderByComparator != null) {
1014            query = new StringBundler(6 +
1015                    (orderByComparator.getOrderByFields().length * 6));
1016        }
1017        else {
1018            query = new StringBundler(3);
1019        }
1020
1021        query.append(_SQL_SELECT_WIKINODE_WHERE);
1022
1023        query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1024
1025        if (orderByComparator != null) {
1026            String[] orderByFields = orderByComparator.getOrderByFields();
1027
1028            if (orderByFields.length > 0) {
1029                query.append(WHERE_AND);
1030            }
1031
1032            for (int i = 0; i < orderByFields.length; i++) {
1033                query.append(_ORDER_BY_ENTITY_ALIAS);
1034                query.append(orderByFields[i]);
1035
1036                if ((i + 1) < orderByFields.length) {
1037                    if (orderByComparator.isAscending() ^ previous) {
1038                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
1039                    }
1040                    else {
1041                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
1042                    }
1043                }
1044                else {
1045                    if (orderByComparator.isAscending() ^ previous) {
1046                        query.append(WHERE_GREATER_THAN);
1047                    }
1048                    else {
1049                        query.append(WHERE_LESSER_THAN);
1050                    }
1051                }
1052            }
1053
1054            query.append(ORDER_BY_CLAUSE);
1055
1056            for (int i = 0; i < orderByFields.length; i++) {
1057                query.append(_ORDER_BY_ENTITY_ALIAS);
1058                query.append(orderByFields[i]);
1059
1060                if ((i + 1) < orderByFields.length) {
1061                    if (orderByComparator.isAscending() ^ previous) {
1062                        query.append(ORDER_BY_ASC_HAS_NEXT);
1063                    }
1064                    else {
1065                        query.append(ORDER_BY_DESC_HAS_NEXT);
1066                    }
1067                }
1068                else {
1069                    if (orderByComparator.isAscending() ^ previous) {
1070                        query.append(ORDER_BY_ASC);
1071                    }
1072                    else {
1073                        query.append(ORDER_BY_DESC);
1074                    }
1075                }
1076            }
1077        }
1078
1079        else {
1080            query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1081        }
1082
1083        String sql = query.toString();
1084
1085        Query q = session.createQuery(sql);
1086
1087        q.setFirstResult(0);
1088        q.setMaxResults(2);
1089
1090        QueryPos qPos = QueryPos.getInstance(q);
1091
1092        qPos.add(groupId);
1093
1094        if (orderByComparator != null) {
1095            Object[] values = orderByComparator.getOrderByValues(wikiNode);
1096
1097            for (Object value : values) {
1098                qPos.add(value);
1099            }
1100        }
1101
1102        List<WikiNode> list = q.list();
1103
1104        if (list.size() == 2) {
1105            return list.get(1);
1106        }
1107        else {
1108            return null;
1109        }
1110    }
1111
1112    public List<WikiNode> findByCompanyId(long companyId)
1113        throws SystemException {
1114        return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1115            null);
1116    }
1117
1118    public List<WikiNode> findByCompanyId(long companyId, int start, int end)
1119        throws SystemException {
1120        return findByCompanyId(companyId, start, end, null);
1121    }
1122
1123    public List<WikiNode> findByCompanyId(long companyId, int start, int end,
1124        OrderByComparator orderByComparator) throws SystemException {
1125        Object[] finderArgs = new Object[] {
1126                companyId,
1127                
1128                String.valueOf(start), String.valueOf(end),
1129                String.valueOf(orderByComparator)
1130            };
1131
1132        List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1133                finderArgs, this);
1134
1135        if (list == null) {
1136            StringBundler query = null;
1137
1138            if (orderByComparator != null) {
1139                query = new StringBundler(3 +
1140                        (orderByComparator.getOrderByFields().length * 3));
1141            }
1142            else {
1143                query = new StringBundler(3);
1144            }
1145
1146            query.append(_SQL_SELECT_WIKINODE_WHERE);
1147
1148            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1149
1150            if (orderByComparator != null) {
1151                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1152                    orderByComparator);
1153            }
1154
1155            else {
1156                query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1157            }
1158
1159            String sql = query.toString();
1160
1161            Session session = null;
1162
1163            try {
1164                session = openSession();
1165
1166                Query q = session.createQuery(sql);
1167
1168                QueryPos qPos = QueryPos.getInstance(q);
1169
1170                qPos.add(companyId);
1171
1172                list = (List<WikiNode>)QueryUtil.list(q, getDialect(), start,
1173                        end);
1174            }
1175            catch (Exception e) {
1176                throw processException(e);
1177            }
1178            finally {
1179                if (list == null) {
1180                    list = new ArrayList<WikiNode>();
1181                }
1182
1183                cacheResult(list);
1184
1185                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1186                    finderArgs, list);
1187
1188                closeSession(session);
1189            }
1190        }
1191
1192        return list;
1193    }
1194
1195    public WikiNode findByCompanyId_First(long companyId,
1196        OrderByComparator orderByComparator)
1197        throws NoSuchNodeException, SystemException {
1198        List<WikiNode> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1199
1200        if (list.isEmpty()) {
1201            StringBundler msg = new StringBundler(4);
1202
1203            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1204
1205            msg.append("companyId=");
1206            msg.append(companyId);
1207
1208            msg.append(StringPool.CLOSE_CURLY_BRACE);
1209
1210            throw new NoSuchNodeException(msg.toString());
1211        }
1212        else {
1213            return list.get(0);
1214        }
1215    }
1216
1217    public WikiNode findByCompanyId_Last(long companyId,
1218        OrderByComparator orderByComparator)
1219        throws NoSuchNodeException, SystemException {
1220        int count = countByCompanyId(companyId);
1221
1222        List<WikiNode> list = findByCompanyId(companyId, count - 1, count,
1223                orderByComparator);
1224
1225        if (list.isEmpty()) {
1226            StringBundler msg = new StringBundler(4);
1227
1228            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1229
1230            msg.append("companyId=");
1231            msg.append(companyId);
1232
1233            msg.append(StringPool.CLOSE_CURLY_BRACE);
1234
1235            throw new NoSuchNodeException(msg.toString());
1236        }
1237        else {
1238            return list.get(0);
1239        }
1240    }
1241
1242    public WikiNode[] findByCompanyId_PrevAndNext(long nodeId, long companyId,
1243        OrderByComparator orderByComparator)
1244        throws NoSuchNodeException, SystemException {
1245        WikiNode wikiNode = findByPrimaryKey(nodeId);
1246
1247        Session session = null;
1248
1249        try {
1250            session = openSession();
1251
1252            WikiNode[] array = new WikiNodeImpl[3];
1253
1254            array[0] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
1255                    orderByComparator, true);
1256
1257            array[1] = wikiNode;
1258
1259            array[2] = getByCompanyId_PrevAndNext(session, wikiNode, companyId,
1260                    orderByComparator, false);
1261
1262            return array;
1263        }
1264        catch (Exception e) {
1265            throw processException(e);
1266        }
1267        finally {
1268            closeSession(session);
1269        }
1270    }
1271
1272    protected WikiNode getByCompanyId_PrevAndNext(Session session,
1273        WikiNode wikiNode, long companyId, OrderByComparator orderByComparator,
1274        boolean previous) {
1275        StringBundler query = null;
1276
1277        if (orderByComparator != null) {
1278            query = new StringBundler(6 +
1279                    (orderByComparator.getOrderByFields().length * 6));
1280        }
1281        else {
1282            query = new StringBundler(3);
1283        }
1284
1285        query.append(_SQL_SELECT_WIKINODE_WHERE);
1286
1287        query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1288
1289        if (orderByComparator != null) {
1290            String[] orderByFields = orderByComparator.getOrderByFields();
1291
1292            if (orderByFields.length > 0) {
1293                query.append(WHERE_AND);
1294            }
1295
1296            for (int i = 0; i < orderByFields.length; i++) {
1297                query.append(_ORDER_BY_ENTITY_ALIAS);
1298                query.append(orderByFields[i]);
1299
1300                if ((i + 1) < orderByFields.length) {
1301                    if (orderByComparator.isAscending() ^ previous) {
1302                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
1303                    }
1304                    else {
1305                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
1306                    }
1307                }
1308                else {
1309                    if (orderByComparator.isAscending() ^ previous) {
1310                        query.append(WHERE_GREATER_THAN);
1311                    }
1312                    else {
1313                        query.append(WHERE_LESSER_THAN);
1314                    }
1315                }
1316            }
1317
1318            query.append(ORDER_BY_CLAUSE);
1319
1320            for (int i = 0; i < orderByFields.length; i++) {
1321                query.append(_ORDER_BY_ENTITY_ALIAS);
1322                query.append(orderByFields[i]);
1323
1324                if ((i + 1) < orderByFields.length) {
1325                    if (orderByComparator.isAscending() ^ previous) {
1326                        query.append(ORDER_BY_ASC_HAS_NEXT);
1327                    }
1328                    else {
1329                        query.append(ORDER_BY_DESC_HAS_NEXT);
1330                    }
1331                }
1332                else {
1333                    if (orderByComparator.isAscending() ^ previous) {
1334                        query.append(ORDER_BY_ASC);
1335                    }
1336                    else {
1337                        query.append(ORDER_BY_DESC);
1338                    }
1339                }
1340            }
1341        }
1342
1343        else {
1344            query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1345        }
1346
1347        String sql = query.toString();
1348
1349        Query q = session.createQuery(sql);
1350
1351        q.setFirstResult(0);
1352        q.setMaxResults(2);
1353
1354        QueryPos qPos = QueryPos.getInstance(q);
1355
1356        qPos.add(companyId);
1357
1358        if (orderByComparator != null) {
1359            Object[] values = orderByComparator.getOrderByValues(wikiNode);
1360
1361            for (Object value : values) {
1362                qPos.add(value);
1363            }
1364        }
1365
1366        List<WikiNode> list = q.list();
1367
1368        if (list.size() == 2) {
1369            return list.get(1);
1370        }
1371        else {
1372            return null;
1373        }
1374    }
1375
1376    public WikiNode findByG_N(long groupId, String name)
1377        throws NoSuchNodeException, SystemException {
1378        WikiNode wikiNode = fetchByG_N(groupId, name);
1379
1380        if (wikiNode == null) {
1381            StringBundler msg = new StringBundler(6);
1382
1383            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1384
1385            msg.append("groupId=");
1386            msg.append(groupId);
1387
1388            msg.append(", name=");
1389            msg.append(name);
1390
1391            msg.append(StringPool.CLOSE_CURLY_BRACE);
1392
1393            if (_log.isWarnEnabled()) {
1394                _log.warn(msg.toString());
1395            }
1396
1397            throw new NoSuchNodeException(msg.toString());
1398        }
1399
1400        return wikiNode;
1401    }
1402
1403    public WikiNode fetchByG_N(long groupId, String name)
1404        throws SystemException {
1405        return fetchByG_N(groupId, name, true);
1406    }
1407
1408    public WikiNode fetchByG_N(long groupId, String name,
1409        boolean retrieveFromCache) throws SystemException {
1410        Object[] finderArgs = new Object[] { groupId, name };
1411
1412        Object result = null;
1413
1414        if (retrieveFromCache) {
1415            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
1416                    finderArgs, this);
1417        }
1418
1419        if (result == null) {
1420            StringBundler query = new StringBundler(4);
1421
1422            query.append(_SQL_SELECT_WIKINODE_WHERE);
1423
1424            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1425
1426            if (name == null) {
1427                query.append(_FINDER_COLUMN_G_N_NAME_1);
1428            }
1429            else {
1430                if (name.equals(StringPool.BLANK)) {
1431                    query.append(_FINDER_COLUMN_G_N_NAME_3);
1432                }
1433                else {
1434                    query.append(_FINDER_COLUMN_G_N_NAME_2);
1435                }
1436            }
1437
1438            query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
1439
1440            String sql = query.toString();
1441
1442            Session session = null;
1443
1444            try {
1445                session = openSession();
1446
1447                Query q = session.createQuery(sql);
1448
1449                QueryPos qPos = QueryPos.getInstance(q);
1450
1451                qPos.add(groupId);
1452
1453                if (name != null) {
1454                    qPos.add(name);
1455                }
1456
1457                List<WikiNode> list = q.list();
1458
1459                result = list;
1460
1461                WikiNode wikiNode = null;
1462
1463                if (list.isEmpty()) {
1464                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1465                        finderArgs, list);
1466                }
1467                else {
1468                    wikiNode = list.get(0);
1469
1470                    cacheResult(wikiNode);
1471
1472                    if ((wikiNode.getGroupId() != groupId) ||
1473                            (wikiNode.getName() == null) ||
1474                            !wikiNode.getName().equals(name)) {
1475                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1476                            finderArgs, wikiNode);
1477                    }
1478                }
1479
1480                return wikiNode;
1481            }
1482            catch (Exception e) {
1483                throw processException(e);
1484            }
1485            finally {
1486                if (result == null) {
1487                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1488                        finderArgs, new ArrayList<WikiNode>());
1489                }
1490
1491                closeSession(session);
1492            }
1493        }
1494        else {
1495            if (result instanceof List<?>) {
1496                return null;
1497            }
1498            else {
1499                return (WikiNode)result;
1500            }
1501        }
1502    }
1503
1504    public List<WikiNode> findAll() throws SystemException {
1505        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1506    }
1507
1508    public List<WikiNode> findAll(int start, int end) throws SystemException {
1509        return findAll(start, end, null);
1510    }
1511
1512    public List<WikiNode> findAll(int start, int end,
1513        OrderByComparator orderByComparator) throws SystemException {
1514        Object[] finderArgs = new Object[] {
1515                String.valueOf(start), String.valueOf(end),
1516                String.valueOf(orderByComparator)
1517            };
1518
1519        List<WikiNode> list = (List<WikiNode>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1520                finderArgs, this);
1521
1522        if (list == null) {
1523            StringBundler query = null;
1524            String sql = null;
1525
1526            if (orderByComparator != null) {
1527                query = new StringBundler(2 +
1528                        (orderByComparator.getOrderByFields().length * 3));
1529
1530                query.append(_SQL_SELECT_WIKINODE);
1531
1532                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1533                    orderByComparator);
1534
1535                sql = query.toString();
1536            }
1537            else {
1538                sql = _SQL_SELECT_WIKINODE.concat(WikiNodeModelImpl.ORDER_BY_JPQL);
1539            }
1540
1541            Session session = null;
1542
1543            try {
1544                session = openSession();
1545
1546                Query q = session.createQuery(sql);
1547
1548                if (orderByComparator == null) {
1549                    list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
1550                            start, end, false);
1551
1552                    Collections.sort(list);
1553                }
1554                else {
1555                    list = (List<WikiNode>)QueryUtil.list(q, getDialect(),
1556                            start, end);
1557                }
1558            }
1559            catch (Exception e) {
1560                throw processException(e);
1561            }
1562            finally {
1563                if (list == null) {
1564                    list = new ArrayList<WikiNode>();
1565                }
1566
1567                cacheResult(list);
1568
1569                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1570
1571                closeSession(session);
1572            }
1573        }
1574
1575        return list;
1576    }
1577
1578    public void removeByUuid(String uuid) throws SystemException {
1579        for (WikiNode wikiNode : findByUuid(uuid)) {
1580            remove(wikiNode);
1581        }
1582    }
1583
1584    public void removeByUUID_G(String uuid, long groupId)
1585        throws NoSuchNodeException, SystemException {
1586        WikiNode wikiNode = findByUUID_G(uuid, groupId);
1587
1588        remove(wikiNode);
1589    }
1590
1591    public void removeByGroupId(long groupId) throws SystemException {
1592        for (WikiNode wikiNode : findByGroupId(groupId)) {
1593            remove(wikiNode);
1594        }
1595    }
1596
1597    public void removeByCompanyId(long companyId) throws SystemException {
1598        for (WikiNode wikiNode : findByCompanyId(companyId)) {
1599            remove(wikiNode);
1600        }
1601    }
1602
1603    public void removeByG_N(long groupId, String name)
1604        throws NoSuchNodeException, SystemException {
1605        WikiNode wikiNode = findByG_N(groupId, name);
1606
1607        remove(wikiNode);
1608    }
1609
1610    public void removeAll() throws SystemException {
1611        for (WikiNode wikiNode : findAll()) {
1612            remove(wikiNode);
1613        }
1614    }
1615
1616    public int countByUuid(String uuid) throws SystemException {
1617        Object[] finderArgs = new Object[] { uuid };
1618
1619        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1620                finderArgs, this);
1621
1622        if (count == null) {
1623            StringBundler query = new StringBundler(2);
1624
1625            query.append(_SQL_COUNT_WIKINODE_WHERE);
1626
1627            if (uuid == null) {
1628                query.append(_FINDER_COLUMN_UUID_UUID_1);
1629            }
1630            else {
1631                if (uuid.equals(StringPool.BLANK)) {
1632                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1633                }
1634                else {
1635                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1636                }
1637            }
1638
1639            String sql = query.toString();
1640
1641            Session session = null;
1642
1643            try {
1644                session = openSession();
1645
1646                Query q = session.createQuery(sql);
1647
1648                QueryPos qPos = QueryPos.getInstance(q);
1649
1650                if (uuid != null) {
1651                    qPos.add(uuid);
1652                }
1653
1654                count = (Long)q.uniqueResult();
1655            }
1656            catch (Exception e) {
1657                throw processException(e);
1658            }
1659            finally {
1660                if (count == null) {
1661                    count = Long.valueOf(0);
1662                }
1663
1664                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1665                    finderArgs, count);
1666
1667                closeSession(session);
1668            }
1669        }
1670
1671        return count.intValue();
1672    }
1673
1674    public int countByUUID_G(String uuid, long groupId)
1675        throws SystemException {
1676        Object[] finderArgs = new Object[] { uuid, groupId };
1677
1678        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1679                finderArgs, this);
1680
1681        if (count == null) {
1682            StringBundler query = new StringBundler(3);
1683
1684            query.append(_SQL_COUNT_WIKINODE_WHERE);
1685
1686            if (uuid == null) {
1687                query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1688            }
1689            else {
1690                if (uuid.equals(StringPool.BLANK)) {
1691                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1692                }
1693                else {
1694                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1695                }
1696            }
1697
1698            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1699
1700            String sql = query.toString();
1701
1702            Session session = null;
1703
1704            try {
1705                session = openSession();
1706
1707                Query q = session.createQuery(sql);
1708
1709                QueryPos qPos = QueryPos.getInstance(q);
1710
1711                if (uuid != null) {
1712                    qPos.add(uuid);
1713                }
1714
1715                qPos.add(groupId);
1716
1717                count = (Long)q.uniqueResult();
1718            }
1719            catch (Exception e) {
1720                throw processException(e);
1721            }
1722            finally {
1723                if (count == null) {
1724                    count = Long.valueOf(0);
1725                }
1726
1727                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1728                    finderArgs, count);
1729
1730                closeSession(session);
1731            }
1732        }
1733
1734        return count.intValue();
1735    }
1736
1737    public int countByGroupId(long groupId) throws SystemException {
1738        Object[] finderArgs = new Object[] { groupId };
1739
1740        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1741                finderArgs, this);
1742
1743        if (count == null) {
1744            StringBundler query = new StringBundler(2);
1745
1746            query.append(_SQL_COUNT_WIKINODE_WHERE);
1747
1748            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1749
1750            String sql = query.toString();
1751
1752            Session session = null;
1753
1754            try {
1755                session = openSession();
1756
1757                Query q = session.createQuery(sql);
1758
1759                QueryPos qPos = QueryPos.getInstance(q);
1760
1761                qPos.add(groupId);
1762
1763                count = (Long)q.uniqueResult();
1764            }
1765            catch (Exception e) {
1766                throw processException(e);
1767            }
1768            finally {
1769                if (count == null) {
1770                    count = Long.valueOf(0);
1771                }
1772
1773                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1774                    finderArgs, count);
1775
1776                closeSession(session);
1777            }
1778        }
1779
1780        return count.intValue();
1781    }
1782
1783    public int countByCompanyId(long companyId) throws SystemException {
1784        Object[] finderArgs = new Object[] { companyId };
1785
1786        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1787                finderArgs, this);
1788
1789        if (count == null) {
1790            StringBundler query = new StringBundler(2);
1791
1792            query.append(_SQL_COUNT_WIKINODE_WHERE);
1793
1794            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1795
1796            String sql = query.toString();
1797
1798            Session session = null;
1799
1800            try {
1801                session = openSession();
1802
1803                Query q = session.createQuery(sql);
1804
1805                QueryPos qPos = QueryPos.getInstance(q);
1806
1807                qPos.add(companyId);
1808
1809                count = (Long)q.uniqueResult();
1810            }
1811            catch (Exception e) {
1812                throw processException(e);
1813            }
1814            finally {
1815                if (count == null) {
1816                    count = Long.valueOf(0);
1817                }
1818
1819                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1820                    finderArgs, count);
1821
1822                closeSession(session);
1823            }
1824        }
1825
1826        return count.intValue();
1827    }
1828
1829    public int countByG_N(long groupId, String name) throws SystemException {
1830        Object[] finderArgs = new Object[] { groupId, name };
1831
1832        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
1833                finderArgs, this);
1834
1835        if (count == null) {
1836            StringBundler query = new StringBundler(3);
1837
1838            query.append(_SQL_COUNT_WIKINODE_WHERE);
1839
1840            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1841
1842            if (name == null) {
1843                query.append(_FINDER_COLUMN_G_N_NAME_1);
1844            }
1845            else {
1846                if (name.equals(StringPool.BLANK)) {
1847                    query.append(_FINDER_COLUMN_G_N_NAME_3);
1848                }
1849                else {
1850                    query.append(_FINDER_COLUMN_G_N_NAME_2);
1851                }
1852            }
1853
1854            String sql = query.toString();
1855
1856            Session session = null;
1857
1858            try {
1859                session = openSession();
1860
1861                Query q = session.createQuery(sql);
1862
1863                QueryPos qPos = QueryPos.getInstance(q);
1864
1865                qPos.add(groupId);
1866
1867                if (name != null) {
1868                    qPos.add(name);
1869                }
1870
1871                count = (Long)q.uniqueResult();
1872            }
1873            catch (Exception e) {
1874                throw processException(e);
1875            }
1876            finally {
1877                if (count == null) {
1878                    count = Long.valueOf(0);
1879                }
1880
1881                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
1882                    count);
1883
1884                closeSession(session);
1885            }
1886        }
1887
1888        return count.intValue();
1889    }
1890
1891    public int countAll() throws SystemException {
1892        Object[] finderArgs = new Object[0];
1893
1894        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1895                finderArgs, this);
1896
1897        if (count == null) {
1898            Session session = null;
1899
1900            try {
1901                session = openSession();
1902
1903                Query q = session.createQuery(_SQL_COUNT_WIKINODE);
1904
1905                count = (Long)q.uniqueResult();
1906            }
1907            catch (Exception e) {
1908                throw processException(e);
1909            }
1910            finally {
1911                if (count == null) {
1912                    count = Long.valueOf(0);
1913                }
1914
1915                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1916                    count);
1917
1918                closeSession(session);
1919            }
1920        }
1921
1922        return count.intValue();
1923    }
1924
1925    public void afterPropertiesSet() {
1926        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1927                    com.liferay.portal.util.PropsUtil.get(
1928                        "value.object.listener.com.liferay.portlet.wiki.model.WikiNode")));
1929
1930        if (listenerClassNames.length > 0) {
1931            try {
1932                List<ModelListener<WikiNode>> listenersList = new ArrayList<ModelListener<WikiNode>>();
1933
1934                for (String listenerClassName : listenerClassNames) {
1935                    listenersList.add((ModelListener<WikiNode>)InstanceFactory.newInstance(
1936                            listenerClassName));
1937                }
1938
1939                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1940            }
1941            catch (Exception e) {
1942                _log.error(e);
1943            }
1944        }
1945    }
1946
1947    public void destroy() {
1948        EntityCacheUtil.removeCache(WikiNodeImpl.class.getName());
1949        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1950        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1951    }
1952
1953    @BeanReference(type = WikiNodePersistence.class)
1954    protected WikiNodePersistence wikiNodePersistence;
1955    @BeanReference(type = WikiPagePersistence.class)
1956    protected WikiPagePersistence wikiPagePersistence;
1957    @BeanReference(type = WikiPageResourcePersistence.class)
1958    protected WikiPageResourcePersistence wikiPageResourcePersistence;
1959    @BeanReference(type = GroupPersistence.class)
1960    protected GroupPersistence groupPersistence;
1961    @BeanReference(type = ResourcePersistence.class)
1962    protected ResourcePersistence resourcePersistence;
1963    @BeanReference(type = SubscriptionPersistence.class)
1964    protected SubscriptionPersistence subscriptionPersistence;
1965    @BeanReference(type = UserPersistence.class)
1966    protected UserPersistence userPersistence;
1967    private static final String _SQL_SELECT_WIKINODE = "SELECT wikiNode FROM WikiNode wikiNode";
1968    private static final String _SQL_SELECT_WIKINODE_WHERE = "SELECT wikiNode FROM WikiNode wikiNode WHERE ";
1969    private static final String _SQL_COUNT_WIKINODE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode";
1970    private static final String _SQL_COUNT_WIKINODE_WHERE = "SELECT COUNT(wikiNode) FROM WikiNode wikiNode WHERE ";
1971    private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiNode.uuid IS NULL";
1972    private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiNode.uuid = ?";
1973    private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiNode.uuid IS NULL OR wikiNode.uuid = ?)";
1974    private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "wikiNode.uuid IS NULL AND ";
1975    private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "wikiNode.uuid = ? AND ";
1976    private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(wikiNode.uuid IS NULL OR wikiNode.uuid = ?) AND ";
1977    private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "wikiNode.groupId = ?";
1978    private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "wikiNode.groupId = ?";
1979    private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "wikiNode.companyId = ?";
1980    private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "wikiNode.groupId = ? AND ";
1981    private static final String _FINDER_COLUMN_G_N_NAME_1 = "wikiNode.name IS NULL";
1982    private static final String _FINDER_COLUMN_G_N_NAME_2 = "wikiNode.name = ?";
1983    private static final String _FINDER_COLUMN_G_N_NAME_3 = "(wikiNode.name IS NULL OR wikiNode.name = ?)";
1984    private static final String _ORDER_BY_ENTITY_ALIAS = "wikiNode.";
1985    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiNode exists with the primary key ";
1986    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiNode exists with the key {";
1987    private static Log _log = LogFactoryUtil.getLog(WikiNodePersistenceImpl.class);
1988}