1
22
23 package com.liferay.portal.service.persistence;
24
25 import com.liferay.portal.NoSuchResourceCodeException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.dao.DynamicQuery;
28 import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
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.model.ResourceCode;
33 import com.liferay.portal.model.impl.ResourceCodeImpl;
34 import com.liferay.portal.service.persistence.BasePersistence;
35 import com.liferay.portal.spring.hibernate.FinderCache;
36 import com.liferay.portal.spring.hibernate.HibernateUtil;
37
38 import com.liferay.util.dao.hibernate.QueryUtil;
39
40 import org.apache.commons.logging.Log;
41 import org.apache.commons.logging.LogFactory;
42
43 import org.hibernate.Query;
44 import org.hibernate.Session;
45
46 import java.util.Collections;
47 import java.util.Iterator;
48 import java.util.List;
49
50
56 public class ResourceCodePersistenceImpl extends BasePersistence
57 implements ResourceCodePersistence {
58 public ResourceCode create(long codeId) {
59 ResourceCode resourceCode = new ResourceCodeImpl();
60 resourceCode.setNew(true);
61 resourceCode.setPrimaryKey(codeId);
62
63 return resourceCode;
64 }
65
66 public ResourceCode remove(long codeId)
67 throws NoSuchResourceCodeException, SystemException {
68 Session session = null;
69
70 try {
71 session = openSession();
72
73 ResourceCode resourceCode = (ResourceCode)session.get(ResourceCodeImpl.class,
74 new Long(codeId));
75
76 if (resourceCode == null) {
77 if (_log.isWarnEnabled()) {
78 _log.warn("No ResourceCode exists with the primary key " +
79 codeId);
80 }
81
82 throw new NoSuchResourceCodeException(
83 "No ResourceCode exists with the primary key " + codeId);
84 }
85
86 return remove(resourceCode);
87 }
88 catch (NoSuchResourceCodeException nsee) {
89 throw nsee;
90 }
91 catch (Exception e) {
92 throw HibernateUtil.processException(e);
93 }
94 finally {
95 closeSession(session);
96 }
97 }
98
99 public ResourceCode remove(ResourceCode resourceCode)
100 throws SystemException {
101 Session session = null;
102
103 try {
104 session = openSession();
105 session.delete(resourceCode);
106 session.flush();
107
108 return resourceCode;
109 }
110 catch (Exception e) {
111 throw HibernateUtil.processException(e);
112 }
113 finally {
114 closeSession(session);
115 FinderCache.clearCache(ResourceCode.class.getName());
116 }
117 }
118
119 public ResourceCode update(
120 com.liferay.portal.model.ResourceCode resourceCode)
121 throws SystemException {
122 return update(resourceCode, false);
123 }
124
125 public ResourceCode update(
126 com.liferay.portal.model.ResourceCode resourceCode, boolean merge)
127 throws SystemException {
128 Session session = null;
129
130 try {
131 session = openSession();
132
133 if (merge) {
134 session.merge(resourceCode);
135 }
136 else {
137 if (resourceCode.isNew()) {
138 session.save(resourceCode);
139 }
140 }
141
142 session.flush();
143 resourceCode.setNew(false);
144
145 return resourceCode;
146 }
147 catch (Exception e) {
148 throw HibernateUtil.processException(e);
149 }
150 finally {
151 closeSession(session);
152 FinderCache.clearCache(ResourceCode.class.getName());
153 }
154 }
155
156 public ResourceCode findByPrimaryKey(long codeId)
157 throws NoSuchResourceCodeException, SystemException {
158 ResourceCode resourceCode = fetchByPrimaryKey(codeId);
159
160 if (resourceCode == null) {
161 if (_log.isWarnEnabled()) {
162 _log.warn("No ResourceCode exists with the primary key " +
163 codeId);
164 }
165
166 throw new NoSuchResourceCodeException(
167 "No ResourceCode exists with the primary key " + codeId);
168 }
169
170 return resourceCode;
171 }
172
173 public ResourceCode fetchByPrimaryKey(long codeId)
174 throws SystemException {
175 Session session = null;
176
177 try {
178 session = openSession();
179
180 return (ResourceCode)session.get(ResourceCodeImpl.class,
181 new Long(codeId));
182 }
183 catch (Exception e) {
184 throw HibernateUtil.processException(e);
185 }
186 finally {
187 closeSession(session);
188 }
189 }
190
191 public List findByCompanyId(long companyId) throws SystemException {
192 String finderClassName = ResourceCode.class.getName();
193 String finderMethodName = "findByCompanyId";
194 String[] finderParams = new String[] { Long.class.getName() };
195 Object[] finderArgs = new Object[] { new Long(companyId) };
196 Object result = FinderCache.getResult(finderClassName,
197 finderMethodName, finderParams, finderArgs, getSessionFactory());
198
199 if (result == null) {
200 Session session = null;
201
202 try {
203 session = openSession();
204
205 StringMaker query = new StringMaker();
206 query.append(
207 "FROM com.liferay.portal.model.ResourceCode WHERE ");
208 query.append("companyId = ?");
209 query.append(" ");
210
211 Query q = session.createQuery(query.toString());
212 int queryPos = 0;
213 q.setLong(queryPos++, companyId);
214
215 List list = q.list();
216 FinderCache.putResult(finderClassName, finderMethodName,
217 finderParams, finderArgs, list);
218
219 return list;
220 }
221 catch (Exception e) {
222 throw HibernateUtil.processException(e);
223 }
224 finally {
225 closeSession(session);
226 }
227 }
228 else {
229 return (List)result;
230 }
231 }
232
233 public List findByCompanyId(long companyId, int begin, int end)
234 throws SystemException {
235 return findByCompanyId(companyId, begin, end, null);
236 }
237
238 public List findByCompanyId(long companyId, int begin, int end,
239 OrderByComparator obc) throws SystemException {
240 String finderClassName = ResourceCode.class.getName();
241 String finderMethodName = "findByCompanyId";
242 String[] finderParams = new String[] {
243 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
244 "com.liferay.portal.kernel.util.OrderByComparator"
245 };
246 Object[] finderArgs = new Object[] {
247 new Long(companyId), String.valueOf(begin), String.valueOf(end),
248 String.valueOf(obc)
249 };
250 Object result = FinderCache.getResult(finderClassName,
251 finderMethodName, finderParams, finderArgs, getSessionFactory());
252
253 if (result == null) {
254 Session session = null;
255
256 try {
257 session = openSession();
258
259 StringMaker query = new StringMaker();
260 query.append(
261 "FROM com.liferay.portal.model.ResourceCode WHERE ");
262 query.append("companyId = ?");
263 query.append(" ");
264
265 if (obc != null) {
266 query.append("ORDER BY ");
267 query.append(obc.getOrderBy());
268 }
269
270 Query q = session.createQuery(query.toString());
271 int queryPos = 0;
272 q.setLong(queryPos++, companyId);
273
274 List list = QueryUtil.list(q, getDialect(), begin, end);
275 FinderCache.putResult(finderClassName, finderMethodName,
276 finderParams, finderArgs, list);
277
278 return list;
279 }
280 catch (Exception e) {
281 throw HibernateUtil.processException(e);
282 }
283 finally {
284 closeSession(session);
285 }
286 }
287 else {
288 return (List)result;
289 }
290 }
291
292 public ResourceCode findByCompanyId_First(long companyId,
293 OrderByComparator obc)
294 throws NoSuchResourceCodeException, SystemException {
295 List list = findByCompanyId(companyId, 0, 1, obc);
296
297 if (list.size() == 0) {
298 StringMaker msg = new StringMaker();
299 msg.append("No ResourceCode exists with the key ");
300 msg.append(StringPool.OPEN_CURLY_BRACE);
301 msg.append("companyId=");
302 msg.append(companyId);
303 msg.append(StringPool.CLOSE_CURLY_BRACE);
304 throw new NoSuchResourceCodeException(msg.toString());
305 }
306 else {
307 return (ResourceCode)list.get(0);
308 }
309 }
310
311 public ResourceCode findByCompanyId_Last(long companyId,
312 OrderByComparator obc)
313 throws NoSuchResourceCodeException, SystemException {
314 int count = countByCompanyId(companyId);
315 List list = findByCompanyId(companyId, count - 1, count, obc);
316
317 if (list.size() == 0) {
318 StringMaker msg = new StringMaker();
319 msg.append("No ResourceCode exists with the key ");
320 msg.append(StringPool.OPEN_CURLY_BRACE);
321 msg.append("companyId=");
322 msg.append(companyId);
323 msg.append(StringPool.CLOSE_CURLY_BRACE);
324 throw new NoSuchResourceCodeException(msg.toString());
325 }
326 else {
327 return (ResourceCode)list.get(0);
328 }
329 }
330
331 public ResourceCode[] findByCompanyId_PrevAndNext(long codeId,
332 long companyId, OrderByComparator obc)
333 throws NoSuchResourceCodeException, SystemException {
334 ResourceCode resourceCode = findByPrimaryKey(codeId);
335 int count = countByCompanyId(companyId);
336 Session session = null;
337
338 try {
339 session = openSession();
340
341 StringMaker query = new StringMaker();
342 query.append("FROM com.liferay.portal.model.ResourceCode WHERE ");
343 query.append("companyId = ?");
344 query.append(" ");
345
346 if (obc != null) {
347 query.append("ORDER BY ");
348 query.append(obc.getOrderBy());
349 }
350
351 Query q = session.createQuery(query.toString());
352 int queryPos = 0;
353 q.setLong(queryPos++, companyId);
354
355 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
356 resourceCode);
357 ResourceCode[] array = new ResourceCodeImpl[3];
358 array[0] = (ResourceCode)objArray[0];
359 array[1] = (ResourceCode)objArray[1];
360 array[2] = (ResourceCode)objArray[2];
361
362 return array;
363 }
364 catch (Exception e) {
365 throw HibernateUtil.processException(e);
366 }
367 finally {
368 closeSession(session);
369 }
370 }
371
372 public List findByName(String name) throws SystemException {
373 String finderClassName = ResourceCode.class.getName();
374 String finderMethodName = "findByName";
375 String[] finderParams = new String[] { String.class.getName() };
376 Object[] finderArgs = new Object[] { name };
377 Object result = FinderCache.getResult(finderClassName,
378 finderMethodName, finderParams, finderArgs, getSessionFactory());
379
380 if (result == null) {
381 Session session = null;
382
383 try {
384 session = openSession();
385
386 StringMaker query = new StringMaker();
387 query.append(
388 "FROM com.liferay.portal.model.ResourceCode WHERE ");
389
390 if (name == null) {
391 query.append("name IS NULL");
392 }
393 else {
394 query.append("name = ?");
395 }
396
397 query.append(" ");
398
399 Query q = session.createQuery(query.toString());
400 int queryPos = 0;
401
402 if (name != null) {
403 q.setString(queryPos++, name);
404 }
405
406 List list = q.list();
407 FinderCache.putResult(finderClassName, finderMethodName,
408 finderParams, finderArgs, list);
409
410 return list;
411 }
412 catch (Exception e) {
413 throw HibernateUtil.processException(e);
414 }
415 finally {
416 closeSession(session);
417 }
418 }
419 else {
420 return (List)result;
421 }
422 }
423
424 public List findByName(String name, int begin, int end)
425 throws SystemException {
426 return findByName(name, begin, end, null);
427 }
428
429 public List findByName(String name, int begin, int end,
430 OrderByComparator obc) throws SystemException {
431 String finderClassName = ResourceCode.class.getName();
432 String finderMethodName = "findByName";
433 String[] finderParams = new String[] {
434 String.class.getName(), "java.lang.Integer", "java.lang.Integer",
435 "com.liferay.portal.kernel.util.OrderByComparator"
436 };
437 Object[] finderArgs = new Object[] {
438 name, String.valueOf(begin), String.valueOf(end),
439 String.valueOf(obc)
440 };
441 Object result = FinderCache.getResult(finderClassName,
442 finderMethodName, finderParams, finderArgs, getSessionFactory());
443
444 if (result == null) {
445 Session session = null;
446
447 try {
448 session = openSession();
449
450 StringMaker query = new StringMaker();
451 query.append(
452 "FROM com.liferay.portal.model.ResourceCode WHERE ");
453
454 if (name == null) {
455 query.append("name IS NULL");
456 }
457 else {
458 query.append("name = ?");
459 }
460
461 query.append(" ");
462
463 if (obc != null) {
464 query.append("ORDER BY ");
465 query.append(obc.getOrderBy());
466 }
467
468 Query q = session.createQuery(query.toString());
469 int queryPos = 0;
470
471 if (name != null) {
472 q.setString(queryPos++, name);
473 }
474
475 List list = QueryUtil.list(q, getDialect(), begin, end);
476 FinderCache.putResult(finderClassName, finderMethodName,
477 finderParams, finderArgs, list);
478
479 return list;
480 }
481 catch (Exception e) {
482 throw HibernateUtil.processException(e);
483 }
484 finally {
485 closeSession(session);
486 }
487 }
488 else {
489 return (List)result;
490 }
491 }
492
493 public ResourceCode findByName_First(String name, OrderByComparator obc)
494 throws NoSuchResourceCodeException, SystemException {
495 List list = findByName(name, 0, 1, obc);
496
497 if (list.size() == 0) {
498 StringMaker msg = new StringMaker();
499 msg.append("No ResourceCode exists with the key ");
500 msg.append(StringPool.OPEN_CURLY_BRACE);
501 msg.append("name=");
502 msg.append(name);
503 msg.append(StringPool.CLOSE_CURLY_BRACE);
504 throw new NoSuchResourceCodeException(msg.toString());
505 }
506 else {
507 return (ResourceCode)list.get(0);
508 }
509 }
510
511 public ResourceCode findByName_Last(String name, OrderByComparator obc)
512 throws NoSuchResourceCodeException, SystemException {
513 int count = countByName(name);
514 List list = findByName(name, count - 1, count, obc);
515
516 if (list.size() == 0) {
517 StringMaker msg = new StringMaker();
518 msg.append("No ResourceCode exists with the key ");
519 msg.append(StringPool.OPEN_CURLY_BRACE);
520 msg.append("name=");
521 msg.append(name);
522 msg.append(StringPool.CLOSE_CURLY_BRACE);
523 throw new NoSuchResourceCodeException(msg.toString());
524 }
525 else {
526 return (ResourceCode)list.get(0);
527 }
528 }
529
530 public ResourceCode[] findByName_PrevAndNext(long codeId, String name,
531 OrderByComparator obc)
532 throws NoSuchResourceCodeException, SystemException {
533 ResourceCode resourceCode = findByPrimaryKey(codeId);
534 int count = countByName(name);
535 Session session = null;
536
537 try {
538 session = openSession();
539
540 StringMaker query = new StringMaker();
541 query.append("FROM com.liferay.portal.model.ResourceCode WHERE ");
542
543 if (name == null) {
544 query.append("name IS NULL");
545 }
546 else {
547 query.append("name = ?");
548 }
549
550 query.append(" ");
551
552 if (obc != null) {
553 query.append("ORDER BY ");
554 query.append(obc.getOrderBy());
555 }
556
557 Query q = session.createQuery(query.toString());
558 int queryPos = 0;
559
560 if (name != null) {
561 q.setString(queryPos++, name);
562 }
563
564 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
565 resourceCode);
566 ResourceCode[] array = new ResourceCodeImpl[3];
567 array[0] = (ResourceCode)objArray[0];
568 array[1] = (ResourceCode)objArray[1];
569 array[2] = (ResourceCode)objArray[2];
570
571 return array;
572 }
573 catch (Exception e) {
574 throw HibernateUtil.processException(e);
575 }
576 finally {
577 closeSession(session);
578 }
579 }
580
581 public ResourceCode findByC_N_S(long companyId, String name, int scope)
582 throws NoSuchResourceCodeException, SystemException {
583 ResourceCode resourceCode = fetchByC_N_S(companyId, name, scope);
584
585 if (resourceCode == null) {
586 StringMaker msg = new StringMaker();
587 msg.append("No ResourceCode exists with the key ");
588 msg.append(StringPool.OPEN_CURLY_BRACE);
589 msg.append("companyId=");
590 msg.append(companyId);
591 msg.append(", ");
592 msg.append("name=");
593 msg.append(name);
594 msg.append(", ");
595 msg.append("scope=");
596 msg.append(scope);
597 msg.append(StringPool.CLOSE_CURLY_BRACE);
598
599 if (_log.isWarnEnabled()) {
600 _log.warn(msg.toString());
601 }
602
603 throw new NoSuchResourceCodeException(msg.toString());
604 }
605
606 return resourceCode;
607 }
608
609 public ResourceCode fetchByC_N_S(long companyId, String name, int scope)
610 throws SystemException {
611 String finderClassName = ResourceCode.class.getName();
612 String finderMethodName = "fetchByC_N_S";
613 String[] finderParams = new String[] {
614 Long.class.getName(), String.class.getName(),
615 Integer.class.getName()
616 };
617 Object[] finderArgs = new Object[] {
618 new Long(companyId), name, new Integer(scope)
619 };
620 Object result = FinderCache.getResult(finderClassName,
621 finderMethodName, finderParams, finderArgs, getSessionFactory());
622
623 if (result == null) {
624 Session session = null;
625
626 try {
627 session = openSession();
628
629 StringMaker query = new StringMaker();
630 query.append(
631 "FROM com.liferay.portal.model.ResourceCode WHERE ");
632 query.append("companyId = ?");
633 query.append(" AND ");
634
635 if (name == null) {
636 query.append("name IS NULL");
637 }
638 else {
639 query.append("name = ?");
640 }
641
642 query.append(" AND ");
643 query.append("scope = ?");
644 query.append(" ");
645
646 Query q = session.createQuery(query.toString());
647 int queryPos = 0;
648 q.setLong(queryPos++, companyId);
649
650 if (name != null) {
651 q.setString(queryPos++, name);
652 }
653
654 q.setInteger(queryPos++, scope);
655
656 List list = q.list();
657 FinderCache.putResult(finderClassName, finderMethodName,
658 finderParams, finderArgs, list);
659
660 if (list.size() == 0) {
661 return null;
662 }
663 else {
664 return (ResourceCode)list.get(0);
665 }
666 }
667 catch (Exception e) {
668 throw HibernateUtil.processException(e);
669 }
670 finally {
671 closeSession(session);
672 }
673 }
674 else {
675 List list = (List)result;
676
677 if (list.size() == 0) {
678 return null;
679 }
680 else {
681 return (ResourceCode)list.get(0);
682 }
683 }
684 }
685
686 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
687 throws SystemException {
688 Session session = null;
689
690 try {
691 session = openSession();
692
693 DynamicQuery query = queryInitializer.initialize(session);
694
695 return query.list();
696 }
697 catch (Exception e) {
698 throw HibernateUtil.processException(e);
699 }
700 finally {
701 closeSession(session);
702 }
703 }
704
705 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
706 int begin, int end) throws SystemException {
707 Session session = null;
708
709 try {
710 session = openSession();
711
712 DynamicQuery query = queryInitializer.initialize(session);
713 query.setLimit(begin, end);
714
715 return query.list();
716 }
717 catch (Exception e) {
718 throw HibernateUtil.processException(e);
719 }
720 finally {
721 closeSession(session);
722 }
723 }
724
725 public List findAll() throws SystemException {
726 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
727 }
728
729 public List findAll(int begin, int end) throws SystemException {
730 return findAll(begin, end, null);
731 }
732
733 public List findAll(int begin, int end, OrderByComparator obc)
734 throws SystemException {
735 String finderClassName = ResourceCode.class.getName();
736 String finderMethodName = "findAll";
737 String[] finderParams = new String[] {
738 "java.lang.Integer", "java.lang.Integer",
739 "com.liferay.portal.kernel.util.OrderByComparator"
740 };
741 Object[] finderArgs = new Object[] {
742 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
743 };
744 Object result = FinderCache.getResult(finderClassName,
745 finderMethodName, finderParams, finderArgs, getSessionFactory());
746
747 if (result == null) {
748 Session session = null;
749
750 try {
751 session = openSession();
752
753 StringMaker query = new StringMaker();
754 query.append("FROM com.liferay.portal.model.ResourceCode ");
755
756 if (obc != null) {
757 query.append("ORDER BY ");
758 query.append(obc.getOrderBy());
759 }
760
761 Query q = session.createQuery(query.toString());
762 List list = QueryUtil.list(q, getDialect(), begin, end);
763
764 if (obc == null) {
765 Collections.sort(list);
766 }
767
768 FinderCache.putResult(finderClassName, finderMethodName,
769 finderParams, finderArgs, list);
770
771 return list;
772 }
773 catch (Exception e) {
774 throw HibernateUtil.processException(e);
775 }
776 finally {
777 closeSession(session);
778 }
779 }
780 else {
781 return (List)result;
782 }
783 }
784
785 public void removeByCompanyId(long companyId) throws SystemException {
786 Iterator itr = findByCompanyId(companyId).iterator();
787
788 while (itr.hasNext()) {
789 ResourceCode resourceCode = (ResourceCode)itr.next();
790 remove(resourceCode);
791 }
792 }
793
794 public void removeByName(String name) throws SystemException {
795 Iterator itr = findByName(name).iterator();
796
797 while (itr.hasNext()) {
798 ResourceCode resourceCode = (ResourceCode)itr.next();
799 remove(resourceCode);
800 }
801 }
802
803 public void removeByC_N_S(long companyId, String name, int scope)
804 throws NoSuchResourceCodeException, SystemException {
805 ResourceCode resourceCode = findByC_N_S(companyId, name, scope);
806 remove(resourceCode);
807 }
808
809 public void removeAll() throws SystemException {
810 Iterator itr = findAll().iterator();
811
812 while (itr.hasNext()) {
813 remove((ResourceCode)itr.next());
814 }
815 }
816
817 public int countByCompanyId(long companyId) throws SystemException {
818 String finderClassName = ResourceCode.class.getName();
819 String finderMethodName = "countByCompanyId";
820 String[] finderParams = new String[] { Long.class.getName() };
821 Object[] finderArgs = new Object[] { new Long(companyId) };
822 Object result = FinderCache.getResult(finderClassName,
823 finderMethodName, finderParams, finderArgs, getSessionFactory());
824
825 if (result == null) {
826 Session session = null;
827
828 try {
829 session = openSession();
830
831 StringMaker query = new StringMaker();
832 query.append("SELECT COUNT(*) ");
833 query.append(
834 "FROM com.liferay.portal.model.ResourceCode WHERE ");
835 query.append("companyId = ?");
836 query.append(" ");
837
838 Query q = session.createQuery(query.toString());
839 int queryPos = 0;
840 q.setLong(queryPos++, companyId);
841
842 Long count = null;
843 Iterator itr = q.list().iterator();
844
845 if (itr.hasNext()) {
846 count = (Long)itr.next();
847 }
848
849 if (count == null) {
850 count = new Long(0);
851 }
852
853 FinderCache.putResult(finderClassName, finderMethodName,
854 finderParams, finderArgs, count);
855
856 return count.intValue();
857 }
858 catch (Exception e) {
859 throw HibernateUtil.processException(e);
860 }
861 finally {
862 closeSession(session);
863 }
864 }
865 else {
866 return ((Long)result).intValue();
867 }
868 }
869
870 public int countByName(String name) throws SystemException {
871 String finderClassName = ResourceCode.class.getName();
872 String finderMethodName = "countByName";
873 String[] finderParams = new String[] { String.class.getName() };
874 Object[] finderArgs = new Object[] { name };
875 Object result = FinderCache.getResult(finderClassName,
876 finderMethodName, finderParams, finderArgs, getSessionFactory());
877
878 if (result == null) {
879 Session session = null;
880
881 try {
882 session = openSession();
883
884 StringMaker query = new StringMaker();
885 query.append("SELECT COUNT(*) ");
886 query.append(
887 "FROM com.liferay.portal.model.ResourceCode WHERE ");
888
889 if (name == null) {
890 query.append("name IS NULL");
891 }
892 else {
893 query.append("name = ?");
894 }
895
896 query.append(" ");
897
898 Query q = session.createQuery(query.toString());
899 int queryPos = 0;
900
901 if (name != null) {
902 q.setString(queryPos++, name);
903 }
904
905 Long count = null;
906 Iterator itr = q.list().iterator();
907
908 if (itr.hasNext()) {
909 count = (Long)itr.next();
910 }
911
912 if (count == null) {
913 count = new Long(0);
914 }
915
916 FinderCache.putResult(finderClassName, finderMethodName,
917 finderParams, finderArgs, count);
918
919 return count.intValue();
920 }
921 catch (Exception e) {
922 throw HibernateUtil.processException(e);
923 }
924 finally {
925 closeSession(session);
926 }
927 }
928 else {
929 return ((Long)result).intValue();
930 }
931 }
932
933 public int countByC_N_S(long companyId, String name, int scope)
934 throws SystemException {
935 String finderClassName = ResourceCode.class.getName();
936 String finderMethodName = "countByC_N_S";
937 String[] finderParams = new String[] {
938 Long.class.getName(), String.class.getName(),
939 Integer.class.getName()
940 };
941 Object[] finderArgs = new Object[] {
942 new Long(companyId), name, new Integer(scope)
943 };
944 Object result = FinderCache.getResult(finderClassName,
945 finderMethodName, finderParams, finderArgs, getSessionFactory());
946
947 if (result == null) {
948 Session session = null;
949
950 try {
951 session = openSession();
952
953 StringMaker query = new StringMaker();
954 query.append("SELECT COUNT(*) ");
955 query.append(
956 "FROM com.liferay.portal.model.ResourceCode WHERE ");
957 query.append("companyId = ?");
958 query.append(" AND ");
959
960 if (name == null) {
961 query.append("name IS NULL");
962 }
963 else {
964 query.append("name = ?");
965 }
966
967 query.append(" AND ");
968 query.append("scope = ?");
969 query.append(" ");
970
971 Query q = session.createQuery(query.toString());
972 int queryPos = 0;
973 q.setLong(queryPos++, companyId);
974
975 if (name != null) {
976 q.setString(queryPos++, name);
977 }
978
979 q.setInteger(queryPos++, scope);
980
981 Long count = null;
982 Iterator itr = q.list().iterator();
983
984 if (itr.hasNext()) {
985 count = (Long)itr.next();
986 }
987
988 if (count == null) {
989 count = new Long(0);
990 }
991
992 FinderCache.putResult(finderClassName, finderMethodName,
993 finderParams, finderArgs, count);
994
995 return count.intValue();
996 }
997 catch (Exception e) {
998 throw HibernateUtil.processException(e);
999 }
1000 finally {
1001 closeSession(session);
1002 }
1003 }
1004 else {
1005 return ((Long)result).intValue();
1006 }
1007 }
1008
1009 public int countAll() throws SystemException {
1010 String finderClassName = ResourceCode.class.getName();
1011 String finderMethodName = "countAll";
1012 String[] finderParams = new String[] { };
1013 Object[] finderArgs = new Object[] { };
1014 Object result = FinderCache.getResult(finderClassName,
1015 finderMethodName, finderParams, finderArgs, getSessionFactory());
1016
1017 if (result == null) {
1018 Session session = null;
1019
1020 try {
1021 session = openSession();
1022
1023 StringMaker query = new StringMaker();
1024 query.append("SELECT COUNT(*) ");
1025 query.append("FROM com.liferay.portal.model.ResourceCode");
1026
1027 Query q = session.createQuery(query.toString());
1028 Long count = null;
1029 Iterator itr = q.list().iterator();
1030
1031 if (itr.hasNext()) {
1032 count = (Long)itr.next();
1033 }
1034
1035 if (count == null) {
1036 count = new Long(0);
1037 }
1038
1039 FinderCache.putResult(finderClassName, finderMethodName,
1040 finderParams, finderArgs, count);
1041
1042 return count.intValue();
1043 }
1044 catch (Exception e) {
1045 throw HibernateUtil.processException(e);
1046 }
1047 finally {
1048 closeSession(session);
1049 }
1050 }
1051 else {
1052 return ((Long)result).intValue();
1053 }
1054 }
1055
1056 protected void initDao() {
1057 }
1058
1059 private static Log _log = LogFactory.getLog(ResourceCodePersistenceImpl.class);
1060}