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