001
014
015 package com.liferay.portlet.softwarecatalog.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.SQLQuery;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.SetUtil;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.Validator;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
038 import com.liferay.portal.service.ServiceContext;
039 import com.liferay.portal.service.ServiceContextThreadLocal;
040 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041 import com.liferay.portal.service.persistence.impl.TableMapper;
042 import com.liferay.portal.service.persistence.impl.TableMapperFactory;
043
044 import com.liferay.portlet.softwarecatalog.NoSuchProductEntryException;
045 import com.liferay.portlet.softwarecatalog.model.SCProductEntry;
046 import com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryImpl;
047 import com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryModelImpl;
048 import com.liferay.portlet.softwarecatalog.service.persistence.SCLicensePersistence;
049 import com.liferay.portlet.softwarecatalog.service.persistence.SCProductEntryPersistence;
050
051 import java.io.Serializable;
052
053 import java.util.Collections;
054 import java.util.Date;
055 import java.util.HashMap;
056 import java.util.HashSet;
057 import java.util.Iterator;
058 import java.util.List;
059 import java.util.Map;
060 import java.util.Set;
061
062
074 @ProviderType
075 public class SCProductEntryPersistenceImpl extends BasePersistenceImpl<SCProductEntry>
076 implements SCProductEntryPersistence {
077
082 public static final String FINDER_CLASS_NAME_ENTITY = SCProductEntryImpl.class.getName();
083 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List1";
085 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086 ".List2";
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
088 SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
089 SCProductEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
090 "findAll", new String[0]);
091 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
092 SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
093 SCProductEntryImpl.class,
094 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
095 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
096 SCProductEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
098 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
099 SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
100 SCProductEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
101 "findByGroupId",
102 new String[] {
103 Long.class.getName(),
104
105 Integer.class.getName(), Integer.class.getName(),
106 OrderByComparator.class.getName()
107 });
108 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
109 new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
110 SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
111 SCProductEntryImpl.class,
112 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
113 new String[] { Long.class.getName() },
114 SCProductEntryModelImpl.GROUPID_COLUMN_BITMASK |
115 SCProductEntryModelImpl.MODIFIEDDATE_COLUMN_BITMASK |
116 SCProductEntryModelImpl.NAME_COLUMN_BITMASK);
117 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
118 SCProductEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
119 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
120 new String[] { Long.class.getName() });
121
122
128 @Override
129 public List<SCProductEntry> findByGroupId(long groupId) {
130 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
131 }
132
133
145 @Override
146 public List<SCProductEntry> findByGroupId(long groupId, int start, int end) {
147 return findByGroupId(groupId, start, end, null);
148 }
149
150
163 @Override
164 public List<SCProductEntry> findByGroupId(long groupId, int start, int end,
165 OrderByComparator<SCProductEntry> orderByComparator) {
166 boolean pagination = true;
167 FinderPath finderPath = null;
168 Object[] finderArgs = null;
169
170 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
171 (orderByComparator == null)) {
172 pagination = false;
173 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
174 finderArgs = new Object[] { groupId };
175 }
176 else {
177 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
178 finderArgs = new Object[] { groupId, start, end, orderByComparator };
179 }
180
181 List<SCProductEntry> list = (List<SCProductEntry>)FinderCacheUtil.getResult(finderPath,
182 finderArgs, this);
183
184 if ((list != null) && !list.isEmpty()) {
185 for (SCProductEntry scProductEntry : list) {
186 if ((groupId != scProductEntry.getGroupId())) {
187 list = null;
188
189 break;
190 }
191 }
192 }
193
194 if (list == null) {
195 StringBundler query = null;
196
197 if (orderByComparator != null) {
198 query = new StringBundler(3 +
199 (orderByComparator.getOrderByFields().length * 3));
200 }
201 else {
202 query = new StringBundler(3);
203 }
204
205 query.append(_SQL_SELECT_SCPRODUCTENTRY_WHERE);
206
207 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
208
209 if (orderByComparator != null) {
210 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
211 orderByComparator);
212 }
213 else
214 if (pagination) {
215 query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
216 }
217
218 String sql = query.toString();
219
220 Session session = null;
221
222 try {
223 session = openSession();
224
225 Query q = session.createQuery(sql);
226
227 QueryPos qPos = QueryPos.getInstance(q);
228
229 qPos.add(groupId);
230
231 if (!pagination) {
232 list = (List<SCProductEntry>)QueryUtil.list(q,
233 getDialect(), start, end, false);
234
235 Collections.sort(list);
236
237 list = Collections.unmodifiableList(list);
238 }
239 else {
240 list = (List<SCProductEntry>)QueryUtil.list(q,
241 getDialect(), start, end);
242 }
243
244 cacheResult(list);
245
246 FinderCacheUtil.putResult(finderPath, finderArgs, list);
247 }
248 catch (Exception e) {
249 FinderCacheUtil.removeResult(finderPath, finderArgs);
250
251 throw processException(e);
252 }
253 finally {
254 closeSession(session);
255 }
256 }
257
258 return list;
259 }
260
261
269 @Override
270 public SCProductEntry findByGroupId_First(long groupId,
271 OrderByComparator<SCProductEntry> orderByComparator)
272 throws NoSuchProductEntryException {
273 SCProductEntry scProductEntry = fetchByGroupId_First(groupId,
274 orderByComparator);
275
276 if (scProductEntry != null) {
277 return scProductEntry;
278 }
279
280 StringBundler msg = new StringBundler(4);
281
282 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
283
284 msg.append("groupId=");
285 msg.append(groupId);
286
287 msg.append(StringPool.CLOSE_CURLY_BRACE);
288
289 throw new NoSuchProductEntryException(msg.toString());
290 }
291
292
299 @Override
300 public SCProductEntry fetchByGroupId_First(long groupId,
301 OrderByComparator<SCProductEntry> orderByComparator) {
302 List<SCProductEntry> list = findByGroupId(groupId, 0, 1,
303 orderByComparator);
304
305 if (!list.isEmpty()) {
306 return list.get(0);
307 }
308
309 return null;
310 }
311
312
320 @Override
321 public SCProductEntry findByGroupId_Last(long groupId,
322 OrderByComparator<SCProductEntry> orderByComparator)
323 throws NoSuchProductEntryException {
324 SCProductEntry scProductEntry = fetchByGroupId_Last(groupId,
325 orderByComparator);
326
327 if (scProductEntry != null) {
328 return scProductEntry;
329 }
330
331 StringBundler msg = new StringBundler(4);
332
333 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
334
335 msg.append("groupId=");
336 msg.append(groupId);
337
338 msg.append(StringPool.CLOSE_CURLY_BRACE);
339
340 throw new NoSuchProductEntryException(msg.toString());
341 }
342
343
350 @Override
351 public SCProductEntry fetchByGroupId_Last(long groupId,
352 OrderByComparator<SCProductEntry> orderByComparator) {
353 int count = countByGroupId(groupId);
354
355 if (count == 0) {
356 return null;
357 }
358
359 List<SCProductEntry> list = findByGroupId(groupId, count - 1, count,
360 orderByComparator);
361
362 if (!list.isEmpty()) {
363 return list.get(0);
364 }
365
366 return null;
367 }
368
369
378 @Override
379 public SCProductEntry[] findByGroupId_PrevAndNext(long productEntryId,
380 long groupId, OrderByComparator<SCProductEntry> orderByComparator)
381 throws NoSuchProductEntryException {
382 SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
383
384 Session session = null;
385
386 try {
387 session = openSession();
388
389 SCProductEntry[] array = new SCProductEntryImpl[3];
390
391 array[0] = getByGroupId_PrevAndNext(session, scProductEntry,
392 groupId, orderByComparator, true);
393
394 array[1] = scProductEntry;
395
396 array[2] = getByGroupId_PrevAndNext(session, scProductEntry,
397 groupId, orderByComparator, false);
398
399 return array;
400 }
401 catch (Exception e) {
402 throw processException(e);
403 }
404 finally {
405 closeSession(session);
406 }
407 }
408
409 protected SCProductEntry getByGroupId_PrevAndNext(Session session,
410 SCProductEntry scProductEntry, long groupId,
411 OrderByComparator<SCProductEntry> orderByComparator, boolean previous) {
412 StringBundler query = null;
413
414 if (orderByComparator != null) {
415 query = new StringBundler(6 +
416 (orderByComparator.getOrderByFields().length * 6));
417 }
418 else {
419 query = new StringBundler(3);
420 }
421
422 query.append(_SQL_SELECT_SCPRODUCTENTRY_WHERE);
423
424 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
425
426 if (orderByComparator != null) {
427 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
428
429 if (orderByConditionFields.length > 0) {
430 query.append(WHERE_AND);
431 }
432
433 for (int i = 0; i < orderByConditionFields.length; i++) {
434 query.append(_ORDER_BY_ENTITY_ALIAS);
435 query.append(orderByConditionFields[i]);
436
437 if ((i + 1) < orderByConditionFields.length) {
438 if (orderByComparator.isAscending() ^ previous) {
439 query.append(WHERE_GREATER_THAN_HAS_NEXT);
440 }
441 else {
442 query.append(WHERE_LESSER_THAN_HAS_NEXT);
443 }
444 }
445 else {
446 if (orderByComparator.isAscending() ^ previous) {
447 query.append(WHERE_GREATER_THAN);
448 }
449 else {
450 query.append(WHERE_LESSER_THAN);
451 }
452 }
453 }
454
455 query.append(ORDER_BY_CLAUSE);
456
457 String[] orderByFields = orderByComparator.getOrderByFields();
458
459 for (int i = 0; i < orderByFields.length; i++) {
460 query.append(_ORDER_BY_ENTITY_ALIAS);
461 query.append(orderByFields[i]);
462
463 if ((i + 1) < orderByFields.length) {
464 if (orderByComparator.isAscending() ^ previous) {
465 query.append(ORDER_BY_ASC_HAS_NEXT);
466 }
467 else {
468 query.append(ORDER_BY_DESC_HAS_NEXT);
469 }
470 }
471 else {
472 if (orderByComparator.isAscending() ^ previous) {
473 query.append(ORDER_BY_ASC);
474 }
475 else {
476 query.append(ORDER_BY_DESC);
477 }
478 }
479 }
480 }
481 else {
482 query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
483 }
484
485 String sql = query.toString();
486
487 Query q = session.createQuery(sql);
488
489 q.setFirstResult(0);
490 q.setMaxResults(2);
491
492 QueryPos qPos = QueryPos.getInstance(q);
493
494 qPos.add(groupId);
495
496 if (orderByComparator != null) {
497 Object[] values = orderByComparator.getOrderByConditionValues(scProductEntry);
498
499 for (Object value : values) {
500 qPos.add(value);
501 }
502 }
503
504 List<SCProductEntry> list = q.list();
505
506 if (list.size() == 2) {
507 return list.get(1);
508 }
509 else {
510 return null;
511 }
512 }
513
514
520 @Override
521 public List<SCProductEntry> filterFindByGroupId(long groupId) {
522 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
523 QueryUtil.ALL_POS, null);
524 }
525
526
538 @Override
539 public List<SCProductEntry> filterFindByGroupId(long groupId, int start,
540 int end) {
541 return filterFindByGroupId(groupId, start, end, null);
542 }
543
544
557 @Override
558 public List<SCProductEntry> filterFindByGroupId(long groupId, int start,
559 int end, OrderByComparator<SCProductEntry> orderByComparator) {
560 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
561 return findByGroupId(groupId, start, end, orderByComparator);
562 }
563
564 StringBundler query = null;
565
566 if (orderByComparator != null) {
567 query = new StringBundler(3 +
568 (orderByComparator.getOrderByFields().length * 3));
569 }
570 else {
571 query = new StringBundler(3);
572 }
573
574 if (getDB().isSupportsInlineDistinct()) {
575 query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_WHERE);
576 }
577 else {
578 query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_1);
579 }
580
581 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
582
583 if (!getDB().isSupportsInlineDistinct()) {
584 query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_2);
585 }
586
587 if (orderByComparator != null) {
588 if (getDB().isSupportsInlineDistinct()) {
589 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
590 orderByComparator, true);
591 }
592 else {
593 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
594 orderByComparator, true);
595 }
596 }
597 else {
598 if (getDB().isSupportsInlineDistinct()) {
599 query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
600 }
601 else {
602 query.append(SCProductEntryModelImpl.ORDER_BY_SQL);
603 }
604 }
605
606 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
607 SCProductEntry.class.getName(),
608 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
609
610 Session session = null;
611
612 try {
613 session = openSession();
614
615 SQLQuery q = session.createSynchronizedSQLQuery(sql);
616
617 if (getDB().isSupportsInlineDistinct()) {
618 q.addEntity(_FILTER_ENTITY_ALIAS, SCProductEntryImpl.class);
619 }
620 else {
621 q.addEntity(_FILTER_ENTITY_TABLE, SCProductEntryImpl.class);
622 }
623
624 QueryPos qPos = QueryPos.getInstance(q);
625
626 qPos.add(groupId);
627
628 return (List<SCProductEntry>)QueryUtil.list(q, getDialect(), start,
629 end);
630 }
631 catch (Exception e) {
632 throw processException(e);
633 }
634 finally {
635 closeSession(session);
636 }
637 }
638
639
648 @Override
649 public SCProductEntry[] filterFindByGroupId_PrevAndNext(
650 long productEntryId, long groupId,
651 OrderByComparator<SCProductEntry> orderByComparator)
652 throws NoSuchProductEntryException {
653 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
654 return findByGroupId_PrevAndNext(productEntryId, groupId,
655 orderByComparator);
656 }
657
658 SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
659
660 Session session = null;
661
662 try {
663 session = openSession();
664
665 SCProductEntry[] array = new SCProductEntryImpl[3];
666
667 array[0] = filterGetByGroupId_PrevAndNext(session, scProductEntry,
668 groupId, orderByComparator, true);
669
670 array[1] = scProductEntry;
671
672 array[2] = filterGetByGroupId_PrevAndNext(session, scProductEntry,
673 groupId, orderByComparator, false);
674
675 return array;
676 }
677 catch (Exception e) {
678 throw processException(e);
679 }
680 finally {
681 closeSession(session);
682 }
683 }
684
685 protected SCProductEntry filterGetByGroupId_PrevAndNext(Session session,
686 SCProductEntry scProductEntry, long groupId,
687 OrderByComparator<SCProductEntry> orderByComparator, boolean previous) {
688 StringBundler query = null;
689
690 if (orderByComparator != null) {
691 query = new StringBundler(6 +
692 (orderByComparator.getOrderByFields().length * 6));
693 }
694 else {
695 query = new StringBundler(3);
696 }
697
698 if (getDB().isSupportsInlineDistinct()) {
699 query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_WHERE);
700 }
701 else {
702 query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_1);
703 }
704
705 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
706
707 if (!getDB().isSupportsInlineDistinct()) {
708 query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_2);
709 }
710
711 if (orderByComparator != null) {
712 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
713
714 if (orderByConditionFields.length > 0) {
715 query.append(WHERE_AND);
716 }
717
718 for (int i = 0; i < orderByConditionFields.length; i++) {
719 if (getDB().isSupportsInlineDistinct()) {
720 query.append(_ORDER_BY_ENTITY_ALIAS);
721 }
722 else {
723 query.append(_ORDER_BY_ENTITY_TABLE);
724 }
725
726 query.append(orderByConditionFields[i]);
727
728 if ((i + 1) < orderByConditionFields.length) {
729 if (orderByComparator.isAscending() ^ previous) {
730 query.append(WHERE_GREATER_THAN_HAS_NEXT);
731 }
732 else {
733 query.append(WHERE_LESSER_THAN_HAS_NEXT);
734 }
735 }
736 else {
737 if (orderByComparator.isAscending() ^ previous) {
738 query.append(WHERE_GREATER_THAN);
739 }
740 else {
741 query.append(WHERE_LESSER_THAN);
742 }
743 }
744 }
745
746 query.append(ORDER_BY_CLAUSE);
747
748 String[] orderByFields = orderByComparator.getOrderByFields();
749
750 for (int i = 0; i < orderByFields.length; i++) {
751 if (getDB().isSupportsInlineDistinct()) {
752 query.append(_ORDER_BY_ENTITY_ALIAS);
753 }
754 else {
755 query.append(_ORDER_BY_ENTITY_TABLE);
756 }
757
758 query.append(orderByFields[i]);
759
760 if ((i + 1) < orderByFields.length) {
761 if (orderByComparator.isAscending() ^ previous) {
762 query.append(ORDER_BY_ASC_HAS_NEXT);
763 }
764 else {
765 query.append(ORDER_BY_DESC_HAS_NEXT);
766 }
767 }
768 else {
769 if (orderByComparator.isAscending() ^ previous) {
770 query.append(ORDER_BY_ASC);
771 }
772 else {
773 query.append(ORDER_BY_DESC);
774 }
775 }
776 }
777 }
778 else {
779 if (getDB().isSupportsInlineDistinct()) {
780 query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
781 }
782 else {
783 query.append(SCProductEntryModelImpl.ORDER_BY_SQL);
784 }
785 }
786
787 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
788 SCProductEntry.class.getName(),
789 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
790
791 SQLQuery q = session.createSynchronizedSQLQuery(sql);
792
793 q.setFirstResult(0);
794 q.setMaxResults(2);
795
796 if (getDB().isSupportsInlineDistinct()) {
797 q.addEntity(_FILTER_ENTITY_ALIAS, SCProductEntryImpl.class);
798 }
799 else {
800 q.addEntity(_FILTER_ENTITY_TABLE, SCProductEntryImpl.class);
801 }
802
803 QueryPos qPos = QueryPos.getInstance(q);
804
805 qPos.add(groupId);
806
807 if (orderByComparator != null) {
808 Object[] values = orderByComparator.getOrderByConditionValues(scProductEntry);
809
810 for (Object value : values) {
811 qPos.add(value);
812 }
813 }
814
815 List<SCProductEntry> list = q.list();
816
817 if (list.size() == 2) {
818 return list.get(1);
819 }
820 else {
821 return null;
822 }
823 }
824
825
830 @Override
831 public void removeByGroupId(long groupId) {
832 for (SCProductEntry scProductEntry : findByGroupId(groupId,
833 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
834 remove(scProductEntry);
835 }
836 }
837
838
844 @Override
845 public int countByGroupId(long groupId) {
846 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
847
848 Object[] finderArgs = new Object[] { groupId };
849
850 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
851 this);
852
853 if (count == null) {
854 StringBundler query = new StringBundler(2);
855
856 query.append(_SQL_COUNT_SCPRODUCTENTRY_WHERE);
857
858 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
859
860 String sql = query.toString();
861
862 Session session = null;
863
864 try {
865 session = openSession();
866
867 Query q = session.createQuery(sql);
868
869 QueryPos qPos = QueryPos.getInstance(q);
870
871 qPos.add(groupId);
872
873 count = (Long)q.uniqueResult();
874
875 FinderCacheUtil.putResult(finderPath, finderArgs, count);
876 }
877 catch (Exception e) {
878 FinderCacheUtil.removeResult(finderPath, finderArgs);
879
880 throw processException(e);
881 }
882 finally {
883 closeSession(session);
884 }
885 }
886
887 return count.intValue();
888 }
889
890
896 @Override
897 public int filterCountByGroupId(long groupId) {
898 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
899 return countByGroupId(groupId);
900 }
901
902 StringBundler query = new StringBundler(2);
903
904 query.append(_FILTER_SQL_COUNT_SCPRODUCTENTRY_WHERE);
905
906 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
907
908 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
909 SCProductEntry.class.getName(),
910 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
911
912 Session session = null;
913
914 try {
915 session = openSession();
916
917 SQLQuery q = session.createSynchronizedSQLQuery(sql);
918
919 q.addScalar(COUNT_COLUMN_NAME,
920 com.liferay.portal.kernel.dao.orm.Type.LONG);
921
922 QueryPos qPos = QueryPos.getInstance(q);
923
924 qPos.add(groupId);
925
926 Long count = (Long)q.uniqueResult();
927
928 return count.intValue();
929 }
930 catch (Exception e) {
931 throw processException(e);
932 }
933 finally {
934 closeSession(session);
935 }
936 }
937
938 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "scProductEntry.groupId = ?";
939 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
940 new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
941 SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
942 SCProductEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
943 "findByCompanyId",
944 new String[] {
945 Long.class.getName(),
946
947 Integer.class.getName(), Integer.class.getName(),
948 OrderByComparator.class.getName()
949 });
950 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
951 new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
952 SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
953 SCProductEntryImpl.class,
954 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
955 new String[] { Long.class.getName() },
956 SCProductEntryModelImpl.COMPANYID_COLUMN_BITMASK |
957 SCProductEntryModelImpl.MODIFIEDDATE_COLUMN_BITMASK |
958 SCProductEntryModelImpl.NAME_COLUMN_BITMASK);
959 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
960 SCProductEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
961 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
962 new String[] { Long.class.getName() });
963
964
970 @Override
971 public List<SCProductEntry> findByCompanyId(long companyId) {
972 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
973 null);
974 }
975
976
988 @Override
989 public List<SCProductEntry> findByCompanyId(long companyId, int start,
990 int end) {
991 return findByCompanyId(companyId, start, end, null);
992 }
993
994
1007 @Override
1008 public List<SCProductEntry> findByCompanyId(long companyId, int start,
1009 int end, OrderByComparator<SCProductEntry> orderByComparator) {
1010 boolean pagination = true;
1011 FinderPath finderPath = null;
1012 Object[] finderArgs = null;
1013
1014 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1015 (orderByComparator == null)) {
1016 pagination = false;
1017 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1018 finderArgs = new Object[] { companyId };
1019 }
1020 else {
1021 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1022 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1023 }
1024
1025 List<SCProductEntry> list = (List<SCProductEntry>)FinderCacheUtil.getResult(finderPath,
1026 finderArgs, this);
1027
1028 if ((list != null) && !list.isEmpty()) {
1029 for (SCProductEntry scProductEntry : list) {
1030 if ((companyId != scProductEntry.getCompanyId())) {
1031 list = null;
1032
1033 break;
1034 }
1035 }
1036 }
1037
1038 if (list == null) {
1039 StringBundler query = null;
1040
1041 if (orderByComparator != null) {
1042 query = new StringBundler(3 +
1043 (orderByComparator.getOrderByFields().length * 3));
1044 }
1045 else {
1046 query = new StringBundler(3);
1047 }
1048
1049 query.append(_SQL_SELECT_SCPRODUCTENTRY_WHERE);
1050
1051 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1052
1053 if (orderByComparator != null) {
1054 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1055 orderByComparator);
1056 }
1057 else
1058 if (pagination) {
1059 query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
1060 }
1061
1062 String sql = query.toString();
1063
1064 Session session = null;
1065
1066 try {
1067 session = openSession();
1068
1069 Query q = session.createQuery(sql);
1070
1071 QueryPos qPos = QueryPos.getInstance(q);
1072
1073 qPos.add(companyId);
1074
1075 if (!pagination) {
1076 list = (List<SCProductEntry>)QueryUtil.list(q,
1077 getDialect(), start, end, false);
1078
1079 Collections.sort(list);
1080
1081 list = Collections.unmodifiableList(list);
1082 }
1083 else {
1084 list = (List<SCProductEntry>)QueryUtil.list(q,
1085 getDialect(), start, end);
1086 }
1087
1088 cacheResult(list);
1089
1090 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1091 }
1092 catch (Exception e) {
1093 FinderCacheUtil.removeResult(finderPath, finderArgs);
1094
1095 throw processException(e);
1096 }
1097 finally {
1098 closeSession(session);
1099 }
1100 }
1101
1102 return list;
1103 }
1104
1105
1113 @Override
1114 public SCProductEntry findByCompanyId_First(long companyId,
1115 OrderByComparator<SCProductEntry> orderByComparator)
1116 throws NoSuchProductEntryException {
1117 SCProductEntry scProductEntry = fetchByCompanyId_First(companyId,
1118 orderByComparator);
1119
1120 if (scProductEntry != null) {
1121 return scProductEntry;
1122 }
1123
1124 StringBundler msg = new StringBundler(4);
1125
1126 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1127
1128 msg.append("companyId=");
1129 msg.append(companyId);
1130
1131 msg.append(StringPool.CLOSE_CURLY_BRACE);
1132
1133 throw new NoSuchProductEntryException(msg.toString());
1134 }
1135
1136
1143 @Override
1144 public SCProductEntry fetchByCompanyId_First(long companyId,
1145 OrderByComparator<SCProductEntry> orderByComparator) {
1146 List<SCProductEntry> list = findByCompanyId(companyId, 0, 1,
1147 orderByComparator);
1148
1149 if (!list.isEmpty()) {
1150 return list.get(0);
1151 }
1152
1153 return null;
1154 }
1155
1156
1164 @Override
1165 public SCProductEntry findByCompanyId_Last(long companyId,
1166 OrderByComparator<SCProductEntry> orderByComparator)
1167 throws NoSuchProductEntryException {
1168 SCProductEntry scProductEntry = fetchByCompanyId_Last(companyId,
1169 orderByComparator);
1170
1171 if (scProductEntry != null) {
1172 return scProductEntry;
1173 }
1174
1175 StringBundler msg = new StringBundler(4);
1176
1177 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1178
1179 msg.append("companyId=");
1180 msg.append(companyId);
1181
1182 msg.append(StringPool.CLOSE_CURLY_BRACE);
1183
1184 throw new NoSuchProductEntryException(msg.toString());
1185 }
1186
1187
1194 @Override
1195 public SCProductEntry fetchByCompanyId_Last(long companyId,
1196 OrderByComparator<SCProductEntry> orderByComparator) {
1197 int count = countByCompanyId(companyId);
1198
1199 if (count == 0) {
1200 return null;
1201 }
1202
1203 List<SCProductEntry> list = findByCompanyId(companyId, count - 1,
1204 count, orderByComparator);
1205
1206 if (!list.isEmpty()) {
1207 return list.get(0);
1208 }
1209
1210 return null;
1211 }
1212
1213
1222 @Override
1223 public SCProductEntry[] findByCompanyId_PrevAndNext(long productEntryId,
1224 long companyId, OrderByComparator<SCProductEntry> orderByComparator)
1225 throws NoSuchProductEntryException {
1226 SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
1227
1228 Session session = null;
1229
1230 try {
1231 session = openSession();
1232
1233 SCProductEntry[] array = new SCProductEntryImpl[3];
1234
1235 array[0] = getByCompanyId_PrevAndNext(session, scProductEntry,
1236 companyId, orderByComparator, true);
1237
1238 array[1] = scProductEntry;
1239
1240 array[2] = getByCompanyId_PrevAndNext(session, scProductEntry,
1241 companyId, orderByComparator, false);
1242
1243 return array;
1244 }
1245 catch (Exception e) {
1246 throw processException(e);
1247 }
1248 finally {
1249 closeSession(session);
1250 }
1251 }
1252
1253 protected SCProductEntry getByCompanyId_PrevAndNext(Session session,
1254 SCProductEntry scProductEntry, long companyId,
1255 OrderByComparator<SCProductEntry> orderByComparator, boolean previous) {
1256 StringBundler query = null;
1257
1258 if (orderByComparator != null) {
1259 query = new StringBundler(6 +
1260 (orderByComparator.getOrderByFields().length * 6));
1261 }
1262 else {
1263 query = new StringBundler(3);
1264 }
1265
1266 query.append(_SQL_SELECT_SCPRODUCTENTRY_WHERE);
1267
1268 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1269
1270 if (orderByComparator != null) {
1271 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1272
1273 if (orderByConditionFields.length > 0) {
1274 query.append(WHERE_AND);
1275 }
1276
1277 for (int i = 0; i < orderByConditionFields.length; i++) {
1278 query.append(_ORDER_BY_ENTITY_ALIAS);
1279 query.append(orderByConditionFields[i]);
1280
1281 if ((i + 1) < orderByConditionFields.length) {
1282 if (orderByComparator.isAscending() ^ previous) {
1283 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1284 }
1285 else {
1286 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1287 }
1288 }
1289 else {
1290 if (orderByComparator.isAscending() ^ previous) {
1291 query.append(WHERE_GREATER_THAN);
1292 }
1293 else {
1294 query.append(WHERE_LESSER_THAN);
1295 }
1296 }
1297 }
1298
1299 query.append(ORDER_BY_CLAUSE);
1300
1301 String[] orderByFields = orderByComparator.getOrderByFields();
1302
1303 for (int i = 0; i < orderByFields.length; i++) {
1304 query.append(_ORDER_BY_ENTITY_ALIAS);
1305 query.append(orderByFields[i]);
1306
1307 if ((i + 1) < orderByFields.length) {
1308 if (orderByComparator.isAscending() ^ previous) {
1309 query.append(ORDER_BY_ASC_HAS_NEXT);
1310 }
1311 else {
1312 query.append(ORDER_BY_DESC_HAS_NEXT);
1313 }
1314 }
1315 else {
1316 if (orderByComparator.isAscending() ^ previous) {
1317 query.append(ORDER_BY_ASC);
1318 }
1319 else {
1320 query.append(ORDER_BY_DESC);
1321 }
1322 }
1323 }
1324 }
1325 else {
1326 query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
1327 }
1328
1329 String sql = query.toString();
1330
1331 Query q = session.createQuery(sql);
1332
1333 q.setFirstResult(0);
1334 q.setMaxResults(2);
1335
1336 QueryPos qPos = QueryPos.getInstance(q);
1337
1338 qPos.add(companyId);
1339
1340 if (orderByComparator != null) {
1341 Object[] values = orderByComparator.getOrderByConditionValues(scProductEntry);
1342
1343 for (Object value : values) {
1344 qPos.add(value);
1345 }
1346 }
1347
1348 List<SCProductEntry> list = q.list();
1349
1350 if (list.size() == 2) {
1351 return list.get(1);
1352 }
1353 else {
1354 return null;
1355 }
1356 }
1357
1358
1363 @Override
1364 public void removeByCompanyId(long companyId) {
1365 for (SCProductEntry scProductEntry : findByCompanyId(companyId,
1366 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1367 remove(scProductEntry);
1368 }
1369 }
1370
1371
1377 @Override
1378 public int countByCompanyId(long companyId) {
1379 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1380
1381 Object[] finderArgs = new Object[] { companyId };
1382
1383 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1384 this);
1385
1386 if (count == null) {
1387 StringBundler query = new StringBundler(2);
1388
1389 query.append(_SQL_COUNT_SCPRODUCTENTRY_WHERE);
1390
1391 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1392
1393 String sql = query.toString();
1394
1395 Session session = null;
1396
1397 try {
1398 session = openSession();
1399
1400 Query q = session.createQuery(sql);
1401
1402 QueryPos qPos = QueryPos.getInstance(q);
1403
1404 qPos.add(companyId);
1405
1406 count = (Long)q.uniqueResult();
1407
1408 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1409 }
1410 catch (Exception e) {
1411 FinderCacheUtil.removeResult(finderPath, finderArgs);
1412
1413 throw processException(e);
1414 }
1415 finally {
1416 closeSession(session);
1417 }
1418 }
1419
1420 return count.intValue();
1421 }
1422
1423 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "scProductEntry.companyId = ?";
1424 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
1425 SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
1426 SCProductEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1427 "findByG_U",
1428 new String[] {
1429 Long.class.getName(), Long.class.getName(),
1430
1431 Integer.class.getName(), Integer.class.getName(),
1432 OrderByComparator.class.getName()
1433 });
1434 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
1435 SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
1436 SCProductEntryImpl.class,
1437 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
1438 new String[] { Long.class.getName(), Long.class.getName() },
1439 SCProductEntryModelImpl.GROUPID_COLUMN_BITMASK |
1440 SCProductEntryModelImpl.USERID_COLUMN_BITMASK |
1441 SCProductEntryModelImpl.MODIFIEDDATE_COLUMN_BITMASK |
1442 SCProductEntryModelImpl.NAME_COLUMN_BITMASK);
1443 public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
1444 SCProductEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1445 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
1446 new String[] { Long.class.getName(), Long.class.getName() });
1447
1448
1455 @Override
1456 public List<SCProductEntry> findByG_U(long groupId, long userId) {
1457 return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1458 null);
1459 }
1460
1461
1474 @Override
1475 public List<SCProductEntry> findByG_U(long groupId, long userId, int start,
1476 int end) {
1477 return findByG_U(groupId, userId, start, end, null);
1478 }
1479
1480
1494 @Override
1495 public List<SCProductEntry> findByG_U(long groupId, long userId, int start,
1496 int end, OrderByComparator<SCProductEntry> orderByComparator) {
1497 boolean pagination = true;
1498 FinderPath finderPath = null;
1499 Object[] finderArgs = null;
1500
1501 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1502 (orderByComparator == null)) {
1503 pagination = false;
1504 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
1505 finderArgs = new Object[] { groupId, userId };
1506 }
1507 else {
1508 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
1509 finderArgs = new Object[] {
1510 groupId, userId,
1511
1512 start, end, orderByComparator
1513 };
1514 }
1515
1516 List<SCProductEntry> list = (List<SCProductEntry>)FinderCacheUtil.getResult(finderPath,
1517 finderArgs, this);
1518
1519 if ((list != null) && !list.isEmpty()) {
1520 for (SCProductEntry scProductEntry : list) {
1521 if ((groupId != scProductEntry.getGroupId()) ||
1522 (userId != scProductEntry.getUserId())) {
1523 list = null;
1524
1525 break;
1526 }
1527 }
1528 }
1529
1530 if (list == null) {
1531 StringBundler query = null;
1532
1533 if (orderByComparator != null) {
1534 query = new StringBundler(4 +
1535 (orderByComparator.getOrderByFields().length * 3));
1536 }
1537 else {
1538 query = new StringBundler(4);
1539 }
1540
1541 query.append(_SQL_SELECT_SCPRODUCTENTRY_WHERE);
1542
1543 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1544
1545 query.append(_FINDER_COLUMN_G_U_USERID_2);
1546
1547 if (orderByComparator != null) {
1548 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1549 orderByComparator);
1550 }
1551 else
1552 if (pagination) {
1553 query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
1554 }
1555
1556 String sql = query.toString();
1557
1558 Session session = null;
1559
1560 try {
1561 session = openSession();
1562
1563 Query q = session.createQuery(sql);
1564
1565 QueryPos qPos = QueryPos.getInstance(q);
1566
1567 qPos.add(groupId);
1568
1569 qPos.add(userId);
1570
1571 if (!pagination) {
1572 list = (List<SCProductEntry>)QueryUtil.list(q,
1573 getDialect(), start, end, false);
1574
1575 Collections.sort(list);
1576
1577 list = Collections.unmodifiableList(list);
1578 }
1579 else {
1580 list = (List<SCProductEntry>)QueryUtil.list(q,
1581 getDialect(), start, end);
1582 }
1583
1584 cacheResult(list);
1585
1586 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1587 }
1588 catch (Exception e) {
1589 FinderCacheUtil.removeResult(finderPath, finderArgs);
1590
1591 throw processException(e);
1592 }
1593 finally {
1594 closeSession(session);
1595 }
1596 }
1597
1598 return list;
1599 }
1600
1601
1610 @Override
1611 public SCProductEntry findByG_U_First(long groupId, long userId,
1612 OrderByComparator<SCProductEntry> orderByComparator)
1613 throws NoSuchProductEntryException {
1614 SCProductEntry scProductEntry = fetchByG_U_First(groupId, userId,
1615 orderByComparator);
1616
1617 if (scProductEntry != null) {
1618 return scProductEntry;
1619 }
1620
1621 StringBundler msg = new StringBundler(6);
1622
1623 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1624
1625 msg.append("groupId=");
1626 msg.append(groupId);
1627
1628 msg.append(", userId=");
1629 msg.append(userId);
1630
1631 msg.append(StringPool.CLOSE_CURLY_BRACE);
1632
1633 throw new NoSuchProductEntryException(msg.toString());
1634 }
1635
1636
1644 @Override
1645 public SCProductEntry fetchByG_U_First(long groupId, long userId,
1646 OrderByComparator<SCProductEntry> orderByComparator) {
1647 List<SCProductEntry> list = findByG_U(groupId, userId, 0, 1,
1648 orderByComparator);
1649
1650 if (!list.isEmpty()) {
1651 return list.get(0);
1652 }
1653
1654 return null;
1655 }
1656
1657
1666 @Override
1667 public SCProductEntry findByG_U_Last(long groupId, long userId,
1668 OrderByComparator<SCProductEntry> orderByComparator)
1669 throws NoSuchProductEntryException {
1670 SCProductEntry scProductEntry = fetchByG_U_Last(groupId, userId,
1671 orderByComparator);
1672
1673 if (scProductEntry != null) {
1674 return scProductEntry;
1675 }
1676
1677 StringBundler msg = new StringBundler(6);
1678
1679 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1680
1681 msg.append("groupId=");
1682 msg.append(groupId);
1683
1684 msg.append(", userId=");
1685 msg.append(userId);
1686
1687 msg.append(StringPool.CLOSE_CURLY_BRACE);
1688
1689 throw new NoSuchProductEntryException(msg.toString());
1690 }
1691
1692
1700 @Override
1701 public SCProductEntry fetchByG_U_Last(long groupId, long userId,
1702 OrderByComparator<SCProductEntry> orderByComparator) {
1703 int count = countByG_U(groupId, userId);
1704
1705 if (count == 0) {
1706 return null;
1707 }
1708
1709 List<SCProductEntry> list = findByG_U(groupId, userId, count - 1,
1710 count, orderByComparator);
1711
1712 if (!list.isEmpty()) {
1713 return list.get(0);
1714 }
1715
1716 return null;
1717 }
1718
1719
1729 @Override
1730 public SCProductEntry[] findByG_U_PrevAndNext(long productEntryId,
1731 long groupId, long userId,
1732 OrderByComparator<SCProductEntry> orderByComparator)
1733 throws NoSuchProductEntryException {
1734 SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
1735
1736 Session session = null;
1737
1738 try {
1739 session = openSession();
1740
1741 SCProductEntry[] array = new SCProductEntryImpl[3];
1742
1743 array[0] = getByG_U_PrevAndNext(session, scProductEntry, groupId,
1744 userId, orderByComparator, true);
1745
1746 array[1] = scProductEntry;
1747
1748 array[2] = getByG_U_PrevAndNext(session, scProductEntry, groupId,
1749 userId, orderByComparator, false);
1750
1751 return array;
1752 }
1753 catch (Exception e) {
1754 throw processException(e);
1755 }
1756 finally {
1757 closeSession(session);
1758 }
1759 }
1760
1761 protected SCProductEntry getByG_U_PrevAndNext(Session session,
1762 SCProductEntry scProductEntry, long groupId, long userId,
1763 OrderByComparator<SCProductEntry> orderByComparator, boolean previous) {
1764 StringBundler query = null;
1765
1766 if (orderByComparator != null) {
1767 query = new StringBundler(6 +
1768 (orderByComparator.getOrderByFields().length * 6));
1769 }
1770 else {
1771 query = new StringBundler(3);
1772 }
1773
1774 query.append(_SQL_SELECT_SCPRODUCTENTRY_WHERE);
1775
1776 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1777
1778 query.append(_FINDER_COLUMN_G_U_USERID_2);
1779
1780 if (orderByComparator != null) {
1781 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1782
1783 if (orderByConditionFields.length > 0) {
1784 query.append(WHERE_AND);
1785 }
1786
1787 for (int i = 0; i < orderByConditionFields.length; i++) {
1788 query.append(_ORDER_BY_ENTITY_ALIAS);
1789 query.append(orderByConditionFields[i]);
1790
1791 if ((i + 1) < orderByConditionFields.length) {
1792 if (orderByComparator.isAscending() ^ previous) {
1793 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1794 }
1795 else {
1796 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1797 }
1798 }
1799 else {
1800 if (orderByComparator.isAscending() ^ previous) {
1801 query.append(WHERE_GREATER_THAN);
1802 }
1803 else {
1804 query.append(WHERE_LESSER_THAN);
1805 }
1806 }
1807 }
1808
1809 query.append(ORDER_BY_CLAUSE);
1810
1811 String[] orderByFields = orderByComparator.getOrderByFields();
1812
1813 for (int i = 0; i < orderByFields.length; i++) {
1814 query.append(_ORDER_BY_ENTITY_ALIAS);
1815 query.append(orderByFields[i]);
1816
1817 if ((i + 1) < orderByFields.length) {
1818 if (orderByComparator.isAscending() ^ previous) {
1819 query.append(ORDER_BY_ASC_HAS_NEXT);
1820 }
1821 else {
1822 query.append(ORDER_BY_DESC_HAS_NEXT);
1823 }
1824 }
1825 else {
1826 if (orderByComparator.isAscending() ^ previous) {
1827 query.append(ORDER_BY_ASC);
1828 }
1829 else {
1830 query.append(ORDER_BY_DESC);
1831 }
1832 }
1833 }
1834 }
1835 else {
1836 query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
1837 }
1838
1839 String sql = query.toString();
1840
1841 Query q = session.createQuery(sql);
1842
1843 q.setFirstResult(0);
1844 q.setMaxResults(2);
1845
1846 QueryPos qPos = QueryPos.getInstance(q);
1847
1848 qPos.add(groupId);
1849
1850 qPos.add(userId);
1851
1852 if (orderByComparator != null) {
1853 Object[] values = orderByComparator.getOrderByConditionValues(scProductEntry);
1854
1855 for (Object value : values) {
1856 qPos.add(value);
1857 }
1858 }
1859
1860 List<SCProductEntry> list = q.list();
1861
1862 if (list.size() == 2) {
1863 return list.get(1);
1864 }
1865 else {
1866 return null;
1867 }
1868 }
1869
1870
1877 @Override
1878 public List<SCProductEntry> filterFindByG_U(long groupId, long userId) {
1879 return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
1880 QueryUtil.ALL_POS, null);
1881 }
1882
1883
1896 @Override
1897 public List<SCProductEntry> filterFindByG_U(long groupId, long userId,
1898 int start, int end) {
1899 return filterFindByG_U(groupId, userId, start, end, null);
1900 }
1901
1902
1916 @Override
1917 public List<SCProductEntry> filterFindByG_U(long groupId, long userId,
1918 int start, int end, OrderByComparator<SCProductEntry> orderByComparator) {
1919 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1920 return findByG_U(groupId, userId, start, end, orderByComparator);
1921 }
1922
1923 StringBundler query = null;
1924
1925 if (orderByComparator != null) {
1926 query = new StringBundler(4 +
1927 (orderByComparator.getOrderByFields().length * 3));
1928 }
1929 else {
1930 query = new StringBundler(4);
1931 }
1932
1933 if (getDB().isSupportsInlineDistinct()) {
1934 query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_WHERE);
1935 }
1936 else {
1937 query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_1);
1938 }
1939
1940 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1941
1942 query.append(_FINDER_COLUMN_G_U_USERID_2);
1943
1944 if (!getDB().isSupportsInlineDistinct()) {
1945 query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_2);
1946 }
1947
1948 if (orderByComparator != null) {
1949 if (getDB().isSupportsInlineDistinct()) {
1950 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1951 orderByComparator, true);
1952 }
1953 else {
1954 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1955 orderByComparator, true);
1956 }
1957 }
1958 else {
1959 if (getDB().isSupportsInlineDistinct()) {
1960 query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
1961 }
1962 else {
1963 query.append(SCProductEntryModelImpl.ORDER_BY_SQL);
1964 }
1965 }
1966
1967 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1968 SCProductEntry.class.getName(),
1969 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1970
1971 Session session = null;
1972
1973 try {
1974 session = openSession();
1975
1976 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1977
1978 if (getDB().isSupportsInlineDistinct()) {
1979 q.addEntity(_FILTER_ENTITY_ALIAS, SCProductEntryImpl.class);
1980 }
1981 else {
1982 q.addEntity(_FILTER_ENTITY_TABLE, SCProductEntryImpl.class);
1983 }
1984
1985 QueryPos qPos = QueryPos.getInstance(q);
1986
1987 qPos.add(groupId);
1988
1989 qPos.add(userId);
1990
1991 return (List<SCProductEntry>)QueryUtil.list(q, getDialect(), start,
1992 end);
1993 }
1994 catch (Exception e) {
1995 throw processException(e);
1996 }
1997 finally {
1998 closeSession(session);
1999 }
2000 }
2001
2002
2012 @Override
2013 public SCProductEntry[] filterFindByG_U_PrevAndNext(long productEntryId,
2014 long groupId, long userId,
2015 OrderByComparator<SCProductEntry> orderByComparator)
2016 throws NoSuchProductEntryException {
2017 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2018 return findByG_U_PrevAndNext(productEntryId, groupId, userId,
2019 orderByComparator);
2020 }
2021
2022 SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
2023
2024 Session session = null;
2025
2026 try {
2027 session = openSession();
2028
2029 SCProductEntry[] array = new SCProductEntryImpl[3];
2030
2031 array[0] = filterGetByG_U_PrevAndNext(session, scProductEntry,
2032 groupId, userId, orderByComparator, true);
2033
2034 array[1] = scProductEntry;
2035
2036 array[2] = filterGetByG_U_PrevAndNext(session, scProductEntry,
2037 groupId, userId, orderByComparator, false);
2038
2039 return array;
2040 }
2041 catch (Exception e) {
2042 throw processException(e);
2043 }
2044 finally {
2045 closeSession(session);
2046 }
2047 }
2048
2049 protected SCProductEntry filterGetByG_U_PrevAndNext(Session session,
2050 SCProductEntry scProductEntry, long groupId, long userId,
2051 OrderByComparator<SCProductEntry> orderByComparator, boolean previous) {
2052 StringBundler query = null;
2053
2054 if (orderByComparator != null) {
2055 query = new StringBundler(6 +
2056 (orderByComparator.getOrderByFields().length * 6));
2057 }
2058 else {
2059 query = new StringBundler(3);
2060 }
2061
2062 if (getDB().isSupportsInlineDistinct()) {
2063 query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_WHERE);
2064 }
2065 else {
2066 query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_1);
2067 }
2068
2069 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2070
2071 query.append(_FINDER_COLUMN_G_U_USERID_2);
2072
2073 if (!getDB().isSupportsInlineDistinct()) {
2074 query.append(_FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_2);
2075 }
2076
2077 if (orderByComparator != null) {
2078 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2079
2080 if (orderByConditionFields.length > 0) {
2081 query.append(WHERE_AND);
2082 }
2083
2084 for (int i = 0; i < orderByConditionFields.length; i++) {
2085 if (getDB().isSupportsInlineDistinct()) {
2086 query.append(_ORDER_BY_ENTITY_ALIAS);
2087 }
2088 else {
2089 query.append(_ORDER_BY_ENTITY_TABLE);
2090 }
2091
2092 query.append(orderByConditionFields[i]);
2093
2094 if ((i + 1) < orderByConditionFields.length) {
2095 if (orderByComparator.isAscending() ^ previous) {
2096 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2097 }
2098 else {
2099 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2100 }
2101 }
2102 else {
2103 if (orderByComparator.isAscending() ^ previous) {
2104 query.append(WHERE_GREATER_THAN);
2105 }
2106 else {
2107 query.append(WHERE_LESSER_THAN);
2108 }
2109 }
2110 }
2111
2112 query.append(ORDER_BY_CLAUSE);
2113
2114 String[] orderByFields = orderByComparator.getOrderByFields();
2115
2116 for (int i = 0; i < orderByFields.length; i++) {
2117 if (getDB().isSupportsInlineDistinct()) {
2118 query.append(_ORDER_BY_ENTITY_ALIAS);
2119 }
2120 else {
2121 query.append(_ORDER_BY_ENTITY_TABLE);
2122 }
2123
2124 query.append(orderByFields[i]);
2125
2126 if ((i + 1) < orderByFields.length) {
2127 if (orderByComparator.isAscending() ^ previous) {
2128 query.append(ORDER_BY_ASC_HAS_NEXT);
2129 }
2130 else {
2131 query.append(ORDER_BY_DESC_HAS_NEXT);
2132 }
2133 }
2134 else {
2135 if (orderByComparator.isAscending() ^ previous) {
2136 query.append(ORDER_BY_ASC);
2137 }
2138 else {
2139 query.append(ORDER_BY_DESC);
2140 }
2141 }
2142 }
2143 }
2144 else {
2145 if (getDB().isSupportsInlineDistinct()) {
2146 query.append(SCProductEntryModelImpl.ORDER_BY_JPQL);
2147 }
2148 else {
2149 query.append(SCProductEntryModelImpl.ORDER_BY_SQL);
2150 }
2151 }
2152
2153 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2154 SCProductEntry.class.getName(),
2155 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2156
2157 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2158
2159 q.setFirstResult(0);
2160 q.setMaxResults(2);
2161
2162 if (getDB().isSupportsInlineDistinct()) {
2163 q.addEntity(_FILTER_ENTITY_ALIAS, SCProductEntryImpl.class);
2164 }
2165 else {
2166 q.addEntity(_FILTER_ENTITY_TABLE, SCProductEntryImpl.class);
2167 }
2168
2169 QueryPos qPos = QueryPos.getInstance(q);
2170
2171 qPos.add(groupId);
2172
2173 qPos.add(userId);
2174
2175 if (orderByComparator != null) {
2176 Object[] values = orderByComparator.getOrderByConditionValues(scProductEntry);
2177
2178 for (Object value : values) {
2179 qPos.add(value);
2180 }
2181 }
2182
2183 List<SCProductEntry> list = q.list();
2184
2185 if (list.size() == 2) {
2186 return list.get(1);
2187 }
2188 else {
2189 return null;
2190 }
2191 }
2192
2193
2199 @Override
2200 public void removeByG_U(long groupId, long userId) {
2201 for (SCProductEntry scProductEntry : findByG_U(groupId, userId,
2202 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2203 remove(scProductEntry);
2204 }
2205 }
2206
2207
2214 @Override
2215 public int countByG_U(long groupId, long userId) {
2216 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
2217
2218 Object[] finderArgs = new Object[] { groupId, userId };
2219
2220 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2221 this);
2222
2223 if (count == null) {
2224 StringBundler query = new StringBundler(3);
2225
2226 query.append(_SQL_COUNT_SCPRODUCTENTRY_WHERE);
2227
2228 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2229
2230 query.append(_FINDER_COLUMN_G_U_USERID_2);
2231
2232 String sql = query.toString();
2233
2234 Session session = null;
2235
2236 try {
2237 session = openSession();
2238
2239 Query q = session.createQuery(sql);
2240
2241 QueryPos qPos = QueryPos.getInstance(q);
2242
2243 qPos.add(groupId);
2244
2245 qPos.add(userId);
2246
2247 count = (Long)q.uniqueResult();
2248
2249 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2250 }
2251 catch (Exception e) {
2252 FinderCacheUtil.removeResult(finderPath, finderArgs);
2253
2254 throw processException(e);
2255 }
2256 finally {
2257 closeSession(session);
2258 }
2259 }
2260
2261 return count.intValue();
2262 }
2263
2264
2271 @Override
2272 public int filterCountByG_U(long groupId, long userId) {
2273 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2274 return countByG_U(groupId, userId);
2275 }
2276
2277 StringBundler query = new StringBundler(3);
2278
2279 query.append(_FILTER_SQL_COUNT_SCPRODUCTENTRY_WHERE);
2280
2281 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2282
2283 query.append(_FINDER_COLUMN_G_U_USERID_2);
2284
2285 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2286 SCProductEntry.class.getName(),
2287 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2288
2289 Session session = null;
2290
2291 try {
2292 session = openSession();
2293
2294 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2295
2296 q.addScalar(COUNT_COLUMN_NAME,
2297 com.liferay.portal.kernel.dao.orm.Type.LONG);
2298
2299 QueryPos qPos = QueryPos.getInstance(q);
2300
2301 qPos.add(groupId);
2302
2303 qPos.add(userId);
2304
2305 Long count = (Long)q.uniqueResult();
2306
2307 return count.intValue();
2308 }
2309 catch (Exception e) {
2310 throw processException(e);
2311 }
2312 finally {
2313 closeSession(session);
2314 }
2315 }
2316
2317 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "scProductEntry.groupId = ? AND ";
2318 private static final String _FINDER_COLUMN_G_U_USERID_2 = "scProductEntry.userId = ?";
2319 public static final FinderPath FINDER_PATH_FETCH_BY_RG_RA = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
2320 SCProductEntryModelImpl.FINDER_CACHE_ENABLED,
2321 SCProductEntryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByRG_RA",
2322 new String[] { String.class.getName(), String.class.getName() },
2323 SCProductEntryModelImpl.REPOGROUPID_COLUMN_BITMASK |
2324 SCProductEntryModelImpl.REPOARTIFACTID_COLUMN_BITMASK);
2325 public static final FinderPath FINDER_PATH_COUNT_BY_RG_RA = new FinderPath(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
2326 SCProductEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2327 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRG_RA",
2328 new String[] { String.class.getName(), String.class.getName() });
2329
2330
2338 @Override
2339 public SCProductEntry findByRG_RA(String repoGroupId, String repoArtifactId)
2340 throws NoSuchProductEntryException {
2341 SCProductEntry scProductEntry = fetchByRG_RA(repoGroupId, repoArtifactId);
2342
2343 if (scProductEntry == null) {
2344 StringBundler msg = new StringBundler(6);
2345
2346 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2347
2348 msg.append("repoGroupId=");
2349 msg.append(repoGroupId);
2350
2351 msg.append(", repoArtifactId=");
2352 msg.append(repoArtifactId);
2353
2354 msg.append(StringPool.CLOSE_CURLY_BRACE);
2355
2356 if (_log.isWarnEnabled()) {
2357 _log.warn(msg.toString());
2358 }
2359
2360 throw new NoSuchProductEntryException(msg.toString());
2361 }
2362
2363 return scProductEntry;
2364 }
2365
2366
2373 @Override
2374 public SCProductEntry fetchByRG_RA(String repoGroupId, String repoArtifactId) {
2375 return fetchByRG_RA(repoGroupId, repoArtifactId, true);
2376 }
2377
2378
2386 @Override
2387 public SCProductEntry fetchByRG_RA(String repoGroupId,
2388 String repoArtifactId, boolean retrieveFromCache) {
2389 Object[] finderArgs = new Object[] { repoGroupId, repoArtifactId };
2390
2391 Object result = null;
2392
2393 if (retrieveFromCache) {
2394 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_RG_RA,
2395 finderArgs, this);
2396 }
2397
2398 if (result instanceof SCProductEntry) {
2399 SCProductEntry scProductEntry = (SCProductEntry)result;
2400
2401 if (!Validator.equals(repoGroupId, scProductEntry.getRepoGroupId()) ||
2402 !Validator.equals(repoArtifactId,
2403 scProductEntry.getRepoArtifactId())) {
2404 result = null;
2405 }
2406 }
2407
2408 if (result == null) {
2409 StringBundler query = new StringBundler(4);
2410
2411 query.append(_SQL_SELECT_SCPRODUCTENTRY_WHERE);
2412
2413 boolean bindRepoGroupId = false;
2414
2415 if (repoGroupId == null) {
2416 query.append(_FINDER_COLUMN_RG_RA_REPOGROUPID_1);
2417 }
2418 else if (repoGroupId.equals(StringPool.BLANK)) {
2419 query.append(_FINDER_COLUMN_RG_RA_REPOGROUPID_3);
2420 }
2421 else {
2422 bindRepoGroupId = true;
2423
2424 query.append(_FINDER_COLUMN_RG_RA_REPOGROUPID_2);
2425 }
2426
2427 boolean bindRepoArtifactId = false;
2428
2429 if (repoArtifactId == null) {
2430 query.append(_FINDER_COLUMN_RG_RA_REPOARTIFACTID_1);
2431 }
2432 else if (repoArtifactId.equals(StringPool.BLANK)) {
2433 query.append(_FINDER_COLUMN_RG_RA_REPOARTIFACTID_3);
2434 }
2435 else {
2436 bindRepoArtifactId = true;
2437
2438 query.append(_FINDER_COLUMN_RG_RA_REPOARTIFACTID_2);
2439 }
2440
2441 String sql = query.toString();
2442
2443 Session session = null;
2444
2445 try {
2446 session = openSession();
2447
2448 Query q = session.createQuery(sql);
2449
2450 QueryPos qPos = QueryPos.getInstance(q);
2451
2452 if (bindRepoGroupId) {
2453 qPos.add(StringUtil.toLowerCase(repoGroupId));
2454 }
2455
2456 if (bindRepoArtifactId) {
2457 qPos.add(StringUtil.toLowerCase(repoArtifactId));
2458 }
2459
2460 List<SCProductEntry> list = q.list();
2461
2462 if (list.isEmpty()) {
2463 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_RG_RA,
2464 finderArgs, list);
2465 }
2466 else {
2467 if ((list.size() > 1) && _log.isWarnEnabled()) {
2468 _log.warn(
2469 "SCProductEntryPersistenceImpl.fetchByRG_RA(String, String, boolean) with parameters (" +
2470 StringUtil.merge(finderArgs) +
2471 ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
2472 }
2473
2474 SCProductEntry scProductEntry = list.get(0);
2475
2476 result = scProductEntry;
2477
2478 cacheResult(scProductEntry);
2479
2480 if ((scProductEntry.getRepoGroupId() == null) ||
2481 !scProductEntry.getRepoGroupId().equals(repoGroupId) ||
2482 (scProductEntry.getRepoArtifactId() == null) ||
2483 !scProductEntry.getRepoArtifactId()
2484 .equals(repoArtifactId)) {
2485 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_RG_RA,
2486 finderArgs, scProductEntry);
2487 }
2488 }
2489 }
2490 catch (Exception e) {
2491 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_RG_RA,
2492 finderArgs);
2493
2494 throw processException(e);
2495 }
2496 finally {
2497 closeSession(session);
2498 }
2499 }
2500
2501 if (result instanceof List<?>) {
2502 return null;
2503 }
2504 else {
2505 return (SCProductEntry)result;
2506 }
2507 }
2508
2509
2516 @Override
2517 public SCProductEntry removeByRG_RA(String repoGroupId,
2518 String repoArtifactId) throws NoSuchProductEntryException {
2519 SCProductEntry scProductEntry = findByRG_RA(repoGroupId, repoArtifactId);
2520
2521 return remove(scProductEntry);
2522 }
2523
2524
2531 @Override
2532 public int countByRG_RA(String repoGroupId, String repoArtifactId) {
2533 FinderPath finderPath = FINDER_PATH_COUNT_BY_RG_RA;
2534
2535 Object[] finderArgs = new Object[] { repoGroupId, repoArtifactId };
2536
2537 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2538 this);
2539
2540 if (count == null) {
2541 StringBundler query = new StringBundler(3);
2542
2543 query.append(_SQL_COUNT_SCPRODUCTENTRY_WHERE);
2544
2545 boolean bindRepoGroupId = false;
2546
2547 if (repoGroupId == null) {
2548 query.append(_FINDER_COLUMN_RG_RA_REPOGROUPID_1);
2549 }
2550 else if (repoGroupId.equals(StringPool.BLANK)) {
2551 query.append(_FINDER_COLUMN_RG_RA_REPOGROUPID_3);
2552 }
2553 else {
2554 bindRepoGroupId = true;
2555
2556 query.append(_FINDER_COLUMN_RG_RA_REPOGROUPID_2);
2557 }
2558
2559 boolean bindRepoArtifactId = false;
2560
2561 if (repoArtifactId == null) {
2562 query.append(_FINDER_COLUMN_RG_RA_REPOARTIFACTID_1);
2563 }
2564 else if (repoArtifactId.equals(StringPool.BLANK)) {
2565 query.append(_FINDER_COLUMN_RG_RA_REPOARTIFACTID_3);
2566 }
2567 else {
2568 bindRepoArtifactId = true;
2569
2570 query.append(_FINDER_COLUMN_RG_RA_REPOARTIFACTID_2);
2571 }
2572
2573 String sql = query.toString();
2574
2575 Session session = null;
2576
2577 try {
2578 session = openSession();
2579
2580 Query q = session.createQuery(sql);
2581
2582 QueryPos qPos = QueryPos.getInstance(q);
2583
2584 if (bindRepoGroupId) {
2585 qPos.add(StringUtil.toLowerCase(repoGroupId));
2586 }
2587
2588 if (bindRepoArtifactId) {
2589 qPos.add(StringUtil.toLowerCase(repoArtifactId));
2590 }
2591
2592 count = (Long)q.uniqueResult();
2593
2594 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2595 }
2596 catch (Exception e) {
2597 FinderCacheUtil.removeResult(finderPath, finderArgs);
2598
2599 throw processException(e);
2600 }
2601 finally {
2602 closeSession(session);
2603 }
2604 }
2605
2606 return count.intValue();
2607 }
2608
2609 private static final String _FINDER_COLUMN_RG_RA_REPOGROUPID_1 = "scProductEntry.repoGroupId IS NULL AND ";
2610 private static final String _FINDER_COLUMN_RG_RA_REPOGROUPID_2 = "lower(scProductEntry.repoGroupId) = ? AND ";
2611 private static final String _FINDER_COLUMN_RG_RA_REPOGROUPID_3 = "(scProductEntry.repoGroupId IS NULL OR scProductEntry.repoGroupId = '') AND ";
2612 private static final String _FINDER_COLUMN_RG_RA_REPOARTIFACTID_1 = "scProductEntry.repoArtifactId IS NULL";
2613 private static final String _FINDER_COLUMN_RG_RA_REPOARTIFACTID_2 = "lower(scProductEntry.repoArtifactId) = ?";
2614 private static final String _FINDER_COLUMN_RG_RA_REPOARTIFACTID_3 = "(scProductEntry.repoArtifactId IS NULL OR scProductEntry.repoArtifactId = '')";
2615
2616 public SCProductEntryPersistenceImpl() {
2617 setModelClass(SCProductEntry.class);
2618 }
2619
2620
2625 @Override
2626 public void cacheResult(SCProductEntry scProductEntry) {
2627 EntityCacheUtil.putResult(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
2628 SCProductEntryImpl.class, scProductEntry.getPrimaryKey(),
2629 scProductEntry);
2630
2631 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_RG_RA,
2632 new Object[] {
2633 scProductEntry.getRepoGroupId(),
2634 scProductEntry.getRepoArtifactId()
2635 }, scProductEntry);
2636
2637 scProductEntry.resetOriginalValues();
2638 }
2639
2640
2645 @Override
2646 public void cacheResult(List<SCProductEntry> scProductEntries) {
2647 for (SCProductEntry scProductEntry : scProductEntries) {
2648 if (EntityCacheUtil.getResult(
2649 SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
2650 SCProductEntryImpl.class, scProductEntry.getPrimaryKey()) == null) {
2651 cacheResult(scProductEntry);
2652 }
2653 else {
2654 scProductEntry.resetOriginalValues();
2655 }
2656 }
2657 }
2658
2659
2666 @Override
2667 public void clearCache() {
2668 EntityCacheUtil.clearCache(SCProductEntryImpl.class);
2669
2670 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2671 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2672 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2673 }
2674
2675
2682 @Override
2683 public void clearCache(SCProductEntry scProductEntry) {
2684 EntityCacheUtil.removeResult(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
2685 SCProductEntryImpl.class, scProductEntry.getPrimaryKey());
2686
2687 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2688 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2689
2690 clearUniqueFindersCache(scProductEntry);
2691 }
2692
2693 @Override
2694 public void clearCache(List<SCProductEntry> scProductEntries) {
2695 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2696 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2697
2698 for (SCProductEntry scProductEntry : scProductEntries) {
2699 EntityCacheUtil.removeResult(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
2700 SCProductEntryImpl.class, scProductEntry.getPrimaryKey());
2701
2702 clearUniqueFindersCache(scProductEntry);
2703 }
2704 }
2705
2706 protected void cacheUniqueFindersCache(SCProductEntry scProductEntry) {
2707 if (scProductEntry.isNew()) {
2708 Object[] args = new Object[] {
2709 scProductEntry.getRepoGroupId(),
2710 scProductEntry.getRepoArtifactId()
2711 };
2712
2713 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RG_RA, args,
2714 Long.valueOf(1));
2715 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_RG_RA, args,
2716 scProductEntry);
2717 }
2718 else {
2719 SCProductEntryModelImpl scProductEntryModelImpl = (SCProductEntryModelImpl)scProductEntry;
2720
2721 if ((scProductEntryModelImpl.getColumnBitmask() &
2722 FINDER_PATH_FETCH_BY_RG_RA.getColumnBitmask()) != 0) {
2723 Object[] args = new Object[] {
2724 scProductEntry.getRepoGroupId(),
2725 scProductEntry.getRepoArtifactId()
2726 };
2727
2728 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RG_RA, args,
2729 Long.valueOf(1));
2730 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_RG_RA, args,
2731 scProductEntry);
2732 }
2733 }
2734 }
2735
2736 protected void clearUniqueFindersCache(SCProductEntry scProductEntry) {
2737 SCProductEntryModelImpl scProductEntryModelImpl = (SCProductEntryModelImpl)scProductEntry;
2738
2739 Object[] args = new Object[] {
2740 scProductEntry.getRepoGroupId(),
2741 scProductEntry.getRepoArtifactId()
2742 };
2743
2744 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RG_RA, args);
2745 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_RG_RA, args);
2746
2747 if ((scProductEntryModelImpl.getColumnBitmask() &
2748 FINDER_PATH_FETCH_BY_RG_RA.getColumnBitmask()) != 0) {
2749 args = new Object[] {
2750 scProductEntryModelImpl.getOriginalRepoGroupId(),
2751 scProductEntryModelImpl.getOriginalRepoArtifactId()
2752 };
2753
2754 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RG_RA, args);
2755 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_RG_RA, args);
2756 }
2757 }
2758
2759
2765 @Override
2766 public SCProductEntry create(long productEntryId) {
2767 SCProductEntry scProductEntry = new SCProductEntryImpl();
2768
2769 scProductEntry.setNew(true);
2770 scProductEntry.setPrimaryKey(productEntryId);
2771
2772 return scProductEntry;
2773 }
2774
2775
2782 @Override
2783 public SCProductEntry remove(long productEntryId)
2784 throws NoSuchProductEntryException {
2785 return remove((Serializable)productEntryId);
2786 }
2787
2788
2795 @Override
2796 public SCProductEntry remove(Serializable primaryKey)
2797 throws NoSuchProductEntryException {
2798 Session session = null;
2799
2800 try {
2801 session = openSession();
2802
2803 SCProductEntry scProductEntry = (SCProductEntry)session.get(SCProductEntryImpl.class,
2804 primaryKey);
2805
2806 if (scProductEntry == null) {
2807 if (_log.isWarnEnabled()) {
2808 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2809 }
2810
2811 throw new NoSuchProductEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2812 primaryKey);
2813 }
2814
2815 return remove(scProductEntry);
2816 }
2817 catch (NoSuchProductEntryException nsee) {
2818 throw nsee;
2819 }
2820 catch (Exception e) {
2821 throw processException(e);
2822 }
2823 finally {
2824 closeSession(session);
2825 }
2826 }
2827
2828 @Override
2829 protected SCProductEntry removeImpl(SCProductEntry scProductEntry) {
2830 scProductEntry = toUnwrappedModel(scProductEntry);
2831
2832 scProductEntryToSCLicenseTableMapper.deleteLeftPrimaryKeyTableMappings(scProductEntry.getPrimaryKey());
2833
2834 Session session = null;
2835
2836 try {
2837 session = openSession();
2838
2839 if (!session.contains(scProductEntry)) {
2840 scProductEntry = (SCProductEntry)session.get(SCProductEntryImpl.class,
2841 scProductEntry.getPrimaryKeyObj());
2842 }
2843
2844 if (scProductEntry != null) {
2845 session.delete(scProductEntry);
2846 }
2847 }
2848 catch (Exception e) {
2849 throw processException(e);
2850 }
2851 finally {
2852 closeSession(session);
2853 }
2854
2855 if (scProductEntry != null) {
2856 clearCache(scProductEntry);
2857 }
2858
2859 return scProductEntry;
2860 }
2861
2862 @Override
2863 public SCProductEntry updateImpl(SCProductEntry scProductEntry) {
2864 scProductEntry = toUnwrappedModel(scProductEntry);
2865
2866 boolean isNew = scProductEntry.isNew();
2867
2868 SCProductEntryModelImpl scProductEntryModelImpl = (SCProductEntryModelImpl)scProductEntry;
2869
2870 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
2871
2872 Date now = new Date();
2873
2874 if (isNew && (scProductEntry.getCreateDate() == null)) {
2875 if (serviceContext == null) {
2876 scProductEntry.setCreateDate(now);
2877 }
2878 else {
2879 scProductEntry.setCreateDate(serviceContext.getCreateDate(now));
2880 }
2881 }
2882
2883 if (!scProductEntryModelImpl.hasSetModifiedDate()) {
2884 if (serviceContext == null) {
2885 scProductEntry.setModifiedDate(now);
2886 }
2887 else {
2888 scProductEntry.setModifiedDate(serviceContext.getModifiedDate(
2889 now));
2890 }
2891 }
2892
2893 Session session = null;
2894
2895 try {
2896 session = openSession();
2897
2898 if (scProductEntry.isNew()) {
2899 session.save(scProductEntry);
2900
2901 scProductEntry.setNew(false);
2902 }
2903 else {
2904 session.merge(scProductEntry);
2905 }
2906 }
2907 catch (Exception e) {
2908 throw processException(e);
2909 }
2910 finally {
2911 closeSession(session);
2912 }
2913
2914 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2915
2916 if (isNew || !SCProductEntryModelImpl.COLUMN_BITMASK_ENABLED) {
2917 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2918 }
2919
2920 else {
2921 if ((scProductEntryModelImpl.getColumnBitmask() &
2922 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2923 Object[] args = new Object[] {
2924 scProductEntryModelImpl.getOriginalGroupId()
2925 };
2926
2927 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2928 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2929 args);
2930
2931 args = new Object[] { scProductEntryModelImpl.getGroupId() };
2932
2933 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2934 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2935 args);
2936 }
2937
2938 if ((scProductEntryModelImpl.getColumnBitmask() &
2939 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
2940 Object[] args = new Object[] {
2941 scProductEntryModelImpl.getOriginalCompanyId()
2942 };
2943
2944 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2945 args);
2946 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2947 args);
2948
2949 args = new Object[] { scProductEntryModelImpl.getCompanyId() };
2950
2951 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2952 args);
2953 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2954 args);
2955 }
2956
2957 if ((scProductEntryModelImpl.getColumnBitmask() &
2958 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
2959 Object[] args = new Object[] {
2960 scProductEntryModelImpl.getOriginalGroupId(),
2961 scProductEntryModelImpl.getOriginalUserId()
2962 };
2963
2964 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
2965 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
2966 args);
2967
2968 args = new Object[] {
2969 scProductEntryModelImpl.getGroupId(),
2970 scProductEntryModelImpl.getUserId()
2971 };
2972
2973 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
2974 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
2975 args);
2976 }
2977 }
2978
2979 EntityCacheUtil.putResult(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
2980 SCProductEntryImpl.class, scProductEntry.getPrimaryKey(),
2981 scProductEntry, false);
2982
2983 clearUniqueFindersCache(scProductEntry);
2984 cacheUniqueFindersCache(scProductEntry);
2985
2986 scProductEntry.resetOriginalValues();
2987
2988 return scProductEntry;
2989 }
2990
2991 protected SCProductEntry toUnwrappedModel(SCProductEntry scProductEntry) {
2992 if (scProductEntry instanceof SCProductEntryImpl) {
2993 return scProductEntry;
2994 }
2995
2996 SCProductEntryImpl scProductEntryImpl = new SCProductEntryImpl();
2997
2998 scProductEntryImpl.setNew(scProductEntry.isNew());
2999 scProductEntryImpl.setPrimaryKey(scProductEntry.getPrimaryKey());
3000
3001 scProductEntryImpl.setProductEntryId(scProductEntry.getProductEntryId());
3002 scProductEntryImpl.setGroupId(scProductEntry.getGroupId());
3003 scProductEntryImpl.setCompanyId(scProductEntry.getCompanyId());
3004 scProductEntryImpl.setUserId(scProductEntry.getUserId());
3005 scProductEntryImpl.setUserName(scProductEntry.getUserName());
3006 scProductEntryImpl.setCreateDate(scProductEntry.getCreateDate());
3007 scProductEntryImpl.setModifiedDate(scProductEntry.getModifiedDate());
3008 scProductEntryImpl.setName(scProductEntry.getName());
3009 scProductEntryImpl.setType(scProductEntry.getType());
3010 scProductEntryImpl.setTags(scProductEntry.getTags());
3011 scProductEntryImpl.setShortDescription(scProductEntry.getShortDescription());
3012 scProductEntryImpl.setLongDescription(scProductEntry.getLongDescription());
3013 scProductEntryImpl.setPageURL(scProductEntry.getPageURL());
3014 scProductEntryImpl.setAuthor(scProductEntry.getAuthor());
3015 scProductEntryImpl.setRepoGroupId(scProductEntry.getRepoGroupId());
3016 scProductEntryImpl.setRepoArtifactId(scProductEntry.getRepoArtifactId());
3017
3018 return scProductEntryImpl;
3019 }
3020
3021
3028 @Override
3029 public SCProductEntry findByPrimaryKey(Serializable primaryKey)
3030 throws NoSuchProductEntryException {
3031 SCProductEntry scProductEntry = fetchByPrimaryKey(primaryKey);
3032
3033 if (scProductEntry == null) {
3034 if (_log.isWarnEnabled()) {
3035 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3036 }
3037
3038 throw new NoSuchProductEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3039 primaryKey);
3040 }
3041
3042 return scProductEntry;
3043 }
3044
3045
3052 @Override
3053 public SCProductEntry findByPrimaryKey(long productEntryId)
3054 throws NoSuchProductEntryException {
3055 return findByPrimaryKey((Serializable)productEntryId);
3056 }
3057
3058
3064 @Override
3065 public SCProductEntry fetchByPrimaryKey(Serializable primaryKey) {
3066 SCProductEntry scProductEntry = (SCProductEntry)EntityCacheUtil.getResult(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
3067 SCProductEntryImpl.class, primaryKey);
3068
3069 if (scProductEntry == _nullSCProductEntry) {
3070 return null;
3071 }
3072
3073 if (scProductEntry == null) {
3074 Session session = null;
3075
3076 try {
3077 session = openSession();
3078
3079 scProductEntry = (SCProductEntry)session.get(SCProductEntryImpl.class,
3080 primaryKey);
3081
3082 if (scProductEntry != null) {
3083 cacheResult(scProductEntry);
3084 }
3085 else {
3086 EntityCacheUtil.putResult(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
3087 SCProductEntryImpl.class, primaryKey,
3088 _nullSCProductEntry);
3089 }
3090 }
3091 catch (Exception e) {
3092 EntityCacheUtil.removeResult(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
3093 SCProductEntryImpl.class, primaryKey);
3094
3095 throw processException(e);
3096 }
3097 finally {
3098 closeSession(session);
3099 }
3100 }
3101
3102 return scProductEntry;
3103 }
3104
3105
3111 @Override
3112 public SCProductEntry fetchByPrimaryKey(long productEntryId) {
3113 return fetchByPrimaryKey((Serializable)productEntryId);
3114 }
3115
3116 @Override
3117 public Map<Serializable, SCProductEntry> fetchByPrimaryKeys(
3118 Set<Serializable> primaryKeys) {
3119 if (primaryKeys.isEmpty()) {
3120 return Collections.emptyMap();
3121 }
3122
3123 Map<Serializable, SCProductEntry> map = new HashMap<Serializable, SCProductEntry>();
3124
3125 if (primaryKeys.size() == 1) {
3126 Iterator<Serializable> iterator = primaryKeys.iterator();
3127
3128 Serializable primaryKey = iterator.next();
3129
3130 SCProductEntry scProductEntry = fetchByPrimaryKey(primaryKey);
3131
3132 if (scProductEntry != null) {
3133 map.put(primaryKey, scProductEntry);
3134 }
3135
3136 return map;
3137 }
3138
3139 Set<Serializable> uncachedPrimaryKeys = null;
3140
3141 for (Serializable primaryKey : primaryKeys) {
3142 SCProductEntry scProductEntry = (SCProductEntry)EntityCacheUtil.getResult(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
3143 SCProductEntryImpl.class, primaryKey);
3144
3145 if (scProductEntry == null) {
3146 if (uncachedPrimaryKeys == null) {
3147 uncachedPrimaryKeys = new HashSet<Serializable>();
3148 }
3149
3150 uncachedPrimaryKeys.add(primaryKey);
3151 }
3152 else {
3153 map.put(primaryKey, scProductEntry);
3154 }
3155 }
3156
3157 if (uncachedPrimaryKeys == null) {
3158 return map;
3159 }
3160
3161 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
3162 1);
3163
3164 query.append(_SQL_SELECT_SCPRODUCTENTRY_WHERE_PKS_IN);
3165
3166 for (Serializable primaryKey : uncachedPrimaryKeys) {
3167 query.append(String.valueOf(primaryKey));
3168
3169 query.append(StringPool.COMMA);
3170 }
3171
3172 query.setIndex(query.index() - 1);
3173
3174 query.append(StringPool.CLOSE_PARENTHESIS);
3175
3176 String sql = query.toString();
3177
3178 Session session = null;
3179
3180 try {
3181 session = openSession();
3182
3183 Query q = session.createQuery(sql);
3184
3185 for (SCProductEntry scProductEntry : (List<SCProductEntry>)q.list()) {
3186 map.put(scProductEntry.getPrimaryKeyObj(), scProductEntry);
3187
3188 cacheResult(scProductEntry);
3189
3190 uncachedPrimaryKeys.remove(scProductEntry.getPrimaryKeyObj());
3191 }
3192
3193 for (Serializable primaryKey : uncachedPrimaryKeys) {
3194 EntityCacheUtil.putResult(SCProductEntryModelImpl.ENTITY_CACHE_ENABLED,
3195 SCProductEntryImpl.class, primaryKey, _nullSCProductEntry);
3196 }
3197 }
3198 catch (Exception e) {
3199 throw processException(e);
3200 }
3201 finally {
3202 closeSession(session);
3203 }
3204
3205 return map;
3206 }
3207
3208
3213 @Override
3214 public List<SCProductEntry> findAll() {
3215 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3216 }
3217
3218
3229 @Override
3230 public List<SCProductEntry> findAll(int start, int end) {
3231 return findAll(start, end, null);
3232 }
3233
3234
3246 @Override
3247 public List<SCProductEntry> findAll(int start, int end,
3248 OrderByComparator<SCProductEntry> orderByComparator) {
3249 boolean pagination = true;
3250 FinderPath finderPath = null;
3251 Object[] finderArgs = null;
3252
3253 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3254 (orderByComparator == null)) {
3255 pagination = false;
3256 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3257 finderArgs = FINDER_ARGS_EMPTY;
3258 }
3259 else {
3260 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3261 finderArgs = new Object[] { start, end, orderByComparator };
3262 }
3263
3264 List<SCProductEntry> list = (List<SCProductEntry>)FinderCacheUtil.getResult(finderPath,
3265 finderArgs, this);
3266
3267 if (list == null) {
3268 StringBundler query = null;
3269 String sql = null;
3270
3271 if (orderByComparator != null) {
3272 query = new StringBundler(2 +
3273 (orderByComparator.getOrderByFields().length * 3));
3274
3275 query.append(_SQL_SELECT_SCPRODUCTENTRY);
3276
3277 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3278 orderByComparator);
3279
3280 sql = query.toString();
3281 }
3282 else {
3283 sql = _SQL_SELECT_SCPRODUCTENTRY;
3284
3285 if (pagination) {
3286 sql = sql.concat(SCProductEntryModelImpl.ORDER_BY_JPQL);
3287 }
3288 }
3289
3290 Session session = null;
3291
3292 try {
3293 session = openSession();
3294
3295 Query q = session.createQuery(sql);
3296
3297 if (!pagination) {
3298 list = (List<SCProductEntry>)QueryUtil.list(q,
3299 getDialect(), start, end, false);
3300
3301 Collections.sort(list);
3302
3303 list = Collections.unmodifiableList(list);
3304 }
3305 else {
3306 list = (List<SCProductEntry>)QueryUtil.list(q,
3307 getDialect(), start, end);
3308 }
3309
3310 cacheResult(list);
3311
3312 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3313 }
3314 catch (Exception e) {
3315 FinderCacheUtil.removeResult(finderPath, finderArgs);
3316
3317 throw processException(e);
3318 }
3319 finally {
3320 closeSession(session);
3321 }
3322 }
3323
3324 return list;
3325 }
3326
3327
3331 @Override
3332 public void removeAll() {
3333 for (SCProductEntry scProductEntry : findAll()) {
3334 remove(scProductEntry);
3335 }
3336 }
3337
3338
3343 @Override
3344 public int countAll() {
3345 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3346 FINDER_ARGS_EMPTY, this);
3347
3348 if (count == null) {
3349 Session session = null;
3350
3351 try {
3352 session = openSession();
3353
3354 Query q = session.createQuery(_SQL_COUNT_SCPRODUCTENTRY);
3355
3356 count = (Long)q.uniqueResult();
3357
3358 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3359 FINDER_ARGS_EMPTY, count);
3360 }
3361 catch (Exception e) {
3362 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3363 FINDER_ARGS_EMPTY);
3364
3365 throw processException(e);
3366 }
3367 finally {
3368 closeSession(session);
3369 }
3370 }
3371
3372 return count.intValue();
3373 }
3374
3375
3381 @Override
3382 public long[] getSCLicensePrimaryKeys(long pk) {
3383 long[] pks = scProductEntryToSCLicenseTableMapper.getRightPrimaryKeys(pk);
3384
3385 return pks.clone();
3386 }
3387
3388
3394 @Override
3395 public List<com.liferay.portlet.softwarecatalog.model.SCLicense> getSCLicenses(
3396 long pk) {
3397 return getSCLicenses(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3398 }
3399
3400
3412 @Override
3413 public List<com.liferay.portlet.softwarecatalog.model.SCLicense> getSCLicenses(
3414 long pk, int start, int end) {
3415 return getSCLicenses(pk, start, end, null);
3416 }
3417
3418
3431 @Override
3432 public List<com.liferay.portlet.softwarecatalog.model.SCLicense> getSCLicenses(
3433 long pk, int start, int end,
3434 OrderByComparator<com.liferay.portlet.softwarecatalog.model.SCLicense> orderByComparator) {
3435 return scProductEntryToSCLicenseTableMapper.getRightBaseModels(pk,
3436 start, end, orderByComparator);
3437 }
3438
3439
3445 @Override
3446 public int getSCLicensesSize(long pk) {
3447 long[] pks = scProductEntryToSCLicenseTableMapper.getRightPrimaryKeys(pk);
3448
3449 return pks.length;
3450 }
3451
3452
3459 @Override
3460 public boolean containsSCLicense(long pk, long scLicensePK) {
3461 return scProductEntryToSCLicenseTableMapper.containsTableMapping(pk,
3462 scLicensePK);
3463 }
3464
3465
3471 @Override
3472 public boolean containsSCLicenses(long pk) {
3473 if (getSCLicensesSize(pk) > 0) {
3474 return true;
3475 }
3476 else {
3477 return false;
3478 }
3479 }
3480
3481
3487 @Override
3488 public void addSCLicense(long pk, long scLicensePK) {
3489 scProductEntryToSCLicenseTableMapper.addTableMapping(pk, scLicensePK);
3490 }
3491
3492
3498 @Override
3499 public void addSCLicense(long pk,
3500 com.liferay.portlet.softwarecatalog.model.SCLicense scLicense) {
3501 scProductEntryToSCLicenseTableMapper.addTableMapping(pk,
3502 scLicense.getPrimaryKey());
3503 }
3504
3505
3511 @Override
3512 public void addSCLicenses(long pk, long[] scLicensePKs) {
3513 for (long scLicensePK : scLicensePKs) {
3514 scProductEntryToSCLicenseTableMapper.addTableMapping(pk, scLicensePK);
3515 }
3516 }
3517
3518
3524 @Override
3525 public void addSCLicenses(long pk,
3526 List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses) {
3527 for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
3528 scProductEntryToSCLicenseTableMapper.addTableMapping(pk,
3529 scLicense.getPrimaryKey());
3530 }
3531 }
3532
3533
3538 @Override
3539 public void clearSCLicenses(long pk) {
3540 scProductEntryToSCLicenseTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
3541 }
3542
3543
3549 @Override
3550 public void removeSCLicense(long pk, long scLicensePK) {
3551 scProductEntryToSCLicenseTableMapper.deleteTableMapping(pk, scLicensePK);
3552 }
3553
3554
3560 @Override
3561 public void removeSCLicense(long pk,
3562 com.liferay.portlet.softwarecatalog.model.SCLicense scLicense) {
3563 scProductEntryToSCLicenseTableMapper.deleteTableMapping(pk,
3564 scLicense.getPrimaryKey());
3565 }
3566
3567
3573 @Override
3574 public void removeSCLicenses(long pk, long[] scLicensePKs) {
3575 for (long scLicensePK : scLicensePKs) {
3576 scProductEntryToSCLicenseTableMapper.deleteTableMapping(pk,
3577 scLicensePK);
3578 }
3579 }
3580
3581
3587 @Override
3588 public void removeSCLicenses(long pk,
3589 List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses) {
3590 for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
3591 scProductEntryToSCLicenseTableMapper.deleteTableMapping(pk,
3592 scLicense.getPrimaryKey());
3593 }
3594 }
3595
3596
3602 @Override
3603 public void setSCLicenses(long pk, long[] scLicensePKs) {
3604 Set<Long> newSCLicensePKsSet = SetUtil.fromArray(scLicensePKs);
3605 Set<Long> oldSCLicensePKsSet = SetUtil.fromArray(scProductEntryToSCLicenseTableMapper.getRightPrimaryKeys(
3606 pk));
3607
3608 Set<Long> removeSCLicensePKsSet = new HashSet<Long>(oldSCLicensePKsSet);
3609
3610 removeSCLicensePKsSet.removeAll(newSCLicensePKsSet);
3611
3612 for (long removeSCLicensePK : removeSCLicensePKsSet) {
3613 scProductEntryToSCLicenseTableMapper.deleteTableMapping(pk,
3614 removeSCLicensePK);
3615 }
3616
3617 newSCLicensePKsSet.removeAll(oldSCLicensePKsSet);
3618
3619 for (long newSCLicensePK : newSCLicensePKsSet) {
3620 scProductEntryToSCLicenseTableMapper.addTableMapping(pk,
3621 newSCLicensePK);
3622 }
3623 }
3624
3625
3631 @Override
3632 public void setSCLicenses(long pk,
3633 List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses) {
3634 try {
3635 long[] scLicensePKs = new long[scLicenses.size()];
3636
3637 for (int i = 0; i < scLicenses.size(); i++) {
3638 com.liferay.portlet.softwarecatalog.model.SCLicense scLicense = scLicenses.get(i);
3639
3640 scLicensePKs[i] = scLicense.getPrimaryKey();
3641 }
3642
3643 setSCLicenses(pk, scLicensePKs);
3644 }
3645 catch (Exception e) {
3646 throw processException(e);
3647 }
3648 }
3649
3650 @Override
3651 protected Set<String> getBadColumnNames() {
3652 return _badColumnNames;
3653 }
3654
3655
3658 public void afterPropertiesSet() {
3659 scProductEntryToSCLicenseTableMapper = TableMapperFactory.getTableMapper("SCLicenses_SCProductEntries",
3660 "productEntryId", "licenseId", this, scLicensePersistence);
3661 }
3662
3663 public void destroy() {
3664 EntityCacheUtil.removeCache(SCProductEntryImpl.class.getName());
3665 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3666 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3667 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3668
3669 TableMapperFactory.removeTableMapper("SCLicenses_SCProductEntries");
3670 }
3671
3672 @BeanReference(type = SCLicensePersistence.class)
3673 protected SCLicensePersistence scLicensePersistence;
3674 protected TableMapper<SCProductEntry, com.liferay.portlet.softwarecatalog.model.SCLicense> scProductEntryToSCLicenseTableMapper;
3675 private static final String _SQL_SELECT_SCPRODUCTENTRY = "SELECT scProductEntry FROM SCProductEntry scProductEntry";
3676 private static final String _SQL_SELECT_SCPRODUCTENTRY_WHERE_PKS_IN = "SELECT scProductEntry FROM SCProductEntry scProductEntry WHERE productEntryId IN (";
3677 private static final String _SQL_SELECT_SCPRODUCTENTRY_WHERE = "SELECT scProductEntry FROM SCProductEntry scProductEntry WHERE ";
3678 private static final String _SQL_COUNT_SCPRODUCTENTRY = "SELECT COUNT(scProductEntry) FROM SCProductEntry scProductEntry";
3679 private static final String _SQL_COUNT_SCPRODUCTENTRY_WHERE = "SELECT COUNT(scProductEntry) FROM SCProductEntry scProductEntry WHERE ";
3680 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "scProductEntry.productEntryId";
3681 private static final String _FILTER_SQL_SELECT_SCPRODUCTENTRY_WHERE = "SELECT DISTINCT {scProductEntry.*} FROM SCProductEntry scProductEntry WHERE ";
3682 private static final String _FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_1 =
3683 "SELECT {SCProductEntry.*} FROM (SELECT DISTINCT scProductEntry.productEntryId FROM SCProductEntry scProductEntry WHERE ";
3684 private static final String _FILTER_SQL_SELECT_SCPRODUCTENTRY_NO_INLINE_DISTINCT_WHERE_2 =
3685 ") TEMP_TABLE INNER JOIN SCProductEntry ON TEMP_TABLE.productEntryId = SCProductEntry.productEntryId";
3686 private static final String _FILTER_SQL_COUNT_SCPRODUCTENTRY_WHERE = "SELECT COUNT(DISTINCT scProductEntry.productEntryId) AS COUNT_VALUE FROM SCProductEntry scProductEntry WHERE ";
3687 private static final String _FILTER_ENTITY_ALIAS = "scProductEntry";
3688 private static final String _FILTER_ENTITY_TABLE = "SCProductEntry";
3689 private static final String _ORDER_BY_ENTITY_ALIAS = "scProductEntry.";
3690 private static final String _ORDER_BY_ENTITY_TABLE = "SCProductEntry.";
3691 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SCProductEntry exists with the primary key ";
3692 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SCProductEntry exists with the key {";
3693 private static final Log _log = LogFactoryUtil.getLog(SCProductEntryPersistenceImpl.class);
3694 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3695 "type"
3696 });
3697 private static final SCProductEntry _nullSCProductEntry = new SCProductEntryImpl() {
3698 @Override
3699 public Object clone() {
3700 return this;
3701 }
3702
3703 @Override
3704 public CacheModel<SCProductEntry> toCacheModel() {
3705 return _nullSCProductEntryCacheModel;
3706 }
3707 };
3708
3709 private static final CacheModel<SCProductEntry> _nullSCProductEntryCacheModel =
3710 new CacheModel<SCProductEntry>() {
3711 @Override
3712 public SCProductEntry toEntityModel() {
3713 return _nullSCProductEntry;
3714 }
3715 };
3716 }