1
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.OrderByComparator;
29 import com.liferay.portal.kernel.util.StringMaker;
30 import com.liferay.portal.kernel.util.StringPool;
31 import com.liferay.portal.service.persistence.BasePersistence;
32 import com.liferay.portal.spring.hibernate.FinderCache;
33 import com.liferay.portal.spring.hibernate.HibernateUtil;
34
35 import com.liferay.portlet.wiki.NoSuchNodeException;
36 import com.liferay.portlet.wiki.model.WikiNode;
37 import com.liferay.portlet.wiki.model.impl.WikiNodeImpl;
38
39 import com.liferay.util.dao.hibernate.QueryUtil;
40
41 import org.apache.commons.logging.Log;
42 import org.apache.commons.logging.LogFactory;
43
44 import org.hibernate.Query;
45 import org.hibernate.Session;
46
47 import java.util.Collections;
48 import java.util.Iterator;
49 import java.util.List;
50
51
57 public class WikiNodePersistenceImpl extends BasePersistence
58 implements WikiNodePersistence {
59 public WikiNode create(long nodeId) {
60 WikiNode wikiNode = new WikiNodeImpl();
61 wikiNode.setNew(true);
62 wikiNode.setPrimaryKey(nodeId);
63
64 return wikiNode;
65 }
66
67 public WikiNode remove(long nodeId)
68 throws NoSuchNodeException, SystemException {
69 Session session = null;
70
71 try {
72 session = openSession();
73
74 WikiNode wikiNode = (WikiNode)session.get(WikiNodeImpl.class,
75 new Long(nodeId));
76
77 if (wikiNode == null) {
78 if (_log.isWarnEnabled()) {
79 _log.warn("No WikiNode exists with the primary key " +
80 nodeId);
81 }
82
83 throw new NoSuchNodeException(
84 "No WikiNode exists with the primary key " + nodeId);
85 }
86
87 return remove(wikiNode);
88 }
89 catch (NoSuchNodeException nsee) {
90 throw nsee;
91 }
92 catch (Exception e) {
93 throw HibernateUtil.processException(e);
94 }
95 finally {
96 closeSession(session);
97 }
98 }
99
100 public WikiNode remove(WikiNode wikiNode) throws SystemException {
101 Session session = null;
102
103 try {
104 session = openSession();
105 session.delete(wikiNode);
106 session.flush();
107
108 return wikiNode;
109 }
110 catch (Exception e) {
111 throw HibernateUtil.processException(e);
112 }
113 finally {
114 closeSession(session);
115 FinderCache.clearCache(WikiNode.class.getName());
116 }
117 }
118
119 public WikiNode update(com.liferay.portlet.wiki.model.WikiNode wikiNode)
120 throws SystemException {
121 return update(wikiNode, false);
122 }
123
124 public WikiNode update(com.liferay.portlet.wiki.model.WikiNode wikiNode,
125 boolean merge) throws SystemException {
126 Session session = null;
127
128 try {
129 session = openSession();
130
131 if (merge) {
132 session.merge(wikiNode);
133 }
134 else {
135 if (wikiNode.isNew()) {
136 session.save(wikiNode);
137 }
138 }
139
140 session.flush();
141 wikiNode.setNew(false);
142
143 return wikiNode;
144 }
145 catch (Exception e) {
146 throw HibernateUtil.processException(e);
147 }
148 finally {
149 closeSession(session);
150 FinderCache.clearCache(WikiNode.class.getName());
151 }
152 }
153
154 public WikiNode findByPrimaryKey(long nodeId)
155 throws NoSuchNodeException, SystemException {
156 WikiNode wikiNode = fetchByPrimaryKey(nodeId);
157
158 if (wikiNode == null) {
159 if (_log.isWarnEnabled()) {
160 _log.warn("No WikiNode exists with the primary key " + nodeId);
161 }
162
163 throw new NoSuchNodeException(
164 "No WikiNode exists with the primary key " + nodeId);
165 }
166
167 return wikiNode;
168 }
169
170 public WikiNode fetchByPrimaryKey(long nodeId) throws SystemException {
171 Session session = null;
172
173 try {
174 session = openSession();
175
176 return (WikiNode)session.get(WikiNodeImpl.class, new Long(nodeId));
177 }
178 catch (Exception e) {
179 throw HibernateUtil.processException(e);
180 }
181 finally {
182 closeSession(session);
183 }
184 }
185
186 public List findByGroupId(long groupId) throws SystemException {
187 String finderClassName = WikiNode.class.getName();
188 String finderMethodName = "findByGroupId";
189 String[] finderParams = new String[] { Long.class.getName() };
190 Object[] finderArgs = new Object[] { new Long(groupId) };
191 Object result = FinderCache.getResult(finderClassName,
192 finderMethodName, finderParams, finderArgs, getSessionFactory());
193
194 if (result == null) {
195 Session session = null;
196
197 try {
198 session = openSession();
199
200 StringMaker query = new StringMaker();
201 query.append(
202 "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
203 query.append("groupId = ?");
204 query.append(" ");
205 query.append("ORDER BY ");
206 query.append("name ASC");
207
208 Query q = session.createQuery(query.toString());
209 int queryPos = 0;
210 q.setLong(queryPos++, groupId);
211
212 List list = q.list();
213 FinderCache.putResult(finderClassName, finderMethodName,
214 finderParams, finderArgs, list);
215
216 return list;
217 }
218 catch (Exception e) {
219 throw HibernateUtil.processException(e);
220 }
221 finally {
222 closeSession(session);
223 }
224 }
225 else {
226 return (List)result;
227 }
228 }
229
230 public List findByGroupId(long groupId, int begin, int end)
231 throws SystemException {
232 return findByGroupId(groupId, begin, end, null);
233 }
234
235 public List findByGroupId(long groupId, int begin, int end,
236 OrderByComparator obc) throws SystemException {
237 String finderClassName = WikiNode.class.getName();
238 String finderMethodName = "findByGroupId";
239 String[] finderParams = new String[] {
240 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
241 "com.liferay.portal.kernel.util.OrderByComparator"
242 };
243 Object[] finderArgs = new Object[] {
244 new Long(groupId), String.valueOf(begin), String.valueOf(end),
245 String.valueOf(obc)
246 };
247 Object result = FinderCache.getResult(finderClassName,
248 finderMethodName, finderParams, finderArgs, getSessionFactory());
249
250 if (result == null) {
251 Session session = null;
252
253 try {
254 session = openSession();
255
256 StringMaker query = new StringMaker();
257 query.append(
258 "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
259 query.append("groupId = ?");
260 query.append(" ");
261
262 if (obc != null) {
263 query.append("ORDER BY ");
264 query.append(obc.getOrderBy());
265 }
266 else {
267 query.append("ORDER BY ");
268 query.append("name ASC");
269 }
270
271 Query q = session.createQuery(query.toString());
272 int queryPos = 0;
273 q.setLong(queryPos++, groupId);
274
275 List list = QueryUtil.list(q, getDialect(), begin, end);
276 FinderCache.putResult(finderClassName, finderMethodName,
277 finderParams, finderArgs, list);
278
279 return list;
280 }
281 catch (Exception e) {
282 throw HibernateUtil.processException(e);
283 }
284 finally {
285 closeSession(session);
286 }
287 }
288 else {
289 return (List)result;
290 }
291 }
292
293 public WikiNode findByGroupId_First(long groupId, OrderByComparator obc)
294 throws NoSuchNodeException, SystemException {
295 List list = findByGroupId(groupId, 0, 1, obc);
296
297 if (list.size() == 0) {
298 StringMaker msg = new StringMaker();
299 msg.append("No WikiNode exists with the key ");
300 msg.append(StringPool.OPEN_CURLY_BRACE);
301 msg.append("groupId=");
302 msg.append(groupId);
303 msg.append(StringPool.CLOSE_CURLY_BRACE);
304 throw new NoSuchNodeException(msg.toString());
305 }
306 else {
307 return (WikiNode)list.get(0);
308 }
309 }
310
311 public WikiNode findByGroupId_Last(long groupId, OrderByComparator obc)
312 throws NoSuchNodeException, SystemException {
313 int count = countByGroupId(groupId);
314 List list = findByGroupId(groupId, count - 1, count, obc);
315
316 if (list.size() == 0) {
317 StringMaker msg = new StringMaker();
318 msg.append("No WikiNode exists with the key ");
319 msg.append(StringPool.OPEN_CURLY_BRACE);
320 msg.append("groupId=");
321 msg.append(groupId);
322 msg.append(StringPool.CLOSE_CURLY_BRACE);
323 throw new NoSuchNodeException(msg.toString());
324 }
325 else {
326 return (WikiNode)list.get(0);
327 }
328 }
329
330 public WikiNode[] findByGroupId_PrevAndNext(long nodeId, long groupId,
331 OrderByComparator obc) throws NoSuchNodeException, SystemException {
332 WikiNode wikiNode = findByPrimaryKey(nodeId);
333 int count = countByGroupId(groupId);
334 Session session = null;
335
336 try {
337 session = openSession();
338
339 StringMaker query = new StringMaker();
340 query.append("FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
341 query.append("groupId = ?");
342 query.append(" ");
343
344 if (obc != null) {
345 query.append("ORDER BY ");
346 query.append(obc.getOrderBy());
347 }
348 else {
349 query.append("ORDER BY ");
350 query.append("name ASC");
351 }
352
353 Query q = session.createQuery(query.toString());
354 int queryPos = 0;
355 q.setLong(queryPos++, groupId);
356
357 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, wikiNode);
358 WikiNode[] array = new WikiNodeImpl[3];
359 array[0] = (WikiNode)objArray[0];
360 array[1] = (WikiNode)objArray[1];
361 array[2] = (WikiNode)objArray[2];
362
363 return array;
364 }
365 catch (Exception e) {
366 throw HibernateUtil.processException(e);
367 }
368 finally {
369 closeSession(session);
370 }
371 }
372
373 public List findByCompanyId(long companyId) throws SystemException {
374 String finderClassName = WikiNode.class.getName();
375 String finderMethodName = "findByCompanyId";
376 String[] finderParams = new String[] { Long.class.getName() };
377 Object[] finderArgs = new Object[] { new Long(companyId) };
378 Object result = FinderCache.getResult(finderClassName,
379 finderMethodName, finderParams, finderArgs, getSessionFactory());
380
381 if (result == null) {
382 Session session = null;
383
384 try {
385 session = openSession();
386
387 StringMaker query = new StringMaker();
388 query.append(
389 "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
390 query.append("companyId = ?");
391 query.append(" ");
392 query.append("ORDER BY ");
393 query.append("name ASC");
394
395 Query q = session.createQuery(query.toString());
396 int queryPos = 0;
397 q.setLong(queryPos++, companyId);
398
399 List list = q.list();
400 FinderCache.putResult(finderClassName, finderMethodName,
401 finderParams, finderArgs, list);
402
403 return list;
404 }
405 catch (Exception e) {
406 throw HibernateUtil.processException(e);
407 }
408 finally {
409 closeSession(session);
410 }
411 }
412 else {
413 return (List)result;
414 }
415 }
416
417 public List findByCompanyId(long companyId, int begin, int end)
418 throws SystemException {
419 return findByCompanyId(companyId, begin, end, null);
420 }
421
422 public List findByCompanyId(long companyId, int begin, int end,
423 OrderByComparator obc) throws SystemException {
424 String finderClassName = WikiNode.class.getName();
425 String finderMethodName = "findByCompanyId";
426 String[] finderParams = new String[] {
427 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
428 "com.liferay.portal.kernel.util.OrderByComparator"
429 };
430 Object[] finderArgs = new Object[] {
431 new Long(companyId), String.valueOf(begin), String.valueOf(end),
432 String.valueOf(obc)
433 };
434 Object result = FinderCache.getResult(finderClassName,
435 finderMethodName, finderParams, finderArgs, getSessionFactory());
436
437 if (result == null) {
438 Session session = null;
439
440 try {
441 session = openSession();
442
443 StringMaker query = new StringMaker();
444 query.append(
445 "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
446 query.append("companyId = ?");
447 query.append(" ");
448
449 if (obc != null) {
450 query.append("ORDER BY ");
451 query.append(obc.getOrderBy());
452 }
453 else {
454 query.append("ORDER BY ");
455 query.append("name ASC");
456 }
457
458 Query q = session.createQuery(query.toString());
459 int queryPos = 0;
460 q.setLong(queryPos++, companyId);
461
462 List list = QueryUtil.list(q, getDialect(), begin, end);
463 FinderCache.putResult(finderClassName, finderMethodName,
464 finderParams, finderArgs, list);
465
466 return list;
467 }
468 catch (Exception e) {
469 throw HibernateUtil.processException(e);
470 }
471 finally {
472 closeSession(session);
473 }
474 }
475 else {
476 return (List)result;
477 }
478 }
479
480 public WikiNode findByCompanyId_First(long companyId, OrderByComparator obc)
481 throws NoSuchNodeException, SystemException {
482 List list = findByCompanyId(companyId, 0, 1, obc);
483
484 if (list.size() == 0) {
485 StringMaker msg = new StringMaker();
486 msg.append("No WikiNode exists with the key ");
487 msg.append(StringPool.OPEN_CURLY_BRACE);
488 msg.append("companyId=");
489 msg.append(companyId);
490 msg.append(StringPool.CLOSE_CURLY_BRACE);
491 throw new NoSuchNodeException(msg.toString());
492 }
493 else {
494 return (WikiNode)list.get(0);
495 }
496 }
497
498 public WikiNode findByCompanyId_Last(long companyId, OrderByComparator obc)
499 throws NoSuchNodeException, SystemException {
500 int count = countByCompanyId(companyId);
501 List list = findByCompanyId(companyId, count - 1, count, obc);
502
503 if (list.size() == 0) {
504 StringMaker msg = new StringMaker();
505 msg.append("No WikiNode exists with the key ");
506 msg.append(StringPool.OPEN_CURLY_BRACE);
507 msg.append("companyId=");
508 msg.append(companyId);
509 msg.append(StringPool.CLOSE_CURLY_BRACE);
510 throw new NoSuchNodeException(msg.toString());
511 }
512 else {
513 return (WikiNode)list.get(0);
514 }
515 }
516
517 public WikiNode[] findByCompanyId_PrevAndNext(long nodeId, long companyId,
518 OrderByComparator obc) throws NoSuchNodeException, SystemException {
519 WikiNode wikiNode = findByPrimaryKey(nodeId);
520 int count = countByCompanyId(companyId);
521 Session session = null;
522
523 try {
524 session = openSession();
525
526 StringMaker query = new StringMaker();
527 query.append("FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
528 query.append("companyId = ?");
529 query.append(" ");
530
531 if (obc != null) {
532 query.append("ORDER BY ");
533 query.append(obc.getOrderBy());
534 }
535 else {
536 query.append("ORDER BY ");
537 query.append("name ASC");
538 }
539
540 Query q = session.createQuery(query.toString());
541 int queryPos = 0;
542 q.setLong(queryPos++, companyId);
543
544 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, wikiNode);
545 WikiNode[] array = new WikiNodeImpl[3];
546 array[0] = (WikiNode)objArray[0];
547 array[1] = (WikiNode)objArray[1];
548 array[2] = (WikiNode)objArray[2];
549
550 return array;
551 }
552 catch (Exception e) {
553 throw HibernateUtil.processException(e);
554 }
555 finally {
556 closeSession(session);
557 }
558 }
559
560 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
561 throws SystemException {
562 Session session = null;
563
564 try {
565 session = openSession();
566
567 DynamicQuery query = queryInitializer.initialize(session);
568
569 return query.list();
570 }
571 catch (Exception e) {
572 throw HibernateUtil.processException(e);
573 }
574 finally {
575 closeSession(session);
576 }
577 }
578
579 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
580 int begin, int end) throws SystemException {
581 Session session = null;
582
583 try {
584 session = openSession();
585
586 DynamicQuery query = queryInitializer.initialize(session);
587 query.setLimit(begin, end);
588
589 return query.list();
590 }
591 catch (Exception e) {
592 throw HibernateUtil.processException(e);
593 }
594 finally {
595 closeSession(session);
596 }
597 }
598
599 public List findAll() throws SystemException {
600 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
601 }
602
603 public List findAll(int begin, int end) throws SystemException {
604 return findAll(begin, end, null);
605 }
606
607 public List findAll(int begin, int end, OrderByComparator obc)
608 throws SystemException {
609 String finderClassName = WikiNode.class.getName();
610 String finderMethodName = "findAll";
611 String[] finderParams = new String[] {
612 "java.lang.Integer", "java.lang.Integer",
613 "com.liferay.portal.kernel.util.OrderByComparator"
614 };
615 Object[] finderArgs = new Object[] {
616 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
617 };
618 Object result = FinderCache.getResult(finderClassName,
619 finderMethodName, finderParams, finderArgs, getSessionFactory());
620
621 if (result == null) {
622 Session session = null;
623
624 try {
625 session = openSession();
626
627 StringMaker query = new StringMaker();
628 query.append("FROM com.liferay.portlet.wiki.model.WikiNode ");
629
630 if (obc != null) {
631 query.append("ORDER BY ");
632 query.append(obc.getOrderBy());
633 }
634 else {
635 query.append("ORDER BY ");
636 query.append("name ASC");
637 }
638
639 Query q = session.createQuery(query.toString());
640 List list = QueryUtil.list(q, getDialect(), begin, end);
641
642 if (obc == null) {
643 Collections.sort(list);
644 }
645
646 FinderCache.putResult(finderClassName, finderMethodName,
647 finderParams, finderArgs, list);
648
649 return list;
650 }
651 catch (Exception e) {
652 throw HibernateUtil.processException(e);
653 }
654 finally {
655 closeSession(session);
656 }
657 }
658 else {
659 return (List)result;
660 }
661 }
662
663 public void removeByGroupId(long groupId) throws SystemException {
664 Iterator itr = findByGroupId(groupId).iterator();
665
666 while (itr.hasNext()) {
667 WikiNode wikiNode = (WikiNode)itr.next();
668 remove(wikiNode);
669 }
670 }
671
672 public void removeByCompanyId(long companyId) throws SystemException {
673 Iterator itr = findByCompanyId(companyId).iterator();
674
675 while (itr.hasNext()) {
676 WikiNode wikiNode = (WikiNode)itr.next();
677 remove(wikiNode);
678 }
679 }
680
681 public void removeAll() throws SystemException {
682 Iterator itr = findAll().iterator();
683
684 while (itr.hasNext()) {
685 remove((WikiNode)itr.next());
686 }
687 }
688
689 public int countByGroupId(long groupId) throws SystemException {
690 String finderClassName = WikiNode.class.getName();
691 String finderMethodName = "countByGroupId";
692 String[] finderParams = new String[] { Long.class.getName() };
693 Object[] finderArgs = new Object[] { new Long(groupId) };
694 Object result = FinderCache.getResult(finderClassName,
695 finderMethodName, finderParams, finderArgs, getSessionFactory());
696
697 if (result == null) {
698 Session session = null;
699
700 try {
701 session = openSession();
702
703 StringMaker query = new StringMaker();
704 query.append("SELECT COUNT(*) ");
705 query.append(
706 "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
707 query.append("groupId = ?");
708 query.append(" ");
709
710 Query q = session.createQuery(query.toString());
711 int queryPos = 0;
712 q.setLong(queryPos++, groupId);
713
714 Long count = null;
715 Iterator itr = q.list().iterator();
716
717 if (itr.hasNext()) {
718 count = (Long)itr.next();
719 }
720
721 if (count == null) {
722 count = new Long(0);
723 }
724
725 FinderCache.putResult(finderClassName, finderMethodName,
726 finderParams, finderArgs, count);
727
728 return count.intValue();
729 }
730 catch (Exception e) {
731 throw HibernateUtil.processException(e);
732 }
733 finally {
734 closeSession(session);
735 }
736 }
737 else {
738 return ((Long)result).intValue();
739 }
740 }
741
742 public int countByCompanyId(long companyId) throws SystemException {
743 String finderClassName = WikiNode.class.getName();
744 String finderMethodName = "countByCompanyId";
745 String[] finderParams = new String[] { Long.class.getName() };
746 Object[] finderArgs = new Object[] { new Long(companyId) };
747 Object result = FinderCache.getResult(finderClassName,
748 finderMethodName, finderParams, finderArgs, getSessionFactory());
749
750 if (result == null) {
751 Session session = null;
752
753 try {
754 session = openSession();
755
756 StringMaker query = new StringMaker();
757 query.append("SELECT COUNT(*) ");
758 query.append(
759 "FROM com.liferay.portlet.wiki.model.WikiNode WHERE ");
760 query.append("companyId = ?");
761 query.append(" ");
762
763 Query q = session.createQuery(query.toString());
764 int queryPos = 0;
765 q.setLong(queryPos++, companyId);
766
767 Long count = null;
768 Iterator itr = q.list().iterator();
769
770 if (itr.hasNext()) {
771 count = (Long)itr.next();
772 }
773
774 if (count == null) {
775 count = new Long(0);
776 }
777
778 FinderCache.putResult(finderClassName, finderMethodName,
779 finderParams, finderArgs, count);
780
781 return count.intValue();
782 }
783 catch (Exception e) {
784 throw HibernateUtil.processException(e);
785 }
786 finally {
787 closeSession(session);
788 }
789 }
790 else {
791 return ((Long)result).intValue();
792 }
793 }
794
795 public int countAll() throws SystemException {
796 String finderClassName = WikiNode.class.getName();
797 String finderMethodName = "countAll";
798 String[] finderParams = new String[] { };
799 Object[] finderArgs = new Object[] { };
800 Object result = FinderCache.getResult(finderClassName,
801 finderMethodName, finderParams, finderArgs, getSessionFactory());
802
803 if (result == null) {
804 Session session = null;
805
806 try {
807 session = openSession();
808
809 StringMaker query = new StringMaker();
810 query.append("SELECT COUNT(*) ");
811 query.append("FROM com.liferay.portlet.wiki.model.WikiNode");
812
813 Query q = session.createQuery(query.toString());
814 Long count = null;
815 Iterator itr = q.list().iterator();
816
817 if (itr.hasNext()) {
818 count = (Long)itr.next();
819 }
820
821 if (count == null) {
822 count = new Long(0);
823 }
824
825 FinderCache.putResult(finderClassName, finderMethodName,
826 finderParams, finderArgs, count);
827
828 return count.intValue();
829 }
830 catch (Exception e) {
831 throw HibernateUtil.processException(e);
832 }
833 finally {
834 closeSession(session);
835 }
836 }
837 else {
838 return ((Long)result).intValue();
839 }
840 }
841
842 protected void initDao() {
843 }
844
845 private static Log _log = LogFactory.getLog(WikiNodePersistenceImpl.class);
846 }