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