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