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