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