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