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