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