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