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