1
22
23 package com.liferay.portlet.softwarecatalog.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.dao.DynamicQuery;
27 import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
28 import com.liferay.portal.kernel.util.GetterUtil;
29 import com.liferay.portal.kernel.util.OrderByComparator;
30 import com.liferay.portal.kernel.util.StringMaker;
31 import com.liferay.portal.kernel.util.StringPool;
32 import com.liferay.portal.kernel.util.Validator;
33 import com.liferay.portal.model.ModelListener;
34 import com.liferay.portal.service.persistence.BasePersistence;
35 import com.liferay.portal.spring.hibernate.FinderCache;
36 import com.liferay.portal.spring.hibernate.HibernateUtil;
37 import com.liferay.portal.util.PropsUtil;
38
39 import com.liferay.portlet.softwarecatalog.NoSuchProductEntryException;
40 import com.liferay.portlet.softwarecatalog.model.SCProductEntry;
41 import com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryImpl;
42 import com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryModelImpl;
43
44 import com.liferay.util.dao.hibernate.QueryPos;
45 import com.liferay.util.dao.hibernate.QueryUtil;
46
47 import org.apache.commons.logging.Log;
48 import org.apache.commons.logging.LogFactory;
49
50 import org.hibernate.Hibernate;
51 import org.hibernate.Query;
52 import org.hibernate.SQLQuery;
53 import org.hibernate.Session;
54
55 import org.springframework.dao.DataAccessException;
56
57 import org.springframework.jdbc.core.SqlParameter;
58 import org.springframework.jdbc.object.MappingSqlQuery;
59 import org.springframework.jdbc.object.SqlUpdate;
60
61 import java.sql.ResultSet;
62 import java.sql.SQLException;
63 import java.sql.Types;
64
65 import java.util.Collections;
66 import java.util.Iterator;
67 import java.util.List;
68
69
75 public class SCProductEntryPersistenceImpl extends BasePersistence
76 implements SCProductEntryPersistence {
77 public SCProductEntry create(long productEntryId) {
78 SCProductEntry scProductEntry = new SCProductEntryImpl();
79
80 scProductEntry.setNew(true);
81 scProductEntry.setPrimaryKey(productEntryId);
82
83 return scProductEntry;
84 }
85
86 public SCProductEntry remove(long productEntryId)
87 throws NoSuchProductEntryException, SystemException {
88 Session session = null;
89
90 try {
91 session = openSession();
92
93 SCProductEntry scProductEntry = (SCProductEntry)session.get(SCProductEntryImpl.class,
94 new Long(productEntryId));
95
96 if (scProductEntry == null) {
97 if (_log.isWarnEnabled()) {
98 _log.warn("No SCProductEntry exists with the primary key " +
99 productEntryId);
100 }
101
102 throw new NoSuchProductEntryException(
103 "No SCProductEntry exists with the primary key " +
104 productEntryId);
105 }
106
107 return remove(scProductEntry);
108 }
109 catch (NoSuchProductEntryException nsee) {
110 throw nsee;
111 }
112 catch (Exception e) {
113 throw HibernateUtil.processException(e);
114 }
115 finally {
116 closeSession(session);
117 }
118 }
119
120 public SCProductEntry remove(SCProductEntry scProductEntry)
121 throws SystemException {
122 ModelListener listener = _getListener();
123
124 if (listener != null) {
125 listener.onBeforeRemove(scProductEntry);
126 }
127
128 scProductEntry = removeImpl(scProductEntry);
129
130 if (listener != null) {
131 listener.onAfterRemove(scProductEntry);
132 }
133
134 return scProductEntry;
135 }
136
137 protected SCProductEntry removeImpl(SCProductEntry scProductEntry)
138 throws SystemException {
139 try {
140 clearSCLicenses.clear(scProductEntry.getPrimaryKey());
141 }
142 catch (Exception e) {
143 throw HibernateUtil.processException(e);
144 }
145 finally {
146 FinderCache.clearCache("SCLicenses_SCProductEntries");
147 }
148
149 Session session = null;
150
151 try {
152 session = openSession();
153
154 session.delete(scProductEntry);
155
156 session.flush();
157
158 return scProductEntry;
159 }
160 catch (Exception e) {
161 throw HibernateUtil.processException(e);
162 }
163 finally {
164 closeSession(session);
165
166 FinderCache.clearCache(SCProductEntry.class.getName());
167 }
168 }
169
170 public SCProductEntry update(SCProductEntry scProductEntry)
171 throws SystemException {
172 return update(scProductEntry, false);
173 }
174
175 public SCProductEntry update(SCProductEntry scProductEntry, boolean merge)
176 throws SystemException {
177 ModelListener listener = _getListener();
178
179 boolean isNew = scProductEntry.isNew();
180
181 if (listener != null) {
182 if (isNew) {
183 listener.onBeforeCreate(scProductEntry);
184 }
185 else {
186 listener.onBeforeUpdate(scProductEntry);
187 }
188 }
189
190 scProductEntry = updateImpl(scProductEntry, merge);
191
192 if (listener != null) {
193 if (isNew) {
194 listener.onAfterCreate(scProductEntry);
195 }
196 else {
197 listener.onAfterUpdate(scProductEntry);
198 }
199 }
200
201 return scProductEntry;
202 }
203
204 public SCProductEntry updateImpl(
205 com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry,
206 boolean merge) throws SystemException {
207 FinderCache.clearCache("SCLicenses_SCProductEntries");
208
209 Session session = null;
210
211 try {
212 session = openSession();
213
214 if (merge) {
215 session.merge(scProductEntry);
216 }
217 else {
218 if (scProductEntry.isNew()) {
219 session.save(scProductEntry);
220 }
221 }
222
223 session.flush();
224
225 scProductEntry.setNew(false);
226
227 return scProductEntry;
228 }
229 catch (Exception e) {
230 throw HibernateUtil.processException(e);
231 }
232 finally {
233 closeSession(session);
234
235 FinderCache.clearCache(SCProductEntry.class.getName());
236 }
237 }
238
239 public SCProductEntry findByPrimaryKey(long productEntryId)
240 throws NoSuchProductEntryException, SystemException {
241 SCProductEntry scProductEntry = fetchByPrimaryKey(productEntryId);
242
243 if (scProductEntry == null) {
244 if (_log.isWarnEnabled()) {
245 _log.warn("No SCProductEntry exists with the primary key " +
246 productEntryId);
247 }
248
249 throw new NoSuchProductEntryException(
250 "No SCProductEntry exists with the primary key " +
251 productEntryId);
252 }
253
254 return scProductEntry;
255 }
256
257 public SCProductEntry fetchByPrimaryKey(long productEntryId)
258 throws SystemException {
259 Session session = null;
260
261 try {
262 session = openSession();
263
264 return (SCProductEntry)session.get(SCProductEntryImpl.class,
265 new Long(productEntryId));
266 }
267 catch (Exception e) {
268 throw HibernateUtil.processException(e);
269 }
270 finally {
271 closeSession(session);
272 }
273 }
274
275 public List findByGroupId(long groupId) throws SystemException {
276 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
277 String finderClassName = SCProductEntry.class.getName();
278 String finderMethodName = "findByGroupId";
279 String[] finderParams = new String[] { Long.class.getName() };
280 Object[] finderArgs = new Object[] { new Long(groupId) };
281
282 Object result = null;
283
284 if (finderClassNameCacheEnabled) {
285 result = FinderCache.getResult(finderClassName, finderMethodName,
286 finderParams, finderArgs, getSessionFactory());
287 }
288
289 if (result == null) {
290 Session session = null;
291
292 try {
293 session = openSession();
294
295 StringMaker query = new StringMaker();
296
297 query.append(
298 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
299
300 query.append("groupId = ?");
301
302 query.append(" ");
303
304 query.append("ORDER BY ");
305
306 query.append("modifiedDate DESC, ");
307 query.append("name DESC");
308
309 Query q = session.createQuery(query.toString());
310
311 int queryPos = 0;
312
313 q.setLong(queryPos++, groupId);
314
315 List list = q.list();
316
317 FinderCache.putResult(finderClassNameCacheEnabled,
318 finderClassName, finderMethodName, finderParams,
319 finderArgs, list);
320
321 return list;
322 }
323 catch (Exception e) {
324 throw HibernateUtil.processException(e);
325 }
326 finally {
327 closeSession(session);
328 }
329 }
330 else {
331 return (List)result;
332 }
333 }
334
335 public List findByGroupId(long groupId, int begin, int end)
336 throws SystemException {
337 return findByGroupId(groupId, begin, end, null);
338 }
339
340 public List findByGroupId(long groupId, int begin, int end,
341 OrderByComparator obc) throws SystemException {
342 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
343 String finderClassName = SCProductEntry.class.getName();
344 String finderMethodName = "findByGroupId";
345 String[] finderParams = new String[] {
346 Long.class.getName(),
347
348 "java.lang.Integer", "java.lang.Integer",
349 "com.liferay.portal.kernel.util.OrderByComparator"
350 };
351 Object[] finderArgs = new Object[] {
352 new Long(groupId),
353
354 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
355 };
356
357 Object result = null;
358
359 if (finderClassNameCacheEnabled) {
360 result = FinderCache.getResult(finderClassName, finderMethodName,
361 finderParams, finderArgs, getSessionFactory());
362 }
363
364 if (result == null) {
365 Session session = null;
366
367 try {
368 session = openSession();
369
370 StringMaker query = new StringMaker();
371
372 query.append(
373 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
374
375 query.append("groupId = ?");
376
377 query.append(" ");
378
379 if (obc != null) {
380 query.append("ORDER BY ");
381 query.append(obc.getOrderBy());
382 }
383
384 else {
385 query.append("ORDER BY ");
386
387 query.append("modifiedDate DESC, ");
388 query.append("name DESC");
389 }
390
391 Query q = session.createQuery(query.toString());
392
393 int queryPos = 0;
394
395 q.setLong(queryPos++, groupId);
396
397 List list = QueryUtil.list(q, getDialect(), begin, end);
398
399 FinderCache.putResult(finderClassNameCacheEnabled,
400 finderClassName, finderMethodName, finderParams,
401 finderArgs, list);
402
403 return list;
404 }
405 catch (Exception e) {
406 throw HibernateUtil.processException(e);
407 }
408 finally {
409 closeSession(session);
410 }
411 }
412 else {
413 return (List)result;
414 }
415 }
416
417 public SCProductEntry findByGroupId_First(long groupId,
418 OrderByComparator obc)
419 throws NoSuchProductEntryException, SystemException {
420 List list = findByGroupId(groupId, 0, 1, obc);
421
422 if (list.size() == 0) {
423 StringMaker msg = new StringMaker();
424
425 msg.append("No SCProductEntry exists with the key {");
426
427 msg.append("groupId=" + groupId);
428
429 msg.append(StringPool.CLOSE_CURLY_BRACE);
430
431 throw new NoSuchProductEntryException(msg.toString());
432 }
433 else {
434 return (SCProductEntry)list.get(0);
435 }
436 }
437
438 public SCProductEntry findByGroupId_Last(long groupId, OrderByComparator obc)
439 throws NoSuchProductEntryException, SystemException {
440 int count = countByGroupId(groupId);
441
442 List list = findByGroupId(groupId, count - 1, count, obc);
443
444 if (list.size() == 0) {
445 StringMaker msg = new StringMaker();
446
447 msg.append("No SCProductEntry exists with the key {");
448
449 msg.append("groupId=" + groupId);
450
451 msg.append(StringPool.CLOSE_CURLY_BRACE);
452
453 throw new NoSuchProductEntryException(msg.toString());
454 }
455 else {
456 return (SCProductEntry)list.get(0);
457 }
458 }
459
460 public SCProductEntry[] findByGroupId_PrevAndNext(long productEntryId,
461 long groupId, OrderByComparator obc)
462 throws NoSuchProductEntryException, SystemException {
463 SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
464
465 int count = countByGroupId(groupId);
466
467 Session session = null;
468
469 try {
470 session = openSession();
471
472 StringMaker query = new StringMaker();
473
474 query.append(
475 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
476
477 query.append("groupId = ?");
478
479 query.append(" ");
480
481 if (obc != null) {
482 query.append("ORDER BY ");
483 query.append(obc.getOrderBy());
484 }
485
486 else {
487 query.append("ORDER BY ");
488
489 query.append("modifiedDate DESC, ");
490 query.append("name DESC");
491 }
492
493 Query q = session.createQuery(query.toString());
494
495 int queryPos = 0;
496
497 q.setLong(queryPos++, groupId);
498
499 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
500 scProductEntry);
501
502 SCProductEntry[] array = new SCProductEntryImpl[3];
503
504 array[0] = (SCProductEntry)objArray[0];
505 array[1] = (SCProductEntry)objArray[1];
506 array[2] = (SCProductEntry)objArray[2];
507
508 return array;
509 }
510 catch (Exception e) {
511 throw HibernateUtil.processException(e);
512 }
513 finally {
514 closeSession(session);
515 }
516 }
517
518 public List findByCompanyId(long companyId) throws SystemException {
519 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
520 String finderClassName = SCProductEntry.class.getName();
521 String finderMethodName = "findByCompanyId";
522 String[] finderParams = new String[] { Long.class.getName() };
523 Object[] finderArgs = new Object[] { new Long(companyId) };
524
525 Object result = null;
526
527 if (finderClassNameCacheEnabled) {
528 result = FinderCache.getResult(finderClassName, finderMethodName,
529 finderParams, finderArgs, getSessionFactory());
530 }
531
532 if (result == null) {
533 Session session = null;
534
535 try {
536 session = openSession();
537
538 StringMaker query = new StringMaker();
539
540 query.append(
541 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
542
543 query.append("companyId = ?");
544
545 query.append(" ");
546
547 query.append("ORDER BY ");
548
549 query.append("modifiedDate DESC, ");
550 query.append("name DESC");
551
552 Query q = session.createQuery(query.toString());
553
554 int queryPos = 0;
555
556 q.setLong(queryPos++, companyId);
557
558 List list = q.list();
559
560 FinderCache.putResult(finderClassNameCacheEnabled,
561 finderClassName, finderMethodName, finderParams,
562 finderArgs, list);
563
564 return list;
565 }
566 catch (Exception e) {
567 throw HibernateUtil.processException(e);
568 }
569 finally {
570 closeSession(session);
571 }
572 }
573 else {
574 return (List)result;
575 }
576 }
577
578 public List findByCompanyId(long companyId, int begin, int end)
579 throws SystemException {
580 return findByCompanyId(companyId, begin, end, null);
581 }
582
583 public List findByCompanyId(long companyId, int begin, int end,
584 OrderByComparator obc) throws SystemException {
585 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
586 String finderClassName = SCProductEntry.class.getName();
587 String finderMethodName = "findByCompanyId";
588 String[] finderParams = new String[] {
589 Long.class.getName(),
590
591 "java.lang.Integer", "java.lang.Integer",
592 "com.liferay.portal.kernel.util.OrderByComparator"
593 };
594 Object[] finderArgs = new Object[] {
595 new Long(companyId),
596
597 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
598 };
599
600 Object result = null;
601
602 if (finderClassNameCacheEnabled) {
603 result = FinderCache.getResult(finderClassName, finderMethodName,
604 finderParams, finderArgs, getSessionFactory());
605 }
606
607 if (result == null) {
608 Session session = null;
609
610 try {
611 session = openSession();
612
613 StringMaker query = new StringMaker();
614
615 query.append(
616 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
617
618 query.append("companyId = ?");
619
620 query.append(" ");
621
622 if (obc != null) {
623 query.append("ORDER BY ");
624 query.append(obc.getOrderBy());
625 }
626
627 else {
628 query.append("ORDER BY ");
629
630 query.append("modifiedDate DESC, ");
631 query.append("name DESC");
632 }
633
634 Query q = session.createQuery(query.toString());
635
636 int queryPos = 0;
637
638 q.setLong(queryPos++, companyId);
639
640 List list = QueryUtil.list(q, getDialect(), begin, end);
641
642 FinderCache.putResult(finderClassNameCacheEnabled,
643 finderClassName, finderMethodName, finderParams,
644 finderArgs, list);
645
646 return list;
647 }
648 catch (Exception e) {
649 throw HibernateUtil.processException(e);
650 }
651 finally {
652 closeSession(session);
653 }
654 }
655 else {
656 return (List)result;
657 }
658 }
659
660 public SCProductEntry findByCompanyId_First(long companyId,
661 OrderByComparator obc)
662 throws NoSuchProductEntryException, SystemException {
663 List list = findByCompanyId(companyId, 0, 1, obc);
664
665 if (list.size() == 0) {
666 StringMaker msg = new StringMaker();
667
668 msg.append("No SCProductEntry exists with the key {");
669
670 msg.append("companyId=" + companyId);
671
672 msg.append(StringPool.CLOSE_CURLY_BRACE);
673
674 throw new NoSuchProductEntryException(msg.toString());
675 }
676 else {
677 return (SCProductEntry)list.get(0);
678 }
679 }
680
681 public SCProductEntry findByCompanyId_Last(long companyId,
682 OrderByComparator obc)
683 throws NoSuchProductEntryException, SystemException {
684 int count = countByCompanyId(companyId);
685
686 List list = findByCompanyId(companyId, count - 1, count, obc);
687
688 if (list.size() == 0) {
689 StringMaker msg = new StringMaker();
690
691 msg.append("No SCProductEntry exists with the key {");
692
693 msg.append("companyId=" + companyId);
694
695 msg.append(StringPool.CLOSE_CURLY_BRACE);
696
697 throw new NoSuchProductEntryException(msg.toString());
698 }
699 else {
700 return (SCProductEntry)list.get(0);
701 }
702 }
703
704 public SCProductEntry[] findByCompanyId_PrevAndNext(long productEntryId,
705 long companyId, OrderByComparator obc)
706 throws NoSuchProductEntryException, SystemException {
707 SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
708
709 int count = countByCompanyId(companyId);
710
711 Session session = null;
712
713 try {
714 session = openSession();
715
716 StringMaker query = new StringMaker();
717
718 query.append(
719 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
720
721 query.append("companyId = ?");
722
723 query.append(" ");
724
725 if (obc != null) {
726 query.append("ORDER BY ");
727 query.append(obc.getOrderBy());
728 }
729
730 else {
731 query.append("ORDER BY ");
732
733 query.append("modifiedDate DESC, ");
734 query.append("name DESC");
735 }
736
737 Query q = session.createQuery(query.toString());
738
739 int queryPos = 0;
740
741 q.setLong(queryPos++, companyId);
742
743 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
744 scProductEntry);
745
746 SCProductEntry[] array = new SCProductEntryImpl[3];
747
748 array[0] = (SCProductEntry)objArray[0];
749 array[1] = (SCProductEntry)objArray[1];
750 array[2] = (SCProductEntry)objArray[2];
751
752 return array;
753 }
754 catch (Exception e) {
755 throw HibernateUtil.processException(e);
756 }
757 finally {
758 closeSession(session);
759 }
760 }
761
762 public List findByG_U(long groupId, long userId) throws SystemException {
763 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
764 String finderClassName = SCProductEntry.class.getName();
765 String finderMethodName = "findByG_U";
766 String[] finderParams = new String[] {
767 Long.class.getName(), Long.class.getName()
768 };
769 Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
770
771 Object result = null;
772
773 if (finderClassNameCacheEnabled) {
774 result = FinderCache.getResult(finderClassName, finderMethodName,
775 finderParams, finderArgs, getSessionFactory());
776 }
777
778 if (result == null) {
779 Session session = null;
780
781 try {
782 session = openSession();
783
784 StringMaker query = new StringMaker();
785
786 query.append(
787 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
788
789 query.append("groupId = ?");
790
791 query.append(" AND ");
792
793 query.append("userId = ?");
794
795 query.append(" ");
796
797 query.append("ORDER BY ");
798
799 query.append("modifiedDate DESC, ");
800 query.append("name DESC");
801
802 Query q = session.createQuery(query.toString());
803
804 int queryPos = 0;
805
806 q.setLong(queryPos++, groupId);
807
808 q.setLong(queryPos++, userId);
809
810 List list = q.list();
811
812 FinderCache.putResult(finderClassNameCacheEnabled,
813 finderClassName, finderMethodName, finderParams,
814 finderArgs, list);
815
816 return list;
817 }
818 catch (Exception e) {
819 throw HibernateUtil.processException(e);
820 }
821 finally {
822 closeSession(session);
823 }
824 }
825 else {
826 return (List)result;
827 }
828 }
829
830 public List findByG_U(long groupId, long userId, int begin, int end)
831 throws SystemException {
832 return findByG_U(groupId, userId, begin, end, null);
833 }
834
835 public List findByG_U(long groupId, long userId, int begin, int end,
836 OrderByComparator obc) throws SystemException {
837 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
838 String finderClassName = SCProductEntry.class.getName();
839 String finderMethodName = "findByG_U";
840 String[] finderParams = new String[] {
841 Long.class.getName(), Long.class.getName(),
842
843 "java.lang.Integer", "java.lang.Integer",
844 "com.liferay.portal.kernel.util.OrderByComparator"
845 };
846 Object[] finderArgs = new Object[] {
847 new Long(groupId), new Long(userId),
848
849 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
850 };
851
852 Object result = null;
853
854 if (finderClassNameCacheEnabled) {
855 result = FinderCache.getResult(finderClassName, finderMethodName,
856 finderParams, finderArgs, getSessionFactory());
857 }
858
859 if (result == null) {
860 Session session = null;
861
862 try {
863 session = openSession();
864
865 StringMaker query = new StringMaker();
866
867 query.append(
868 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
869
870 query.append("groupId = ?");
871
872 query.append(" AND ");
873
874 query.append("userId = ?");
875
876 query.append(" ");
877
878 if (obc != null) {
879 query.append("ORDER BY ");
880 query.append(obc.getOrderBy());
881 }
882
883 else {
884 query.append("ORDER BY ");
885
886 query.append("modifiedDate DESC, ");
887 query.append("name DESC");
888 }
889
890 Query q = session.createQuery(query.toString());
891
892 int queryPos = 0;
893
894 q.setLong(queryPos++, groupId);
895
896 q.setLong(queryPos++, userId);
897
898 List list = QueryUtil.list(q, getDialect(), begin, end);
899
900 FinderCache.putResult(finderClassNameCacheEnabled,
901 finderClassName, finderMethodName, finderParams,
902 finderArgs, list);
903
904 return list;
905 }
906 catch (Exception e) {
907 throw HibernateUtil.processException(e);
908 }
909 finally {
910 closeSession(session);
911 }
912 }
913 else {
914 return (List)result;
915 }
916 }
917
918 public SCProductEntry findByG_U_First(long groupId, long userId,
919 OrderByComparator obc)
920 throws NoSuchProductEntryException, SystemException {
921 List list = findByG_U(groupId, userId, 0, 1, obc);
922
923 if (list.size() == 0) {
924 StringMaker msg = new StringMaker();
925
926 msg.append("No SCProductEntry exists with the key {");
927
928 msg.append("groupId=" + groupId);
929
930 msg.append(", ");
931 msg.append("userId=" + userId);
932
933 msg.append(StringPool.CLOSE_CURLY_BRACE);
934
935 throw new NoSuchProductEntryException(msg.toString());
936 }
937 else {
938 return (SCProductEntry)list.get(0);
939 }
940 }
941
942 public SCProductEntry findByG_U_Last(long groupId, long userId,
943 OrderByComparator obc)
944 throws NoSuchProductEntryException, SystemException {
945 int count = countByG_U(groupId, userId);
946
947 List list = findByG_U(groupId, userId, count - 1, count, obc);
948
949 if (list.size() == 0) {
950 StringMaker msg = new StringMaker();
951
952 msg.append("No SCProductEntry exists with the key {");
953
954 msg.append("groupId=" + groupId);
955
956 msg.append(", ");
957 msg.append("userId=" + userId);
958
959 msg.append(StringPool.CLOSE_CURLY_BRACE);
960
961 throw new NoSuchProductEntryException(msg.toString());
962 }
963 else {
964 return (SCProductEntry)list.get(0);
965 }
966 }
967
968 public SCProductEntry[] findByG_U_PrevAndNext(long productEntryId,
969 long groupId, long userId, OrderByComparator obc)
970 throws NoSuchProductEntryException, SystemException {
971 SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
972
973 int count = countByG_U(groupId, userId);
974
975 Session session = null;
976
977 try {
978 session = openSession();
979
980 StringMaker query = new StringMaker();
981
982 query.append(
983 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
984
985 query.append("groupId = ?");
986
987 query.append(" AND ");
988
989 query.append("userId = ?");
990
991 query.append(" ");
992
993 if (obc != null) {
994 query.append("ORDER BY ");
995 query.append(obc.getOrderBy());
996 }
997
998 else {
999 query.append("ORDER BY ");
1000
1001 query.append("modifiedDate DESC, ");
1002 query.append("name DESC");
1003 }
1004
1005 Query q = session.createQuery(query.toString());
1006
1007 int queryPos = 0;
1008
1009 q.setLong(queryPos++, groupId);
1010
1011 q.setLong(queryPos++, userId);
1012
1013 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1014 scProductEntry);
1015
1016 SCProductEntry[] array = new SCProductEntryImpl[3];
1017
1018 array[0] = (SCProductEntry)objArray[0];
1019 array[1] = (SCProductEntry)objArray[1];
1020 array[2] = (SCProductEntry)objArray[2];
1021
1022 return array;
1023 }
1024 catch (Exception e) {
1025 throw HibernateUtil.processException(e);
1026 }
1027 finally {
1028 closeSession(session);
1029 }
1030 }
1031
1032 public SCProductEntry findByRG_RA(String repoGroupId, String repoArtifactId)
1033 throws NoSuchProductEntryException, SystemException {
1034 SCProductEntry scProductEntry = fetchByRG_RA(repoGroupId, repoArtifactId);
1035
1036 if (scProductEntry == null) {
1037 StringMaker msg = new StringMaker();
1038
1039 msg.append("No SCProductEntry exists with the key {");
1040
1041 msg.append("repoGroupId=" + repoGroupId);
1042
1043 msg.append(", ");
1044 msg.append("repoArtifactId=" + repoArtifactId);
1045
1046 msg.append(StringPool.CLOSE_CURLY_BRACE);
1047
1048 if (_log.isWarnEnabled()) {
1049 _log.warn(msg.toString());
1050 }
1051
1052 throw new NoSuchProductEntryException(msg.toString());
1053 }
1054
1055 return scProductEntry;
1056 }
1057
1058 public SCProductEntry fetchByRG_RA(String repoGroupId, String repoArtifactId)
1059 throws SystemException {
1060 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1061 String finderClassName = SCProductEntry.class.getName();
1062 String finderMethodName = "fetchByRG_RA";
1063 String[] finderParams = new String[] {
1064 String.class.getName(), String.class.getName()
1065 };
1066 Object[] finderArgs = new Object[] { repoGroupId, repoArtifactId };
1067
1068 Object result = null;
1069
1070 if (finderClassNameCacheEnabled) {
1071 result = FinderCache.getResult(finderClassName, finderMethodName,
1072 finderParams, finderArgs, getSessionFactory());
1073 }
1074
1075 if (result == null) {
1076 Session session = null;
1077
1078 try {
1079 session = openSession();
1080
1081 StringMaker query = new StringMaker();
1082
1083 query.append(
1084 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
1085
1086 if (repoGroupId == null) {
1087 query.append("repoGroupId IS NULL");
1088 }
1089 else {
1090 query.append("lower(repoGroupId) = ?");
1091 }
1092
1093 query.append(" AND ");
1094
1095 if (repoArtifactId == null) {
1096 query.append("repoArtifactId IS NULL");
1097 }
1098 else {
1099 query.append("lower(repoArtifactId) = ?");
1100 }
1101
1102 query.append(" ");
1103
1104 query.append("ORDER BY ");
1105
1106 query.append("modifiedDate DESC, ");
1107 query.append("name DESC");
1108
1109 Query q = session.createQuery(query.toString());
1110
1111 int queryPos = 0;
1112
1113 if (repoGroupId != null) {
1114 q.setString(queryPos++, repoGroupId);
1115 }
1116
1117 if (repoArtifactId != null) {
1118 q.setString(queryPos++, repoArtifactId);
1119 }
1120
1121 List list = q.list();
1122
1123 FinderCache.putResult(finderClassNameCacheEnabled,
1124 finderClassName, finderMethodName, finderParams,
1125 finderArgs, list);
1126
1127 if (list.size() == 0) {
1128 return null;
1129 }
1130 else {
1131 return (SCProductEntry)list.get(0);
1132 }
1133 }
1134 catch (Exception e) {
1135 throw HibernateUtil.processException(e);
1136 }
1137 finally {
1138 closeSession(session);
1139 }
1140 }
1141 else {
1142 List list = (List)result;
1143
1144 if (list.size() == 0) {
1145 return null;
1146 }
1147 else {
1148 return (SCProductEntry)list.get(0);
1149 }
1150 }
1151 }
1152
1153 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
1154 throws SystemException {
1155 Session session = null;
1156
1157 try {
1158 session = openSession();
1159
1160 DynamicQuery query = queryInitializer.initialize(session);
1161
1162 return query.list();
1163 }
1164 catch (Exception e) {
1165 throw HibernateUtil.processException(e);
1166 }
1167 finally {
1168 closeSession(session);
1169 }
1170 }
1171
1172 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
1173 int begin, int end) throws SystemException {
1174 Session session = null;
1175
1176 try {
1177 session = openSession();
1178
1179 DynamicQuery query = queryInitializer.initialize(session);
1180
1181 query.setLimit(begin, end);
1182
1183 return query.list();
1184 }
1185 catch (Exception e) {
1186 throw HibernateUtil.processException(e);
1187 }
1188 finally {
1189 closeSession(session);
1190 }
1191 }
1192
1193 public List findAll() throws SystemException {
1194 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1195 }
1196
1197 public List findAll(int begin, int end) throws SystemException {
1198 return findAll(begin, end, null);
1199 }
1200
1201 public List findAll(int begin, int end, OrderByComparator obc)
1202 throws SystemException {
1203 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1204 String finderClassName = SCProductEntry.class.getName();
1205 String finderMethodName = "findAll";
1206 String[] finderParams = new String[] {
1207 "java.lang.Integer", "java.lang.Integer",
1208 "com.liferay.portal.kernel.util.OrderByComparator"
1209 };
1210 Object[] finderArgs = new Object[] {
1211 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1212 };
1213
1214 Object result = null;
1215
1216 if (finderClassNameCacheEnabled) {
1217 result = FinderCache.getResult(finderClassName, finderMethodName,
1218 finderParams, finderArgs, getSessionFactory());
1219 }
1220
1221 if (result == null) {
1222 Session session = null;
1223
1224 try {
1225 session = openSession();
1226
1227 StringMaker query = new StringMaker();
1228
1229 query.append(
1230 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry ");
1231
1232 if (obc != null) {
1233 query.append("ORDER BY ");
1234 query.append(obc.getOrderBy());
1235 }
1236
1237 else {
1238 query.append("ORDER BY ");
1239
1240 query.append("modifiedDate DESC, ");
1241 query.append("name DESC");
1242 }
1243
1244 Query q = session.createQuery(query.toString());
1245
1246 List list = QueryUtil.list(q, getDialect(), begin, end);
1247
1248 if (obc == null) {
1249 Collections.sort(list);
1250 }
1251
1252 FinderCache.putResult(finderClassNameCacheEnabled,
1253 finderClassName, finderMethodName, finderParams,
1254 finderArgs, list);
1255
1256 return list;
1257 }
1258 catch (Exception e) {
1259 throw HibernateUtil.processException(e);
1260 }
1261 finally {
1262 closeSession(session);
1263 }
1264 }
1265 else {
1266 return (List)result;
1267 }
1268 }
1269
1270 public void removeByGroupId(long groupId) throws SystemException {
1271 Iterator itr = findByGroupId(groupId).iterator();
1272
1273 while (itr.hasNext()) {
1274 SCProductEntry scProductEntry = (SCProductEntry)itr.next();
1275
1276 remove(scProductEntry);
1277 }
1278 }
1279
1280 public void removeByCompanyId(long companyId) throws SystemException {
1281 Iterator itr = findByCompanyId(companyId).iterator();
1282
1283 while (itr.hasNext()) {
1284 SCProductEntry scProductEntry = (SCProductEntry)itr.next();
1285
1286 remove(scProductEntry);
1287 }
1288 }
1289
1290 public void removeByG_U(long groupId, long userId)
1291 throws SystemException {
1292 Iterator itr = findByG_U(groupId, userId).iterator();
1293
1294 while (itr.hasNext()) {
1295 SCProductEntry scProductEntry = (SCProductEntry)itr.next();
1296
1297 remove(scProductEntry);
1298 }
1299 }
1300
1301 public void removeByRG_RA(String repoGroupId, String repoArtifactId)
1302 throws NoSuchProductEntryException, SystemException {
1303 SCProductEntry scProductEntry = findByRG_RA(repoGroupId, repoArtifactId);
1304
1305 remove(scProductEntry);
1306 }
1307
1308 public void removeAll() throws SystemException {
1309 Iterator itr = findAll().iterator();
1310
1311 while (itr.hasNext()) {
1312 remove((SCProductEntry)itr.next());
1313 }
1314 }
1315
1316 public int countByGroupId(long groupId) throws SystemException {
1317 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1318 String finderClassName = SCProductEntry.class.getName();
1319 String finderMethodName = "countByGroupId";
1320 String[] finderParams = new String[] { Long.class.getName() };
1321 Object[] finderArgs = new Object[] { new Long(groupId) };
1322
1323 Object result = null;
1324
1325 if (finderClassNameCacheEnabled) {
1326 result = FinderCache.getResult(finderClassName, finderMethodName,
1327 finderParams, finderArgs, getSessionFactory());
1328 }
1329
1330 if (result == null) {
1331 Session session = null;
1332
1333 try {
1334 session = openSession();
1335
1336 StringMaker query = new StringMaker();
1337
1338 query.append("SELECT COUNT(*) ");
1339 query.append(
1340 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
1341
1342 query.append("groupId = ?");
1343
1344 query.append(" ");
1345
1346 Query q = session.createQuery(query.toString());
1347
1348 int queryPos = 0;
1349
1350 q.setLong(queryPos++, groupId);
1351
1352 Long count = null;
1353
1354 Iterator itr = q.list().iterator();
1355
1356 if (itr.hasNext()) {
1357 count = (Long)itr.next();
1358 }
1359
1360 if (count == null) {
1361 count = new Long(0);
1362 }
1363
1364 FinderCache.putResult(finderClassNameCacheEnabled,
1365 finderClassName, finderMethodName, finderParams,
1366 finderArgs, count);
1367
1368 return count.intValue();
1369 }
1370 catch (Exception e) {
1371 throw HibernateUtil.processException(e);
1372 }
1373 finally {
1374 closeSession(session);
1375 }
1376 }
1377 else {
1378 return ((Long)result).intValue();
1379 }
1380 }
1381
1382 public int countByCompanyId(long companyId) throws SystemException {
1383 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1384 String finderClassName = SCProductEntry.class.getName();
1385 String finderMethodName = "countByCompanyId";
1386 String[] finderParams = new String[] { Long.class.getName() };
1387 Object[] finderArgs = new Object[] { new Long(companyId) };
1388
1389 Object result = null;
1390
1391 if (finderClassNameCacheEnabled) {
1392 result = FinderCache.getResult(finderClassName, finderMethodName,
1393 finderParams, finderArgs, getSessionFactory());
1394 }
1395
1396 if (result == null) {
1397 Session session = null;
1398
1399 try {
1400 session = openSession();
1401
1402 StringMaker query = new StringMaker();
1403
1404 query.append("SELECT COUNT(*) ");
1405 query.append(
1406 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
1407
1408 query.append("companyId = ?");
1409
1410 query.append(" ");
1411
1412 Query q = session.createQuery(query.toString());
1413
1414 int queryPos = 0;
1415
1416 q.setLong(queryPos++, companyId);
1417
1418 Long count = null;
1419
1420 Iterator itr = q.list().iterator();
1421
1422 if (itr.hasNext()) {
1423 count = (Long)itr.next();
1424 }
1425
1426 if (count == null) {
1427 count = new Long(0);
1428 }
1429
1430 FinderCache.putResult(finderClassNameCacheEnabled,
1431 finderClassName, finderMethodName, finderParams,
1432 finderArgs, count);
1433
1434 return count.intValue();
1435 }
1436 catch (Exception e) {
1437 throw HibernateUtil.processException(e);
1438 }
1439 finally {
1440 closeSession(session);
1441 }
1442 }
1443 else {
1444 return ((Long)result).intValue();
1445 }
1446 }
1447
1448 public int countByG_U(long groupId, long userId) throws SystemException {
1449 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1450 String finderClassName = SCProductEntry.class.getName();
1451 String finderMethodName = "countByG_U";
1452 String[] finderParams = new String[] {
1453 Long.class.getName(), Long.class.getName()
1454 };
1455 Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1456
1457 Object result = null;
1458
1459 if (finderClassNameCacheEnabled) {
1460 result = FinderCache.getResult(finderClassName, finderMethodName,
1461 finderParams, finderArgs, getSessionFactory());
1462 }
1463
1464 if (result == null) {
1465 Session session = null;
1466
1467 try {
1468 session = openSession();
1469
1470 StringMaker query = new StringMaker();
1471
1472 query.append("SELECT COUNT(*) ");
1473 query.append(
1474 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
1475
1476 query.append("groupId = ?");
1477
1478 query.append(" AND ");
1479
1480 query.append("userId = ?");
1481
1482 query.append(" ");
1483
1484 Query q = session.createQuery(query.toString());
1485
1486 int queryPos = 0;
1487
1488 q.setLong(queryPos++, groupId);
1489
1490 q.setLong(queryPos++, userId);
1491
1492 Long count = null;
1493
1494 Iterator itr = q.list().iterator();
1495
1496 if (itr.hasNext()) {
1497 count = (Long)itr.next();
1498 }
1499
1500 if (count == null) {
1501 count = new Long(0);
1502 }
1503
1504 FinderCache.putResult(finderClassNameCacheEnabled,
1505 finderClassName, finderMethodName, finderParams,
1506 finderArgs, count);
1507
1508 return count.intValue();
1509 }
1510 catch (Exception e) {
1511 throw HibernateUtil.processException(e);
1512 }
1513 finally {
1514 closeSession(session);
1515 }
1516 }
1517 else {
1518 return ((Long)result).intValue();
1519 }
1520 }
1521
1522 public int countByRG_RA(String repoGroupId, String repoArtifactId)
1523 throws SystemException {
1524 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1525 String finderClassName = SCProductEntry.class.getName();
1526 String finderMethodName = "countByRG_RA";
1527 String[] finderParams = new String[] {
1528 String.class.getName(), String.class.getName()
1529 };
1530 Object[] finderArgs = new Object[] { repoGroupId, repoArtifactId };
1531
1532 Object result = null;
1533
1534 if (finderClassNameCacheEnabled) {
1535 result = FinderCache.getResult(finderClassName, finderMethodName,
1536 finderParams, finderArgs, getSessionFactory());
1537 }
1538
1539 if (result == null) {
1540 Session session = null;
1541
1542 try {
1543 session = openSession();
1544
1545 StringMaker query = new StringMaker();
1546
1547 query.append("SELECT COUNT(*) ");
1548 query.append(
1549 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
1550
1551 if (repoGroupId == null) {
1552 query.append("repoGroupId IS NULL");
1553 }
1554 else {
1555 query.append("lower(repoGroupId) = ?");
1556 }
1557
1558 query.append(" AND ");
1559
1560 if (repoArtifactId == null) {
1561 query.append("repoArtifactId IS NULL");
1562 }
1563 else {
1564 query.append("lower(repoArtifactId) = ?");
1565 }
1566
1567 query.append(" ");
1568
1569 Query q = session.createQuery(query.toString());
1570
1571 int queryPos = 0;
1572
1573 if (repoGroupId != null) {
1574 q.setString(queryPos++, repoGroupId);
1575 }
1576
1577 if (repoArtifactId != null) {
1578 q.setString(queryPos++, repoArtifactId);
1579 }
1580
1581 Long count = null;
1582
1583 Iterator itr = q.list().iterator();
1584
1585 if (itr.hasNext()) {
1586 count = (Long)itr.next();
1587 }
1588
1589 if (count == null) {
1590 count = new Long(0);
1591 }
1592
1593 FinderCache.putResult(finderClassNameCacheEnabled,
1594 finderClassName, finderMethodName, finderParams,
1595 finderArgs, count);
1596
1597 return count.intValue();
1598 }
1599 catch (Exception e) {
1600 throw HibernateUtil.processException(e);
1601 }
1602 finally {
1603 closeSession(session);
1604 }
1605 }
1606 else {
1607 return ((Long)result).intValue();
1608 }
1609 }
1610
1611 public int countAll() throws SystemException {
1612 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1613 String finderClassName = SCProductEntry.class.getName();
1614 String finderMethodName = "countAll";
1615 String[] finderParams = new String[] { };
1616 Object[] finderArgs = new Object[] { };
1617
1618 Object result = null;
1619
1620 if (finderClassNameCacheEnabled) {
1621 result = FinderCache.getResult(finderClassName, finderMethodName,
1622 finderParams, finderArgs, getSessionFactory());
1623 }
1624
1625 if (result == null) {
1626 Session session = null;
1627
1628 try {
1629 session = openSession();
1630
1631 Query q = session.createQuery(
1632 "SELECT COUNT(*) FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry");
1633
1634 Long count = null;
1635
1636 Iterator itr = q.list().iterator();
1637
1638 if (itr.hasNext()) {
1639 count = (Long)itr.next();
1640 }
1641
1642 if (count == null) {
1643 count = new Long(0);
1644 }
1645
1646 FinderCache.putResult(finderClassNameCacheEnabled,
1647 finderClassName, finderMethodName, finderParams,
1648 finderArgs, count);
1649
1650 return count.intValue();
1651 }
1652 catch (Exception e) {
1653 throw HibernateUtil.processException(e);
1654 }
1655 finally {
1656 closeSession(session);
1657 }
1658 }
1659 else {
1660 return ((Long)result).intValue();
1661 }
1662 }
1663
1664 public List getSCLicenses(long pk)
1665 throws NoSuchProductEntryException, SystemException {
1666 return getSCLicenses(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1667 }
1668
1669 public List getSCLicenses(long pk, int begin, int end)
1670 throws NoSuchProductEntryException, SystemException {
1671 return getSCLicenses(pk, begin, end, null);
1672 }
1673
1674 public List getSCLicenses(long pk, int begin, int end, OrderByComparator obc)
1675 throws NoSuchProductEntryException, SystemException {
1676 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES;
1677 String finderClassName = "SCLicenses_SCProductEntries";
1678 String finderMethodName = "getSCLicenses";
1679 String[] finderParams = new String[] {
1680 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1681 "com.liferay.portal.kernel.util.OrderByComparator"
1682 };
1683 Object[] finderArgs = new Object[] {
1684 new Long(pk), String.valueOf(begin), String.valueOf(end),
1685 String.valueOf(obc)
1686 };
1687
1688 Object result = null;
1689
1690 if (finderClassNameCacheEnabled) {
1691 result = FinderCache.getResult(finderClassName, finderMethodName,
1692 finderParams, finderArgs, getSessionFactory());
1693 }
1694
1695 if (result == null) {
1696 Session session = null;
1697
1698 try {
1699 session = HibernateUtil.openSession();
1700
1701 StringMaker sm = new StringMaker();
1702
1703 sm.append(_SQL_GETSCLICENSES);
1704
1705 if (obc != null) {
1706 sm.append("ORDER BY ");
1707 sm.append(obc.getOrderBy());
1708 }
1709
1710 else {
1711 sm.append("ORDER BY ");
1712
1713 sm.append("SCLicense.name ASC");
1714 }
1715
1716 String sql = sm.toString();
1717
1718 SQLQuery q = session.createSQLQuery(sql);
1719
1720 q.addEntity("SCLicense",
1721 com.liferay.portlet.softwarecatalog.model.impl.SCLicenseImpl.class);
1722
1723 QueryPos qPos = QueryPos.getInstance(q);
1724
1725 qPos.add(pk);
1726
1727 List list = QueryUtil.list(q, getDialect(), begin, end);
1728
1729 FinderCache.putResult(finderClassNameCacheEnabled,
1730 finderClassName, finderMethodName, finderParams,
1731 finderArgs, list);
1732
1733 return list;
1734 }
1735 catch (Exception e) {
1736 throw new SystemException(e);
1737 }
1738 finally {
1739 closeSession(session);
1740 }
1741 }
1742 else {
1743 return (List)result;
1744 }
1745 }
1746
1747 public int getSCLicensesSize(long pk) throws SystemException {
1748 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES;
1749 String finderClassName = "SCLicenses_SCProductEntries";
1750 String finderMethodName = "getSCLicensesSize";
1751 String[] finderParams = new String[] { Long.class.getName() };
1752 Object[] finderArgs = new Object[] { new Long(pk) };
1753
1754 Object result = null;
1755
1756 if (finderClassNameCacheEnabled) {
1757 result = FinderCache.getResult(finderClassName, finderMethodName,
1758 finderParams, finderArgs, getSessionFactory());
1759 }
1760
1761 if (result == null) {
1762 Session session = null;
1763
1764 try {
1765 session = openSession();
1766
1767 SQLQuery q = session.createSQLQuery(_SQL_GETSCLICENSESSIZE);
1768
1769 q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
1770
1771 QueryPos qPos = QueryPos.getInstance(q);
1772
1773 qPos.add(pk);
1774
1775 Long count = null;
1776
1777 Iterator itr = q.list().iterator();
1778
1779 if (itr.hasNext()) {
1780 count = (Long)itr.next();
1781 }
1782
1783 if (count == null) {
1784 count = new Long(0);
1785 }
1786
1787 FinderCache.putResult(finderClassNameCacheEnabled,
1788 finderClassName, finderMethodName, finderParams,
1789 finderArgs, count);
1790
1791 return count.intValue();
1792 }
1793 catch (Exception e) {
1794 throw HibernateUtil.processException(e);
1795 }
1796 finally {
1797 closeSession(session);
1798 }
1799 }
1800 else {
1801 return ((Long)result).intValue();
1802 }
1803 }
1804
1805 public boolean containsSCLicense(long pk, long scLicensePK)
1806 throws SystemException {
1807 boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES;
1808 String finderClassName = "SCLicenses_SCProductEntries";
1809 String finderMethodName = "containsSCLicenses";
1810 String[] finderParams = new String[] {
1811 Long.class.getName(),
1812
1813 Long.class.getName()
1814 };
1815 Object[] finderArgs = new Object[] { new Long(pk), new Long(scLicensePK) };
1816
1817 Object result = null;
1818
1819 if (finderClassNameCacheEnabled) {
1820 result = FinderCache.getResult(finderClassName, finderMethodName,
1821 finderParams, finderArgs, getSessionFactory());
1822 }
1823
1824 if (result == null) {
1825 try {
1826 Boolean value = Boolean.valueOf(containsSCLicense.contains(pk,
1827 scLicensePK));
1828
1829 FinderCache.putResult(finderClassNameCacheEnabled,
1830 finderClassName, finderMethodName, finderParams,
1831 finderArgs, value);
1832
1833 return value.booleanValue();
1834 }
1835 catch (DataAccessException dae) {
1836 throw new SystemException(dae);
1837 }
1838 }
1839 else {
1840 return ((Boolean)result).booleanValue();
1841 }
1842 }
1843
1844 public boolean containsSCLicenses(long pk) throws SystemException {
1845 if (getSCLicensesSize(pk) > 0) {
1846 return true;
1847 }
1848 else {
1849 return false;
1850 }
1851 }
1852
1853 public void addSCLicense(long pk, long scLicensePK)
1854 throws NoSuchProductEntryException,
1855 com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
1856 SystemException {
1857 try {
1858 addSCLicense.add(pk, scLicensePK);
1859 }
1860 catch (DataAccessException dae) {
1861 throw new SystemException(dae);
1862 }
1863 finally {
1864 FinderCache.clearCache("SCLicenses_SCProductEntries");
1865 }
1866 }
1867
1868 public void addSCLicense(long pk,
1869 com.liferay.portlet.softwarecatalog.model.SCLicense scLicense)
1870 throws NoSuchProductEntryException,
1871 com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
1872 SystemException {
1873 try {
1874 addSCLicense.add(pk, scLicense.getPrimaryKey());
1875 }
1876 catch (DataAccessException dae) {
1877 throw new SystemException(dae);
1878 }
1879 finally {
1880 FinderCache.clearCache("SCLicenses_SCProductEntries");
1881 }
1882 }
1883
1884 public void addSCLicenses(long pk, long[] scLicensePKs)
1885 throws NoSuchProductEntryException,
1886 com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
1887 SystemException {
1888 try {
1889 for (int i = 0; i < scLicensePKs.length; i++) {
1890 addSCLicense.add(pk, scLicensePKs[i]);
1891 }
1892 }
1893 catch (DataAccessException dae) {
1894 throw new SystemException(dae);
1895 }
1896 finally {
1897 FinderCache.clearCache("SCLicenses_SCProductEntries");
1898 }
1899 }
1900
1901 public void addSCLicenses(long pk, List scLicenses)
1902 throws NoSuchProductEntryException,
1903 com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
1904 SystemException {
1905 try {
1906 for (int i = 0; i < scLicenses.size(); i++) {
1907 com.liferay.portlet.softwarecatalog.model.SCLicense scLicense = (com.liferay.portlet.softwarecatalog.model.SCLicense)scLicenses.get(i);
1908
1909 addSCLicense.add(pk, scLicense.getPrimaryKey());
1910 }
1911 }
1912 catch (DataAccessException dae) {
1913 throw new SystemException(dae);
1914 }
1915 finally {
1916 FinderCache.clearCache("SCLicenses_SCProductEntries");
1917 }
1918 }
1919
1920 public void clearSCLicenses(long pk)
1921 throws NoSuchProductEntryException, SystemException {
1922 try {
1923 clearSCLicenses.clear(pk);
1924 }
1925 catch (DataAccessException dae) {
1926 throw new SystemException(dae);
1927 }
1928 finally {
1929 FinderCache.clearCache("SCLicenses_SCProductEntries");
1930 }
1931 }
1932
1933 public void removeSCLicense(long pk, long scLicensePK)
1934 throws NoSuchProductEntryException,
1935 com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
1936 SystemException {
1937 try {
1938 removeSCLicense.remove(pk, scLicensePK);
1939 }
1940 catch (DataAccessException dae) {
1941 throw new SystemException(dae);
1942 }
1943 finally {
1944 FinderCache.clearCache("SCLicenses_SCProductEntries");
1945 }
1946 }
1947
1948 public void removeSCLicense(long pk,
1949 com.liferay.portlet.softwarecatalog.model.SCLicense scLicense)
1950 throws NoSuchProductEntryException,
1951 com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
1952 SystemException {
1953 try {
1954 removeSCLicense.remove(pk, scLicense.getPrimaryKey());
1955 }
1956 catch (DataAccessException dae) {
1957 throw new SystemException(dae);
1958 }
1959 finally {
1960 FinderCache.clearCache("SCLicenses_SCProductEntries");
1961 }
1962 }
1963
1964 public void removeSCLicenses(long pk, long[] scLicensePKs)
1965 throws NoSuchProductEntryException,
1966 com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
1967 SystemException {
1968 try {
1969 for (int i = 0; i < scLicensePKs.length; i++) {
1970 removeSCLicense.remove(pk, scLicensePKs[i]);
1971 }
1972 }
1973 catch (DataAccessException dae) {
1974 throw new SystemException(dae);
1975 }
1976 finally {
1977 FinderCache.clearCache("SCLicenses_SCProductEntries");
1978 }
1979 }
1980
1981 public void removeSCLicenses(long pk, List scLicenses)
1982 throws NoSuchProductEntryException,
1983 com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
1984 SystemException {
1985 try {
1986 for (int i = 0; i < scLicenses.size(); i++) {
1987 com.liferay.portlet.softwarecatalog.model.SCLicense scLicense = (com.liferay.portlet.softwarecatalog.model.SCLicense)scLicenses.get(i);
1988
1989 removeSCLicense.remove(pk, scLicense.getPrimaryKey());
1990 }
1991 }
1992 catch (DataAccessException dae) {
1993 throw new SystemException(dae);
1994 }
1995 finally {
1996 FinderCache.clearCache("SCLicenses_SCProductEntries");
1997 }
1998 }
1999
2000 public void setSCLicenses(long pk, long[] scLicensePKs)
2001 throws NoSuchProductEntryException,
2002 com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
2003 SystemException {
2004 try {
2005 clearSCLicenses.clear(pk);
2006
2007 for (int i = 0; i < scLicensePKs.length; i++) {
2008 addSCLicense.add(pk, scLicensePKs[i]);
2009 }
2010 }
2011 catch (DataAccessException dae) {
2012 throw new SystemException(dae);
2013 }
2014 finally {
2015 FinderCache.clearCache("SCLicenses_SCProductEntries");
2016 }
2017 }
2018
2019 public void setSCLicenses(long pk, List scLicenses)
2020 throws NoSuchProductEntryException,
2021 com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
2022 SystemException {
2023 try {
2024 clearSCLicenses.clear(pk);
2025
2026 for (int i = 0; i < scLicenses.size(); i++) {
2027 com.liferay.portlet.softwarecatalog.model.SCLicense scLicense = (com.liferay.portlet.softwarecatalog.model.SCLicense)scLicenses.get(i);
2028
2029 addSCLicense.add(pk, scLicense.getPrimaryKey());
2030 }
2031 }
2032 catch (DataAccessException dae) {
2033 throw new SystemException(dae);
2034 }
2035 finally {
2036 FinderCache.clearCache("SCLicenses_SCProductEntries");
2037 }
2038 }
2039
2040 protected void initDao() {
2041 containsSCLicense = new ContainsSCLicense(this);
2042
2043 addSCLicense = new AddSCLicense(this);
2044 clearSCLicenses = new ClearSCLicenses(this);
2045 removeSCLicense = new RemoveSCLicense(this);
2046 }
2047
2048 protected ContainsSCLicense containsSCLicense;
2049 protected AddSCLicense addSCLicense;
2050 protected ClearSCLicenses clearSCLicenses;
2051 protected RemoveSCLicense removeSCLicense;
2052
2053 protected class ContainsSCLicense extends MappingSqlQuery {
2054 protected ContainsSCLicense(
2055 SCProductEntryPersistenceImpl persistenceImpl) {
2056 super(persistenceImpl.getDataSource(), _SQL_CONTAINSSCLICENSE);
2057
2058 declareParameter(new SqlParameter(Types.BIGINT));
2059 declareParameter(new SqlParameter(Types.BIGINT));
2060
2061 compile();
2062 }
2063
2064 protected Object mapRow(ResultSet rs, int rowNumber)
2065 throws SQLException {
2066 return new Integer(rs.getInt("COUNT_VALUE"));
2067 }
2068
2069 protected boolean contains(long productEntryId, long licenseId) {
2070 List results = execute(new Object[] {
2071 new Long(productEntryId), new Long(licenseId)
2072 });
2073
2074 if (results.size() > 0) {
2075 Integer count = (Integer)results.get(0);
2076
2077 if (count.intValue() > 0) {
2078 return true;
2079 }
2080 }
2081
2082 return false;
2083 }
2084 }
2085
2086 protected class AddSCLicense extends SqlUpdate {
2087 protected AddSCLicense(SCProductEntryPersistenceImpl persistenceImpl) {
2088 super(persistenceImpl.getDataSource(),
2089 "INSERT INTO SCLicenses_SCProductEntries (productEntryId, licenseId) VALUES (?, ?)");
2090
2091 _persistenceImpl = persistenceImpl;
2092
2093 declareParameter(new SqlParameter(Types.BIGINT));
2094 declareParameter(new SqlParameter(Types.BIGINT));
2095
2096 compile();
2097 }
2098
2099 protected void add(long productEntryId, long licenseId) {
2100 if (!_persistenceImpl.containsSCLicense.contains(productEntryId,
2101 licenseId)) {
2102 update(new Object[] {
2103 new Long(productEntryId), new Long(licenseId)
2104 });
2105 }
2106 }
2107
2108 private SCProductEntryPersistenceImpl _persistenceImpl;
2109 }
2110
2111 protected class ClearSCLicenses extends SqlUpdate {
2112 protected ClearSCLicenses(SCProductEntryPersistenceImpl persistenceImpl) {
2113 super(persistenceImpl.getDataSource(),
2114 "DELETE FROM SCLicenses_SCProductEntries WHERE productEntryId = ?");
2115
2116 declareParameter(new SqlParameter(Types.BIGINT));
2117
2118 compile();
2119 }
2120
2121 protected void clear(long productEntryId) {
2122 update(new Object[] { new Long(productEntryId) });
2123 }
2124 }
2125
2126 protected class RemoveSCLicense extends SqlUpdate {
2127 protected RemoveSCLicense(SCProductEntryPersistenceImpl persistenceImpl) {
2128 super(persistenceImpl.getDataSource(),
2129 "DELETE FROM SCLicenses_SCProductEntries WHERE productEntryId = ? AND licenseId = ?");
2130
2131 declareParameter(new SqlParameter(Types.BIGINT));
2132 declareParameter(new SqlParameter(Types.BIGINT));
2133
2134 compile();
2135 }
2136
2137 protected void remove(long productEntryId, long licenseId) {
2138 update(new Object[] { new Long(productEntryId), new Long(licenseId) });
2139 }
2140 }
2141
2142 private static ModelListener _getListener() {
2143 if (Validator.isNotNull(_LISTENER)) {
2144 try {
2145 return (ModelListener)Class.forName(_LISTENER).newInstance();
2146 }
2147 catch (Exception e) {
2148 _log.error(e);
2149 }
2150 }
2151
2152 return null;
2153 }
2154
2155 private static final String _SQL_GETSCLICENSES = "SELECT {SCLicense.*} FROM SCLicense INNER JOIN SCLicenses_SCProductEntries ON (SCLicenses_SCProductEntries.licenseId = SCLicense.licenseId) WHERE (SCLicenses_SCProductEntries.productEntryId = ?)";
2156 private static final String _SQL_GETSCLICENSESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE productEntryId = ?";
2157 private static final String _SQL_CONTAINSSCLICENSE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE productEntryId = ? AND licenseId = ?";
2158 private static final String _LISTENER = GetterUtil.getString(PropsUtil.get(
2159 "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCProductEntry"));
2160 private static Log _log = LogFactory.getLog(SCProductEntryPersistenceImpl.class);
2161}