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