001
014
015 package com.liferay.portal.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.EntityCache;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCache;
023 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024 import com.liferay.portal.kernel.dao.orm.FinderPath;
025 import com.liferay.portal.kernel.dao.orm.Query;
026 import com.liferay.portal.kernel.dao.orm.QueryPos;
027 import com.liferay.portal.kernel.dao.orm.QueryUtil;
028 import com.liferay.portal.kernel.dao.orm.Session;
029 import com.liferay.portal.kernel.exception.NoSuchRepositoryEntryException;
030 import com.liferay.portal.kernel.log.Log;
031 import com.liferay.portal.kernel.log.LogFactoryUtil;
032 import com.liferay.portal.kernel.model.CacheModel;
033 import com.liferay.portal.kernel.model.MVCCModel;
034 import com.liferay.portal.kernel.model.RepositoryEntry;
035 import com.liferay.portal.kernel.service.ServiceContext;
036 import com.liferay.portal.kernel.service.ServiceContextThreadLocal;
037 import com.liferay.portal.kernel.service.persistence.CompanyProvider;
038 import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper;
039 import com.liferay.portal.kernel.service.persistence.RepositoryEntryPersistence;
040 import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
041 import com.liferay.portal.kernel.util.OrderByComparator;
042 import com.liferay.portal.kernel.util.SetUtil;
043 import com.liferay.portal.kernel.util.StringBundler;
044 import com.liferay.portal.kernel.util.StringPool;
045 import com.liferay.portal.kernel.util.Validator;
046 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
047 import com.liferay.portal.model.impl.RepositoryEntryImpl;
048 import com.liferay.portal.model.impl.RepositoryEntryModelImpl;
049
050 import java.io.Serializable;
051
052 import java.util.Collections;
053 import java.util.Date;
054 import java.util.HashMap;
055 import java.util.HashSet;
056 import java.util.Iterator;
057 import java.util.List;
058 import java.util.Map;
059 import java.util.Set;
060
061
073 @ProviderType
074 public class RepositoryEntryPersistenceImpl extends BasePersistenceImpl<RepositoryEntry>
075 implements RepositoryEntryPersistence {
076
081 public static final String FINDER_CLASS_NAME_ENTITY = RepositoryEntryImpl.class.getName();
082 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083 ".List1";
084 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
085 ".List2";
086 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
087 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
088 RepositoryEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
089 "findAll", new String[0]);
090 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
091 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
092 RepositoryEntryImpl.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
094 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
095 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
097 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
098 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
099 RepositoryEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
100 "findByUuid",
101 new String[] {
102 String.class.getName(),
103
104 Integer.class.getName(), Integer.class.getName(),
105 OrderByComparator.class.getName()
106 });
107 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
108 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
109 RepositoryEntryImpl.class,
110 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
111 new String[] { String.class.getName() },
112 RepositoryEntryModelImpl.UUID_COLUMN_BITMASK);
113 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
114 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
115 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
116 new String[] { String.class.getName() });
117
118
124 @Override
125 public List<RepositoryEntry> findByUuid(String uuid) {
126 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
127 }
128
129
141 @Override
142 public List<RepositoryEntry> findByUuid(String uuid, int start, int end) {
143 return findByUuid(uuid, start, end, null);
144 }
145
146
159 @Override
160 public List<RepositoryEntry> findByUuid(String uuid, int start, int end,
161 OrderByComparator<RepositoryEntry> orderByComparator) {
162 return findByUuid(uuid, start, end, orderByComparator, true);
163 }
164
165
179 @Override
180 public List<RepositoryEntry> findByUuid(String uuid, int start, int end,
181 OrderByComparator<RepositoryEntry> orderByComparator,
182 boolean retrieveFromCache) {
183 boolean pagination = true;
184 FinderPath finderPath = null;
185 Object[] finderArgs = null;
186
187 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
188 (orderByComparator == null)) {
189 pagination = false;
190 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
191 finderArgs = new Object[] { uuid };
192 }
193 else {
194 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
195 finderArgs = new Object[] { uuid, start, end, orderByComparator };
196 }
197
198 List<RepositoryEntry> list = null;
199
200 if (retrieveFromCache) {
201 list = (List<RepositoryEntry>)finderCache.getResult(finderPath,
202 finderArgs, this);
203
204 if ((list != null) && !list.isEmpty()) {
205 for (RepositoryEntry repositoryEntry : list) {
206 if (!Validator.equals(uuid, repositoryEntry.getUuid())) {
207 list = null;
208
209 break;
210 }
211 }
212 }
213 }
214
215 if (list == null) {
216 StringBundler query = null;
217
218 if (orderByComparator != null) {
219 query = new StringBundler(3 +
220 (orderByComparator.getOrderByFields().length * 2));
221 }
222 else {
223 query = new StringBundler(3);
224 }
225
226 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
227
228 boolean bindUuid = false;
229
230 if (uuid == null) {
231 query.append(_FINDER_COLUMN_UUID_UUID_1);
232 }
233 else if (uuid.equals(StringPool.BLANK)) {
234 query.append(_FINDER_COLUMN_UUID_UUID_3);
235 }
236 else {
237 bindUuid = true;
238
239 query.append(_FINDER_COLUMN_UUID_UUID_2);
240 }
241
242 if (orderByComparator != null) {
243 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
244 orderByComparator);
245 }
246 else
247 if (pagination) {
248 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
249 }
250
251 String sql = query.toString();
252
253 Session session = null;
254
255 try {
256 session = openSession();
257
258 Query q = session.createQuery(sql);
259
260 QueryPos qPos = QueryPos.getInstance(q);
261
262 if (bindUuid) {
263 qPos.add(uuid);
264 }
265
266 if (!pagination) {
267 list = (List<RepositoryEntry>)QueryUtil.list(q,
268 getDialect(), start, end, false);
269
270 Collections.sort(list);
271
272 list = Collections.unmodifiableList(list);
273 }
274 else {
275 list = (List<RepositoryEntry>)QueryUtil.list(q,
276 getDialect(), start, end);
277 }
278
279 cacheResult(list);
280
281 finderCache.putResult(finderPath, finderArgs, list);
282 }
283 catch (Exception e) {
284 finderCache.removeResult(finderPath, finderArgs);
285
286 throw processException(e);
287 }
288 finally {
289 closeSession(session);
290 }
291 }
292
293 return list;
294 }
295
296
304 @Override
305 public RepositoryEntry findByUuid_First(String uuid,
306 OrderByComparator<RepositoryEntry> orderByComparator)
307 throws NoSuchRepositoryEntryException {
308 RepositoryEntry repositoryEntry = fetchByUuid_First(uuid,
309 orderByComparator);
310
311 if (repositoryEntry != null) {
312 return repositoryEntry;
313 }
314
315 StringBundler msg = new StringBundler(4);
316
317 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
318
319 msg.append("uuid=");
320 msg.append(uuid);
321
322 msg.append(StringPool.CLOSE_CURLY_BRACE);
323
324 throw new NoSuchRepositoryEntryException(msg.toString());
325 }
326
327
334 @Override
335 public RepositoryEntry fetchByUuid_First(String uuid,
336 OrderByComparator<RepositoryEntry> orderByComparator) {
337 List<RepositoryEntry> list = findByUuid(uuid, 0, 1, orderByComparator);
338
339 if (!list.isEmpty()) {
340 return list.get(0);
341 }
342
343 return null;
344 }
345
346
354 @Override
355 public RepositoryEntry findByUuid_Last(String uuid,
356 OrderByComparator<RepositoryEntry> orderByComparator)
357 throws NoSuchRepositoryEntryException {
358 RepositoryEntry repositoryEntry = fetchByUuid_Last(uuid,
359 orderByComparator);
360
361 if (repositoryEntry != null) {
362 return repositoryEntry;
363 }
364
365 StringBundler msg = new StringBundler(4);
366
367 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
368
369 msg.append("uuid=");
370 msg.append(uuid);
371
372 msg.append(StringPool.CLOSE_CURLY_BRACE);
373
374 throw new NoSuchRepositoryEntryException(msg.toString());
375 }
376
377
384 @Override
385 public RepositoryEntry fetchByUuid_Last(String uuid,
386 OrderByComparator<RepositoryEntry> orderByComparator) {
387 int count = countByUuid(uuid);
388
389 if (count == 0) {
390 return null;
391 }
392
393 List<RepositoryEntry> list = findByUuid(uuid, count - 1, count,
394 orderByComparator);
395
396 if (!list.isEmpty()) {
397 return list.get(0);
398 }
399
400 return null;
401 }
402
403
412 @Override
413 public RepositoryEntry[] findByUuid_PrevAndNext(long repositoryEntryId,
414 String uuid, OrderByComparator<RepositoryEntry> orderByComparator)
415 throws NoSuchRepositoryEntryException {
416 RepositoryEntry repositoryEntry = findByPrimaryKey(repositoryEntryId);
417
418 Session session = null;
419
420 try {
421 session = openSession();
422
423 RepositoryEntry[] array = new RepositoryEntryImpl[3];
424
425 array[0] = getByUuid_PrevAndNext(session, repositoryEntry, uuid,
426 orderByComparator, true);
427
428 array[1] = repositoryEntry;
429
430 array[2] = getByUuid_PrevAndNext(session, repositoryEntry, uuid,
431 orderByComparator, false);
432
433 return array;
434 }
435 catch (Exception e) {
436 throw processException(e);
437 }
438 finally {
439 closeSession(session);
440 }
441 }
442
443 protected RepositoryEntry getByUuid_PrevAndNext(Session session,
444 RepositoryEntry repositoryEntry, String uuid,
445 OrderByComparator<RepositoryEntry> orderByComparator, boolean previous) {
446 StringBundler query = null;
447
448 if (orderByComparator != null) {
449 query = new StringBundler(4 +
450 (orderByComparator.getOrderByConditionFields().length * 3) +
451 (orderByComparator.getOrderByFields().length * 3));
452 }
453 else {
454 query = new StringBundler(3);
455 }
456
457 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
458
459 boolean bindUuid = false;
460
461 if (uuid == null) {
462 query.append(_FINDER_COLUMN_UUID_UUID_1);
463 }
464 else if (uuid.equals(StringPool.BLANK)) {
465 query.append(_FINDER_COLUMN_UUID_UUID_3);
466 }
467 else {
468 bindUuid = true;
469
470 query.append(_FINDER_COLUMN_UUID_UUID_2);
471 }
472
473 if (orderByComparator != null) {
474 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
475
476 if (orderByConditionFields.length > 0) {
477 query.append(WHERE_AND);
478 }
479
480 for (int i = 0; i < orderByConditionFields.length; i++) {
481 query.append(_ORDER_BY_ENTITY_ALIAS);
482 query.append(orderByConditionFields[i]);
483
484 if ((i + 1) < orderByConditionFields.length) {
485 if (orderByComparator.isAscending() ^ previous) {
486 query.append(WHERE_GREATER_THAN_HAS_NEXT);
487 }
488 else {
489 query.append(WHERE_LESSER_THAN_HAS_NEXT);
490 }
491 }
492 else {
493 if (orderByComparator.isAscending() ^ previous) {
494 query.append(WHERE_GREATER_THAN);
495 }
496 else {
497 query.append(WHERE_LESSER_THAN);
498 }
499 }
500 }
501
502 query.append(ORDER_BY_CLAUSE);
503
504 String[] orderByFields = orderByComparator.getOrderByFields();
505
506 for (int i = 0; i < orderByFields.length; i++) {
507 query.append(_ORDER_BY_ENTITY_ALIAS);
508 query.append(orderByFields[i]);
509
510 if ((i + 1) < orderByFields.length) {
511 if (orderByComparator.isAscending() ^ previous) {
512 query.append(ORDER_BY_ASC_HAS_NEXT);
513 }
514 else {
515 query.append(ORDER_BY_DESC_HAS_NEXT);
516 }
517 }
518 else {
519 if (orderByComparator.isAscending() ^ previous) {
520 query.append(ORDER_BY_ASC);
521 }
522 else {
523 query.append(ORDER_BY_DESC);
524 }
525 }
526 }
527 }
528 else {
529 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
530 }
531
532 String sql = query.toString();
533
534 Query q = session.createQuery(sql);
535
536 q.setFirstResult(0);
537 q.setMaxResults(2);
538
539 QueryPos qPos = QueryPos.getInstance(q);
540
541 if (bindUuid) {
542 qPos.add(uuid);
543 }
544
545 if (orderByComparator != null) {
546 Object[] values = orderByComparator.getOrderByConditionValues(repositoryEntry);
547
548 for (Object value : values) {
549 qPos.add(value);
550 }
551 }
552
553 List<RepositoryEntry> list = q.list();
554
555 if (list.size() == 2) {
556 return list.get(1);
557 }
558 else {
559 return null;
560 }
561 }
562
563
568 @Override
569 public void removeByUuid(String uuid) {
570 for (RepositoryEntry repositoryEntry : findByUuid(uuid,
571 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
572 remove(repositoryEntry);
573 }
574 }
575
576
582 @Override
583 public int countByUuid(String uuid) {
584 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
585
586 Object[] finderArgs = new Object[] { uuid };
587
588 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
589
590 if (count == null) {
591 StringBundler query = new StringBundler(2);
592
593 query.append(_SQL_COUNT_REPOSITORYENTRY_WHERE);
594
595 boolean bindUuid = false;
596
597 if (uuid == null) {
598 query.append(_FINDER_COLUMN_UUID_UUID_1);
599 }
600 else if (uuid.equals(StringPool.BLANK)) {
601 query.append(_FINDER_COLUMN_UUID_UUID_3);
602 }
603 else {
604 bindUuid = true;
605
606 query.append(_FINDER_COLUMN_UUID_UUID_2);
607 }
608
609 String sql = query.toString();
610
611 Session session = null;
612
613 try {
614 session = openSession();
615
616 Query q = session.createQuery(sql);
617
618 QueryPos qPos = QueryPos.getInstance(q);
619
620 if (bindUuid) {
621 qPos.add(uuid);
622 }
623
624 count = (Long)q.uniqueResult();
625
626 finderCache.putResult(finderPath, finderArgs, count);
627 }
628 catch (Exception e) {
629 finderCache.removeResult(finderPath, finderArgs);
630
631 throw processException(e);
632 }
633 finally {
634 closeSession(session);
635 }
636 }
637
638 return count.intValue();
639 }
640
641 private static final String _FINDER_COLUMN_UUID_UUID_1 = "repositoryEntry.uuid IS NULL";
642 private static final String _FINDER_COLUMN_UUID_UUID_2 = "repositoryEntry.uuid = ?";
643 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(repositoryEntry.uuid IS NULL OR repositoryEntry.uuid = '')";
644 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
645 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
646 RepositoryEntryImpl.class, FINDER_CLASS_NAME_ENTITY,
647 "fetchByUUID_G",
648 new String[] { String.class.getName(), Long.class.getName() },
649 RepositoryEntryModelImpl.UUID_COLUMN_BITMASK |
650 RepositoryEntryModelImpl.GROUPID_COLUMN_BITMASK);
651 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
652 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
653 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
654 new String[] { String.class.getName(), Long.class.getName() });
655
656
664 @Override
665 public RepositoryEntry findByUUID_G(String uuid, long groupId)
666 throws NoSuchRepositoryEntryException {
667 RepositoryEntry repositoryEntry = fetchByUUID_G(uuid, groupId);
668
669 if (repositoryEntry == null) {
670 StringBundler msg = new StringBundler(6);
671
672 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
673
674 msg.append("uuid=");
675 msg.append(uuid);
676
677 msg.append(", groupId=");
678 msg.append(groupId);
679
680 msg.append(StringPool.CLOSE_CURLY_BRACE);
681
682 if (_log.isWarnEnabled()) {
683 _log.warn(msg.toString());
684 }
685
686 throw new NoSuchRepositoryEntryException(msg.toString());
687 }
688
689 return repositoryEntry;
690 }
691
692
699 @Override
700 public RepositoryEntry fetchByUUID_G(String uuid, long groupId) {
701 return fetchByUUID_G(uuid, groupId, true);
702 }
703
704
712 @Override
713 public RepositoryEntry fetchByUUID_G(String uuid, long groupId,
714 boolean retrieveFromCache) {
715 Object[] finderArgs = new Object[] { uuid, groupId };
716
717 Object result = null;
718
719 if (retrieveFromCache) {
720 result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
721 finderArgs, this);
722 }
723
724 if (result instanceof RepositoryEntry) {
725 RepositoryEntry repositoryEntry = (RepositoryEntry)result;
726
727 if (!Validator.equals(uuid, repositoryEntry.getUuid()) ||
728 (groupId != repositoryEntry.getGroupId())) {
729 result = null;
730 }
731 }
732
733 if (result == null) {
734 StringBundler query = new StringBundler(4);
735
736 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
737
738 boolean bindUuid = false;
739
740 if (uuid == null) {
741 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
742 }
743 else if (uuid.equals(StringPool.BLANK)) {
744 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
745 }
746 else {
747 bindUuid = true;
748
749 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
750 }
751
752 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
753
754 String sql = query.toString();
755
756 Session session = null;
757
758 try {
759 session = openSession();
760
761 Query q = session.createQuery(sql);
762
763 QueryPos qPos = QueryPos.getInstance(q);
764
765 if (bindUuid) {
766 qPos.add(uuid);
767 }
768
769 qPos.add(groupId);
770
771 List<RepositoryEntry> list = q.list();
772
773 if (list.isEmpty()) {
774 finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
775 finderArgs, list);
776 }
777 else {
778 RepositoryEntry repositoryEntry = list.get(0);
779
780 result = repositoryEntry;
781
782 cacheResult(repositoryEntry);
783
784 if ((repositoryEntry.getUuid() == null) ||
785 !repositoryEntry.getUuid().equals(uuid) ||
786 (repositoryEntry.getGroupId() != groupId)) {
787 finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
788 finderArgs, repositoryEntry);
789 }
790 }
791 }
792 catch (Exception e) {
793 finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
794
795 throw processException(e);
796 }
797 finally {
798 closeSession(session);
799 }
800 }
801
802 if (result instanceof List<?>) {
803 return null;
804 }
805 else {
806 return (RepositoryEntry)result;
807 }
808 }
809
810
817 @Override
818 public RepositoryEntry removeByUUID_G(String uuid, long groupId)
819 throws NoSuchRepositoryEntryException {
820 RepositoryEntry repositoryEntry = findByUUID_G(uuid, groupId);
821
822 return remove(repositoryEntry);
823 }
824
825
832 @Override
833 public int countByUUID_G(String uuid, long groupId) {
834 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
835
836 Object[] finderArgs = new Object[] { uuid, groupId };
837
838 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
839
840 if (count == null) {
841 StringBundler query = new StringBundler(3);
842
843 query.append(_SQL_COUNT_REPOSITORYENTRY_WHERE);
844
845 boolean bindUuid = false;
846
847 if (uuid == null) {
848 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
849 }
850 else if (uuid.equals(StringPool.BLANK)) {
851 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
852 }
853 else {
854 bindUuid = true;
855
856 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
857 }
858
859 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
860
861 String sql = query.toString();
862
863 Session session = null;
864
865 try {
866 session = openSession();
867
868 Query q = session.createQuery(sql);
869
870 QueryPos qPos = QueryPos.getInstance(q);
871
872 if (bindUuid) {
873 qPos.add(uuid);
874 }
875
876 qPos.add(groupId);
877
878 count = (Long)q.uniqueResult();
879
880 finderCache.putResult(finderPath, finderArgs, count);
881 }
882 catch (Exception e) {
883 finderCache.removeResult(finderPath, finderArgs);
884
885 throw processException(e);
886 }
887 finally {
888 closeSession(session);
889 }
890 }
891
892 return count.intValue();
893 }
894
895 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "repositoryEntry.uuid IS NULL AND ";
896 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "repositoryEntry.uuid = ? AND ";
897 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(repositoryEntry.uuid IS NULL OR repositoryEntry.uuid = '') AND ";
898 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "repositoryEntry.groupId = ?";
899 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
900 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
901 RepositoryEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
902 "findByUuid_C",
903 new String[] {
904 String.class.getName(), Long.class.getName(),
905
906 Integer.class.getName(), Integer.class.getName(),
907 OrderByComparator.class.getName()
908 });
909 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
910 new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
911 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
912 RepositoryEntryImpl.class,
913 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
914 new String[] { String.class.getName(), Long.class.getName() },
915 RepositoryEntryModelImpl.UUID_COLUMN_BITMASK |
916 RepositoryEntryModelImpl.COMPANYID_COLUMN_BITMASK);
917 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
918 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
919 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
920 new String[] { String.class.getName(), Long.class.getName() });
921
922
929 @Override
930 public List<RepositoryEntry> findByUuid_C(String uuid, long companyId) {
931 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
932 QueryUtil.ALL_POS, null);
933 }
934
935
948 @Override
949 public List<RepositoryEntry> findByUuid_C(String uuid, long companyId,
950 int start, int end) {
951 return findByUuid_C(uuid, companyId, start, end, null);
952 }
953
954
968 @Override
969 public List<RepositoryEntry> findByUuid_C(String uuid, long companyId,
970 int start, int end, OrderByComparator<RepositoryEntry> orderByComparator) {
971 return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
972 }
973
974
989 @Override
990 public List<RepositoryEntry> findByUuid_C(String uuid, long companyId,
991 int start, int end,
992 OrderByComparator<RepositoryEntry> orderByComparator,
993 boolean retrieveFromCache) {
994 boolean pagination = true;
995 FinderPath finderPath = null;
996 Object[] finderArgs = null;
997
998 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
999 (orderByComparator == null)) {
1000 pagination = false;
1001 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1002 finderArgs = new Object[] { uuid, companyId };
1003 }
1004 else {
1005 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1006 finderArgs = new Object[] {
1007 uuid, companyId,
1008
1009 start, end, orderByComparator
1010 };
1011 }
1012
1013 List<RepositoryEntry> list = null;
1014
1015 if (retrieveFromCache) {
1016 list = (List<RepositoryEntry>)finderCache.getResult(finderPath,
1017 finderArgs, this);
1018
1019 if ((list != null) && !list.isEmpty()) {
1020 for (RepositoryEntry repositoryEntry : list) {
1021 if (!Validator.equals(uuid, repositoryEntry.getUuid()) ||
1022 (companyId != repositoryEntry.getCompanyId())) {
1023 list = null;
1024
1025 break;
1026 }
1027 }
1028 }
1029 }
1030
1031 if (list == null) {
1032 StringBundler query = null;
1033
1034 if (orderByComparator != null) {
1035 query = new StringBundler(4 +
1036 (orderByComparator.getOrderByFields().length * 2));
1037 }
1038 else {
1039 query = new StringBundler(4);
1040 }
1041
1042 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
1043
1044 boolean bindUuid = false;
1045
1046 if (uuid == null) {
1047 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1048 }
1049 else if (uuid.equals(StringPool.BLANK)) {
1050 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1051 }
1052 else {
1053 bindUuid = true;
1054
1055 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1056 }
1057
1058 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1059
1060 if (orderByComparator != null) {
1061 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1062 orderByComparator);
1063 }
1064 else
1065 if (pagination) {
1066 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
1067 }
1068
1069 String sql = query.toString();
1070
1071 Session session = null;
1072
1073 try {
1074 session = openSession();
1075
1076 Query q = session.createQuery(sql);
1077
1078 QueryPos qPos = QueryPos.getInstance(q);
1079
1080 if (bindUuid) {
1081 qPos.add(uuid);
1082 }
1083
1084 qPos.add(companyId);
1085
1086 if (!pagination) {
1087 list = (List<RepositoryEntry>)QueryUtil.list(q,
1088 getDialect(), start, end, false);
1089
1090 Collections.sort(list);
1091
1092 list = Collections.unmodifiableList(list);
1093 }
1094 else {
1095 list = (List<RepositoryEntry>)QueryUtil.list(q,
1096 getDialect(), start, end);
1097 }
1098
1099 cacheResult(list);
1100
1101 finderCache.putResult(finderPath, finderArgs, list);
1102 }
1103 catch (Exception e) {
1104 finderCache.removeResult(finderPath, finderArgs);
1105
1106 throw processException(e);
1107 }
1108 finally {
1109 closeSession(session);
1110 }
1111 }
1112
1113 return list;
1114 }
1115
1116
1125 @Override
1126 public RepositoryEntry findByUuid_C_First(String uuid, long companyId,
1127 OrderByComparator<RepositoryEntry> orderByComparator)
1128 throws NoSuchRepositoryEntryException {
1129 RepositoryEntry repositoryEntry = fetchByUuid_C_First(uuid, companyId,
1130 orderByComparator);
1131
1132 if (repositoryEntry != null) {
1133 return repositoryEntry;
1134 }
1135
1136 StringBundler msg = new StringBundler(6);
1137
1138 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1139
1140 msg.append("uuid=");
1141 msg.append(uuid);
1142
1143 msg.append(", companyId=");
1144 msg.append(companyId);
1145
1146 msg.append(StringPool.CLOSE_CURLY_BRACE);
1147
1148 throw new NoSuchRepositoryEntryException(msg.toString());
1149 }
1150
1151
1159 @Override
1160 public RepositoryEntry fetchByUuid_C_First(String uuid, long companyId,
1161 OrderByComparator<RepositoryEntry> orderByComparator) {
1162 List<RepositoryEntry> list = findByUuid_C(uuid, companyId, 0, 1,
1163 orderByComparator);
1164
1165 if (!list.isEmpty()) {
1166 return list.get(0);
1167 }
1168
1169 return null;
1170 }
1171
1172
1181 @Override
1182 public RepositoryEntry findByUuid_C_Last(String uuid, long companyId,
1183 OrderByComparator<RepositoryEntry> orderByComparator)
1184 throws NoSuchRepositoryEntryException {
1185 RepositoryEntry repositoryEntry = fetchByUuid_C_Last(uuid, companyId,
1186 orderByComparator);
1187
1188 if (repositoryEntry != null) {
1189 return repositoryEntry;
1190 }
1191
1192 StringBundler msg = new StringBundler(6);
1193
1194 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1195
1196 msg.append("uuid=");
1197 msg.append(uuid);
1198
1199 msg.append(", companyId=");
1200 msg.append(companyId);
1201
1202 msg.append(StringPool.CLOSE_CURLY_BRACE);
1203
1204 throw new NoSuchRepositoryEntryException(msg.toString());
1205 }
1206
1207
1215 @Override
1216 public RepositoryEntry fetchByUuid_C_Last(String uuid, long companyId,
1217 OrderByComparator<RepositoryEntry> orderByComparator) {
1218 int count = countByUuid_C(uuid, companyId);
1219
1220 if (count == 0) {
1221 return null;
1222 }
1223
1224 List<RepositoryEntry> list = findByUuid_C(uuid, companyId, count - 1,
1225 count, orderByComparator);
1226
1227 if (!list.isEmpty()) {
1228 return list.get(0);
1229 }
1230
1231 return null;
1232 }
1233
1234
1244 @Override
1245 public RepositoryEntry[] findByUuid_C_PrevAndNext(long repositoryEntryId,
1246 String uuid, long companyId,
1247 OrderByComparator<RepositoryEntry> orderByComparator)
1248 throws NoSuchRepositoryEntryException {
1249 RepositoryEntry repositoryEntry = findByPrimaryKey(repositoryEntryId);
1250
1251 Session session = null;
1252
1253 try {
1254 session = openSession();
1255
1256 RepositoryEntry[] array = new RepositoryEntryImpl[3];
1257
1258 array[0] = getByUuid_C_PrevAndNext(session, repositoryEntry, uuid,
1259 companyId, orderByComparator, true);
1260
1261 array[1] = repositoryEntry;
1262
1263 array[2] = getByUuid_C_PrevAndNext(session, repositoryEntry, uuid,
1264 companyId, orderByComparator, false);
1265
1266 return array;
1267 }
1268 catch (Exception e) {
1269 throw processException(e);
1270 }
1271 finally {
1272 closeSession(session);
1273 }
1274 }
1275
1276 protected RepositoryEntry getByUuid_C_PrevAndNext(Session session,
1277 RepositoryEntry repositoryEntry, String uuid, long companyId,
1278 OrderByComparator<RepositoryEntry> orderByComparator, boolean previous) {
1279 StringBundler query = null;
1280
1281 if (orderByComparator != null) {
1282 query = new StringBundler(5 +
1283 (orderByComparator.getOrderByConditionFields().length * 3) +
1284 (orderByComparator.getOrderByFields().length * 3));
1285 }
1286 else {
1287 query = new StringBundler(4);
1288 }
1289
1290 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
1291
1292 boolean bindUuid = false;
1293
1294 if (uuid == null) {
1295 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1296 }
1297 else if (uuid.equals(StringPool.BLANK)) {
1298 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1299 }
1300 else {
1301 bindUuid = true;
1302
1303 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1304 }
1305
1306 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1307
1308 if (orderByComparator != null) {
1309 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1310
1311 if (orderByConditionFields.length > 0) {
1312 query.append(WHERE_AND);
1313 }
1314
1315 for (int i = 0; i < orderByConditionFields.length; i++) {
1316 query.append(_ORDER_BY_ENTITY_ALIAS);
1317 query.append(orderByConditionFields[i]);
1318
1319 if ((i + 1) < orderByConditionFields.length) {
1320 if (orderByComparator.isAscending() ^ previous) {
1321 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1322 }
1323 else {
1324 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1325 }
1326 }
1327 else {
1328 if (orderByComparator.isAscending() ^ previous) {
1329 query.append(WHERE_GREATER_THAN);
1330 }
1331 else {
1332 query.append(WHERE_LESSER_THAN);
1333 }
1334 }
1335 }
1336
1337 query.append(ORDER_BY_CLAUSE);
1338
1339 String[] orderByFields = orderByComparator.getOrderByFields();
1340
1341 for (int i = 0; i < orderByFields.length; i++) {
1342 query.append(_ORDER_BY_ENTITY_ALIAS);
1343 query.append(orderByFields[i]);
1344
1345 if ((i + 1) < orderByFields.length) {
1346 if (orderByComparator.isAscending() ^ previous) {
1347 query.append(ORDER_BY_ASC_HAS_NEXT);
1348 }
1349 else {
1350 query.append(ORDER_BY_DESC_HAS_NEXT);
1351 }
1352 }
1353 else {
1354 if (orderByComparator.isAscending() ^ previous) {
1355 query.append(ORDER_BY_ASC);
1356 }
1357 else {
1358 query.append(ORDER_BY_DESC);
1359 }
1360 }
1361 }
1362 }
1363 else {
1364 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
1365 }
1366
1367 String sql = query.toString();
1368
1369 Query q = session.createQuery(sql);
1370
1371 q.setFirstResult(0);
1372 q.setMaxResults(2);
1373
1374 QueryPos qPos = QueryPos.getInstance(q);
1375
1376 if (bindUuid) {
1377 qPos.add(uuid);
1378 }
1379
1380 qPos.add(companyId);
1381
1382 if (orderByComparator != null) {
1383 Object[] values = orderByComparator.getOrderByConditionValues(repositoryEntry);
1384
1385 for (Object value : values) {
1386 qPos.add(value);
1387 }
1388 }
1389
1390 List<RepositoryEntry> list = q.list();
1391
1392 if (list.size() == 2) {
1393 return list.get(1);
1394 }
1395 else {
1396 return null;
1397 }
1398 }
1399
1400
1406 @Override
1407 public void removeByUuid_C(String uuid, long companyId) {
1408 for (RepositoryEntry repositoryEntry : findByUuid_C(uuid, companyId,
1409 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1410 remove(repositoryEntry);
1411 }
1412 }
1413
1414
1421 @Override
1422 public int countByUuid_C(String uuid, long companyId) {
1423 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1424
1425 Object[] finderArgs = new Object[] { uuid, companyId };
1426
1427 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1428
1429 if (count == null) {
1430 StringBundler query = new StringBundler(3);
1431
1432 query.append(_SQL_COUNT_REPOSITORYENTRY_WHERE);
1433
1434 boolean bindUuid = false;
1435
1436 if (uuid == null) {
1437 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1438 }
1439 else if (uuid.equals(StringPool.BLANK)) {
1440 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1441 }
1442 else {
1443 bindUuid = true;
1444
1445 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1446 }
1447
1448 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1449
1450 String sql = query.toString();
1451
1452 Session session = null;
1453
1454 try {
1455 session = openSession();
1456
1457 Query q = session.createQuery(sql);
1458
1459 QueryPos qPos = QueryPos.getInstance(q);
1460
1461 if (bindUuid) {
1462 qPos.add(uuid);
1463 }
1464
1465 qPos.add(companyId);
1466
1467 count = (Long)q.uniqueResult();
1468
1469 finderCache.putResult(finderPath, finderArgs, count);
1470 }
1471 catch (Exception e) {
1472 finderCache.removeResult(finderPath, finderArgs);
1473
1474 throw processException(e);
1475 }
1476 finally {
1477 closeSession(session);
1478 }
1479 }
1480
1481 return count.intValue();
1482 }
1483
1484 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "repositoryEntry.uuid IS NULL AND ";
1485 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "repositoryEntry.uuid = ? AND ";
1486 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(repositoryEntry.uuid IS NULL OR repositoryEntry.uuid = '') AND ";
1487 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "repositoryEntry.companyId = ?";
1488 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_REPOSITORYID =
1489 new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
1490 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
1491 RepositoryEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1492 "findByRepositoryId",
1493 new String[] {
1494 Long.class.getName(),
1495
1496 Integer.class.getName(), Integer.class.getName(),
1497 OrderByComparator.class.getName()
1498 });
1499 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID =
1500 new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
1501 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
1502 RepositoryEntryImpl.class,
1503 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRepositoryId",
1504 new String[] { Long.class.getName() },
1505 RepositoryEntryModelImpl.REPOSITORYID_COLUMN_BITMASK);
1506 public static final FinderPath FINDER_PATH_COUNT_BY_REPOSITORYID = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
1507 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1508 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRepositoryId",
1509 new String[] { Long.class.getName() });
1510
1511
1517 @Override
1518 public List<RepositoryEntry> findByRepositoryId(long repositoryId) {
1519 return findByRepositoryId(repositoryId, QueryUtil.ALL_POS,
1520 QueryUtil.ALL_POS, null);
1521 }
1522
1523
1535 @Override
1536 public List<RepositoryEntry> findByRepositoryId(long repositoryId,
1537 int start, int end) {
1538 return findByRepositoryId(repositoryId, start, end, null);
1539 }
1540
1541
1554 @Override
1555 public List<RepositoryEntry> findByRepositoryId(long repositoryId,
1556 int start, int end, OrderByComparator<RepositoryEntry> orderByComparator) {
1557 return findByRepositoryId(repositoryId, start, end, orderByComparator,
1558 true);
1559 }
1560
1561
1575 @Override
1576 public List<RepositoryEntry> findByRepositoryId(long repositoryId,
1577 int start, int end,
1578 OrderByComparator<RepositoryEntry> orderByComparator,
1579 boolean retrieveFromCache) {
1580 boolean pagination = true;
1581 FinderPath finderPath = null;
1582 Object[] finderArgs = null;
1583
1584 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1585 (orderByComparator == null)) {
1586 pagination = false;
1587 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID;
1588 finderArgs = new Object[] { repositoryId };
1589 }
1590 else {
1591 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_REPOSITORYID;
1592 finderArgs = new Object[] {
1593 repositoryId,
1594
1595 start, end, orderByComparator
1596 };
1597 }
1598
1599 List<RepositoryEntry> list = null;
1600
1601 if (retrieveFromCache) {
1602 list = (List<RepositoryEntry>)finderCache.getResult(finderPath,
1603 finderArgs, this);
1604
1605 if ((list != null) && !list.isEmpty()) {
1606 for (RepositoryEntry repositoryEntry : list) {
1607 if ((repositoryId != repositoryEntry.getRepositoryId())) {
1608 list = null;
1609
1610 break;
1611 }
1612 }
1613 }
1614 }
1615
1616 if (list == null) {
1617 StringBundler query = null;
1618
1619 if (orderByComparator != null) {
1620 query = new StringBundler(3 +
1621 (orderByComparator.getOrderByFields().length * 2));
1622 }
1623 else {
1624 query = new StringBundler(3);
1625 }
1626
1627 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
1628
1629 query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
1630
1631 if (orderByComparator != null) {
1632 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1633 orderByComparator);
1634 }
1635 else
1636 if (pagination) {
1637 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
1638 }
1639
1640 String sql = query.toString();
1641
1642 Session session = null;
1643
1644 try {
1645 session = openSession();
1646
1647 Query q = session.createQuery(sql);
1648
1649 QueryPos qPos = QueryPos.getInstance(q);
1650
1651 qPos.add(repositoryId);
1652
1653 if (!pagination) {
1654 list = (List<RepositoryEntry>)QueryUtil.list(q,
1655 getDialect(), start, end, false);
1656
1657 Collections.sort(list);
1658
1659 list = Collections.unmodifiableList(list);
1660 }
1661 else {
1662 list = (List<RepositoryEntry>)QueryUtil.list(q,
1663 getDialect(), start, end);
1664 }
1665
1666 cacheResult(list);
1667
1668 finderCache.putResult(finderPath, finderArgs, list);
1669 }
1670 catch (Exception e) {
1671 finderCache.removeResult(finderPath, finderArgs);
1672
1673 throw processException(e);
1674 }
1675 finally {
1676 closeSession(session);
1677 }
1678 }
1679
1680 return list;
1681 }
1682
1683
1691 @Override
1692 public RepositoryEntry findByRepositoryId_First(long repositoryId,
1693 OrderByComparator<RepositoryEntry> orderByComparator)
1694 throws NoSuchRepositoryEntryException {
1695 RepositoryEntry repositoryEntry = fetchByRepositoryId_First(repositoryId,
1696 orderByComparator);
1697
1698 if (repositoryEntry != null) {
1699 return repositoryEntry;
1700 }
1701
1702 StringBundler msg = new StringBundler(4);
1703
1704 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1705
1706 msg.append("repositoryId=");
1707 msg.append(repositoryId);
1708
1709 msg.append(StringPool.CLOSE_CURLY_BRACE);
1710
1711 throw new NoSuchRepositoryEntryException(msg.toString());
1712 }
1713
1714
1721 @Override
1722 public RepositoryEntry fetchByRepositoryId_First(long repositoryId,
1723 OrderByComparator<RepositoryEntry> orderByComparator) {
1724 List<RepositoryEntry> list = findByRepositoryId(repositoryId, 0, 1,
1725 orderByComparator);
1726
1727 if (!list.isEmpty()) {
1728 return list.get(0);
1729 }
1730
1731 return null;
1732 }
1733
1734
1742 @Override
1743 public RepositoryEntry findByRepositoryId_Last(long repositoryId,
1744 OrderByComparator<RepositoryEntry> orderByComparator)
1745 throws NoSuchRepositoryEntryException {
1746 RepositoryEntry repositoryEntry = fetchByRepositoryId_Last(repositoryId,
1747 orderByComparator);
1748
1749 if (repositoryEntry != null) {
1750 return repositoryEntry;
1751 }
1752
1753 StringBundler msg = new StringBundler(4);
1754
1755 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1756
1757 msg.append("repositoryId=");
1758 msg.append(repositoryId);
1759
1760 msg.append(StringPool.CLOSE_CURLY_BRACE);
1761
1762 throw new NoSuchRepositoryEntryException(msg.toString());
1763 }
1764
1765
1772 @Override
1773 public RepositoryEntry fetchByRepositoryId_Last(long repositoryId,
1774 OrderByComparator<RepositoryEntry> orderByComparator) {
1775 int count = countByRepositoryId(repositoryId);
1776
1777 if (count == 0) {
1778 return null;
1779 }
1780
1781 List<RepositoryEntry> list = findByRepositoryId(repositoryId,
1782 count - 1, count, orderByComparator);
1783
1784 if (!list.isEmpty()) {
1785 return list.get(0);
1786 }
1787
1788 return null;
1789 }
1790
1791
1800 @Override
1801 public RepositoryEntry[] findByRepositoryId_PrevAndNext(
1802 long repositoryEntryId, long repositoryId,
1803 OrderByComparator<RepositoryEntry> orderByComparator)
1804 throws NoSuchRepositoryEntryException {
1805 RepositoryEntry repositoryEntry = findByPrimaryKey(repositoryEntryId);
1806
1807 Session session = null;
1808
1809 try {
1810 session = openSession();
1811
1812 RepositoryEntry[] array = new RepositoryEntryImpl[3];
1813
1814 array[0] = getByRepositoryId_PrevAndNext(session, repositoryEntry,
1815 repositoryId, orderByComparator, true);
1816
1817 array[1] = repositoryEntry;
1818
1819 array[2] = getByRepositoryId_PrevAndNext(session, repositoryEntry,
1820 repositoryId, orderByComparator, false);
1821
1822 return array;
1823 }
1824 catch (Exception e) {
1825 throw processException(e);
1826 }
1827 finally {
1828 closeSession(session);
1829 }
1830 }
1831
1832 protected RepositoryEntry getByRepositoryId_PrevAndNext(Session session,
1833 RepositoryEntry repositoryEntry, long repositoryId,
1834 OrderByComparator<RepositoryEntry> orderByComparator, boolean previous) {
1835 StringBundler query = null;
1836
1837 if (orderByComparator != null) {
1838 query = new StringBundler(4 +
1839 (orderByComparator.getOrderByConditionFields().length * 3) +
1840 (orderByComparator.getOrderByFields().length * 3));
1841 }
1842 else {
1843 query = new StringBundler(3);
1844 }
1845
1846 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
1847
1848 query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
1849
1850 if (orderByComparator != null) {
1851 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1852
1853 if (orderByConditionFields.length > 0) {
1854 query.append(WHERE_AND);
1855 }
1856
1857 for (int i = 0; i < orderByConditionFields.length; i++) {
1858 query.append(_ORDER_BY_ENTITY_ALIAS);
1859 query.append(orderByConditionFields[i]);
1860
1861 if ((i + 1) < orderByConditionFields.length) {
1862 if (orderByComparator.isAscending() ^ previous) {
1863 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1864 }
1865 else {
1866 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1867 }
1868 }
1869 else {
1870 if (orderByComparator.isAscending() ^ previous) {
1871 query.append(WHERE_GREATER_THAN);
1872 }
1873 else {
1874 query.append(WHERE_LESSER_THAN);
1875 }
1876 }
1877 }
1878
1879 query.append(ORDER_BY_CLAUSE);
1880
1881 String[] orderByFields = orderByComparator.getOrderByFields();
1882
1883 for (int i = 0; i < orderByFields.length; i++) {
1884 query.append(_ORDER_BY_ENTITY_ALIAS);
1885 query.append(orderByFields[i]);
1886
1887 if ((i + 1) < orderByFields.length) {
1888 if (orderByComparator.isAscending() ^ previous) {
1889 query.append(ORDER_BY_ASC_HAS_NEXT);
1890 }
1891 else {
1892 query.append(ORDER_BY_DESC_HAS_NEXT);
1893 }
1894 }
1895 else {
1896 if (orderByComparator.isAscending() ^ previous) {
1897 query.append(ORDER_BY_ASC);
1898 }
1899 else {
1900 query.append(ORDER_BY_DESC);
1901 }
1902 }
1903 }
1904 }
1905 else {
1906 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
1907 }
1908
1909 String sql = query.toString();
1910
1911 Query q = session.createQuery(sql);
1912
1913 q.setFirstResult(0);
1914 q.setMaxResults(2);
1915
1916 QueryPos qPos = QueryPos.getInstance(q);
1917
1918 qPos.add(repositoryId);
1919
1920 if (orderByComparator != null) {
1921 Object[] values = orderByComparator.getOrderByConditionValues(repositoryEntry);
1922
1923 for (Object value : values) {
1924 qPos.add(value);
1925 }
1926 }
1927
1928 List<RepositoryEntry> list = q.list();
1929
1930 if (list.size() == 2) {
1931 return list.get(1);
1932 }
1933 else {
1934 return null;
1935 }
1936 }
1937
1938
1943 @Override
1944 public void removeByRepositoryId(long repositoryId) {
1945 for (RepositoryEntry repositoryEntry : findByRepositoryId(
1946 repositoryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1947 remove(repositoryEntry);
1948 }
1949 }
1950
1951
1957 @Override
1958 public int countByRepositoryId(long repositoryId) {
1959 FinderPath finderPath = FINDER_PATH_COUNT_BY_REPOSITORYID;
1960
1961 Object[] finderArgs = new Object[] { repositoryId };
1962
1963 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1964
1965 if (count == null) {
1966 StringBundler query = new StringBundler(2);
1967
1968 query.append(_SQL_COUNT_REPOSITORYENTRY_WHERE);
1969
1970 query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
1971
1972 String sql = query.toString();
1973
1974 Session session = null;
1975
1976 try {
1977 session = openSession();
1978
1979 Query q = session.createQuery(sql);
1980
1981 QueryPos qPos = QueryPos.getInstance(q);
1982
1983 qPos.add(repositoryId);
1984
1985 count = (Long)q.uniqueResult();
1986
1987 finderCache.putResult(finderPath, finderArgs, count);
1988 }
1989 catch (Exception e) {
1990 finderCache.removeResult(finderPath, finderArgs);
1991
1992 throw processException(e);
1993 }
1994 finally {
1995 closeSession(session);
1996 }
1997 }
1998
1999 return count.intValue();
2000 }
2001
2002 private static final String _FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2 = "repositoryEntry.repositoryId = ?";
2003 public static final FinderPath FINDER_PATH_FETCH_BY_R_M = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2004 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
2005 RepositoryEntryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByR_M",
2006 new String[] { Long.class.getName(), String.class.getName() },
2007 RepositoryEntryModelImpl.REPOSITORYID_COLUMN_BITMASK |
2008 RepositoryEntryModelImpl.MAPPEDID_COLUMN_BITMASK);
2009 public static final FinderPath FINDER_PATH_COUNT_BY_R_M = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2010 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2011 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_M",
2012 new String[] { Long.class.getName(), String.class.getName() });
2013
2014
2022 @Override
2023 public RepositoryEntry findByR_M(long repositoryId, String mappedId)
2024 throws NoSuchRepositoryEntryException {
2025 RepositoryEntry repositoryEntry = fetchByR_M(repositoryId, mappedId);
2026
2027 if (repositoryEntry == null) {
2028 StringBundler msg = new StringBundler(6);
2029
2030 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2031
2032 msg.append("repositoryId=");
2033 msg.append(repositoryId);
2034
2035 msg.append(", mappedId=");
2036 msg.append(mappedId);
2037
2038 msg.append(StringPool.CLOSE_CURLY_BRACE);
2039
2040 if (_log.isWarnEnabled()) {
2041 _log.warn(msg.toString());
2042 }
2043
2044 throw new NoSuchRepositoryEntryException(msg.toString());
2045 }
2046
2047 return repositoryEntry;
2048 }
2049
2050
2057 @Override
2058 public RepositoryEntry fetchByR_M(long repositoryId, String mappedId) {
2059 return fetchByR_M(repositoryId, mappedId, true);
2060 }
2061
2062
2070 @Override
2071 public RepositoryEntry fetchByR_M(long repositoryId, String mappedId,
2072 boolean retrieveFromCache) {
2073 Object[] finderArgs = new Object[] { repositoryId, mappedId };
2074
2075 Object result = null;
2076
2077 if (retrieveFromCache) {
2078 result = finderCache.getResult(FINDER_PATH_FETCH_BY_R_M,
2079 finderArgs, this);
2080 }
2081
2082 if (result instanceof RepositoryEntry) {
2083 RepositoryEntry repositoryEntry = (RepositoryEntry)result;
2084
2085 if ((repositoryId != repositoryEntry.getRepositoryId()) ||
2086 !Validator.equals(mappedId, repositoryEntry.getMappedId())) {
2087 result = null;
2088 }
2089 }
2090
2091 if (result == null) {
2092 StringBundler query = new StringBundler(4);
2093
2094 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
2095
2096 query.append(_FINDER_COLUMN_R_M_REPOSITORYID_2);
2097
2098 boolean bindMappedId = false;
2099
2100 if (mappedId == null) {
2101 query.append(_FINDER_COLUMN_R_M_MAPPEDID_1);
2102 }
2103 else if (mappedId.equals(StringPool.BLANK)) {
2104 query.append(_FINDER_COLUMN_R_M_MAPPEDID_3);
2105 }
2106 else {
2107 bindMappedId = true;
2108
2109 query.append(_FINDER_COLUMN_R_M_MAPPEDID_2);
2110 }
2111
2112 String sql = query.toString();
2113
2114 Session session = null;
2115
2116 try {
2117 session = openSession();
2118
2119 Query q = session.createQuery(sql);
2120
2121 QueryPos qPos = QueryPos.getInstance(q);
2122
2123 qPos.add(repositoryId);
2124
2125 if (bindMappedId) {
2126 qPos.add(mappedId);
2127 }
2128
2129 List<RepositoryEntry> list = q.list();
2130
2131 if (list.isEmpty()) {
2132 finderCache.putResult(FINDER_PATH_FETCH_BY_R_M, finderArgs,
2133 list);
2134 }
2135 else {
2136 RepositoryEntry repositoryEntry = list.get(0);
2137
2138 result = repositoryEntry;
2139
2140 cacheResult(repositoryEntry);
2141
2142 if ((repositoryEntry.getRepositoryId() != repositoryId) ||
2143 (repositoryEntry.getMappedId() == null) ||
2144 !repositoryEntry.getMappedId().equals(mappedId)) {
2145 finderCache.putResult(FINDER_PATH_FETCH_BY_R_M,
2146 finderArgs, repositoryEntry);
2147 }
2148 }
2149 }
2150 catch (Exception e) {
2151 finderCache.removeResult(FINDER_PATH_FETCH_BY_R_M, finderArgs);
2152
2153 throw processException(e);
2154 }
2155 finally {
2156 closeSession(session);
2157 }
2158 }
2159
2160 if (result instanceof List<?>) {
2161 return null;
2162 }
2163 else {
2164 return (RepositoryEntry)result;
2165 }
2166 }
2167
2168
2175 @Override
2176 public RepositoryEntry removeByR_M(long repositoryId, String mappedId)
2177 throws NoSuchRepositoryEntryException {
2178 RepositoryEntry repositoryEntry = findByR_M(repositoryId, mappedId);
2179
2180 return remove(repositoryEntry);
2181 }
2182
2183
2190 @Override
2191 public int countByR_M(long repositoryId, String mappedId) {
2192 FinderPath finderPath = FINDER_PATH_COUNT_BY_R_M;
2193
2194 Object[] finderArgs = new Object[] { repositoryId, mappedId };
2195
2196 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2197
2198 if (count == null) {
2199 StringBundler query = new StringBundler(3);
2200
2201 query.append(_SQL_COUNT_REPOSITORYENTRY_WHERE);
2202
2203 query.append(_FINDER_COLUMN_R_M_REPOSITORYID_2);
2204
2205 boolean bindMappedId = false;
2206
2207 if (mappedId == null) {
2208 query.append(_FINDER_COLUMN_R_M_MAPPEDID_1);
2209 }
2210 else if (mappedId.equals(StringPool.BLANK)) {
2211 query.append(_FINDER_COLUMN_R_M_MAPPEDID_3);
2212 }
2213 else {
2214 bindMappedId = true;
2215
2216 query.append(_FINDER_COLUMN_R_M_MAPPEDID_2);
2217 }
2218
2219 String sql = query.toString();
2220
2221 Session session = null;
2222
2223 try {
2224 session = openSession();
2225
2226 Query q = session.createQuery(sql);
2227
2228 QueryPos qPos = QueryPos.getInstance(q);
2229
2230 qPos.add(repositoryId);
2231
2232 if (bindMappedId) {
2233 qPos.add(mappedId);
2234 }
2235
2236 count = (Long)q.uniqueResult();
2237
2238 finderCache.putResult(finderPath, finderArgs, count);
2239 }
2240 catch (Exception e) {
2241 finderCache.removeResult(finderPath, finderArgs);
2242
2243 throw processException(e);
2244 }
2245 finally {
2246 closeSession(session);
2247 }
2248 }
2249
2250 return count.intValue();
2251 }
2252
2253 private static final String _FINDER_COLUMN_R_M_REPOSITORYID_2 = "repositoryEntry.repositoryId = ? AND ";
2254 private static final String _FINDER_COLUMN_R_M_MAPPEDID_1 = "repositoryEntry.mappedId IS NULL";
2255 private static final String _FINDER_COLUMN_R_M_MAPPEDID_2 = "repositoryEntry.mappedId = ?";
2256 private static final String _FINDER_COLUMN_R_M_MAPPEDID_3 = "(repositoryEntry.mappedId IS NULL OR repositoryEntry.mappedId = '')";
2257
2258 public RepositoryEntryPersistenceImpl() {
2259 setModelClass(RepositoryEntry.class);
2260 }
2261
2262
2267 @Override
2268 public void cacheResult(RepositoryEntry repositoryEntry) {
2269 entityCache.putResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2270 RepositoryEntryImpl.class, repositoryEntry.getPrimaryKey(),
2271 repositoryEntry);
2272
2273 finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2274 new Object[] { repositoryEntry.getUuid(), repositoryEntry.getGroupId() },
2275 repositoryEntry);
2276
2277 finderCache.putResult(FINDER_PATH_FETCH_BY_R_M,
2278 new Object[] {
2279 repositoryEntry.getRepositoryId(), repositoryEntry.getMappedId()
2280 }, repositoryEntry);
2281
2282 repositoryEntry.resetOriginalValues();
2283 }
2284
2285
2290 @Override
2291 public void cacheResult(List<RepositoryEntry> repositoryEntries) {
2292 for (RepositoryEntry repositoryEntry : repositoryEntries) {
2293 if (entityCache.getResult(
2294 RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2295 RepositoryEntryImpl.class,
2296 repositoryEntry.getPrimaryKey()) == null) {
2297 cacheResult(repositoryEntry);
2298 }
2299 else {
2300 repositoryEntry.resetOriginalValues();
2301 }
2302 }
2303 }
2304
2305
2312 @Override
2313 public void clearCache() {
2314 entityCache.clearCache(RepositoryEntryImpl.class);
2315
2316 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
2317 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2318 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2319 }
2320
2321
2328 @Override
2329 public void clearCache(RepositoryEntry repositoryEntry) {
2330 entityCache.removeResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2331 RepositoryEntryImpl.class, repositoryEntry.getPrimaryKey());
2332
2333 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2334 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2335
2336 clearUniqueFindersCache((RepositoryEntryModelImpl)repositoryEntry);
2337 }
2338
2339 @Override
2340 public void clearCache(List<RepositoryEntry> repositoryEntries) {
2341 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2342 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2343
2344 for (RepositoryEntry repositoryEntry : repositoryEntries) {
2345 entityCache.removeResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2346 RepositoryEntryImpl.class, repositoryEntry.getPrimaryKey());
2347
2348 clearUniqueFindersCache((RepositoryEntryModelImpl)repositoryEntry);
2349 }
2350 }
2351
2352 protected void cacheUniqueFindersCache(
2353 RepositoryEntryModelImpl repositoryEntryModelImpl, boolean isNew) {
2354 if (isNew) {
2355 Object[] args = new Object[] {
2356 repositoryEntryModelImpl.getUuid(),
2357 repositoryEntryModelImpl.getGroupId()
2358 };
2359
2360 finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2361 Long.valueOf(1));
2362 finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2363 repositoryEntryModelImpl);
2364
2365 args = new Object[] {
2366 repositoryEntryModelImpl.getRepositoryId(),
2367 repositoryEntryModelImpl.getMappedId()
2368 };
2369
2370 finderCache.putResult(FINDER_PATH_COUNT_BY_R_M, args,
2371 Long.valueOf(1));
2372 finderCache.putResult(FINDER_PATH_FETCH_BY_R_M, args,
2373 repositoryEntryModelImpl);
2374 }
2375 else {
2376 if ((repositoryEntryModelImpl.getColumnBitmask() &
2377 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2378 Object[] args = new Object[] {
2379 repositoryEntryModelImpl.getUuid(),
2380 repositoryEntryModelImpl.getGroupId()
2381 };
2382
2383 finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2384 Long.valueOf(1));
2385 finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2386 repositoryEntryModelImpl);
2387 }
2388
2389 if ((repositoryEntryModelImpl.getColumnBitmask() &
2390 FINDER_PATH_FETCH_BY_R_M.getColumnBitmask()) != 0) {
2391 Object[] args = new Object[] {
2392 repositoryEntryModelImpl.getRepositoryId(),
2393 repositoryEntryModelImpl.getMappedId()
2394 };
2395
2396 finderCache.putResult(FINDER_PATH_COUNT_BY_R_M, args,
2397 Long.valueOf(1));
2398 finderCache.putResult(FINDER_PATH_FETCH_BY_R_M, args,
2399 repositoryEntryModelImpl);
2400 }
2401 }
2402 }
2403
2404 protected void clearUniqueFindersCache(
2405 RepositoryEntryModelImpl repositoryEntryModelImpl) {
2406 Object[] args = new Object[] {
2407 repositoryEntryModelImpl.getUuid(),
2408 repositoryEntryModelImpl.getGroupId()
2409 };
2410
2411 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2412 finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2413
2414 if ((repositoryEntryModelImpl.getColumnBitmask() &
2415 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2416 args = new Object[] {
2417 repositoryEntryModelImpl.getOriginalUuid(),
2418 repositoryEntryModelImpl.getOriginalGroupId()
2419 };
2420
2421 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2422 finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2423 }
2424
2425 args = new Object[] {
2426 repositoryEntryModelImpl.getRepositoryId(),
2427 repositoryEntryModelImpl.getMappedId()
2428 };
2429
2430 finderCache.removeResult(FINDER_PATH_COUNT_BY_R_M, args);
2431 finderCache.removeResult(FINDER_PATH_FETCH_BY_R_M, args);
2432
2433 if ((repositoryEntryModelImpl.getColumnBitmask() &
2434 FINDER_PATH_FETCH_BY_R_M.getColumnBitmask()) != 0) {
2435 args = new Object[] {
2436 repositoryEntryModelImpl.getOriginalRepositoryId(),
2437 repositoryEntryModelImpl.getOriginalMappedId()
2438 };
2439
2440 finderCache.removeResult(FINDER_PATH_COUNT_BY_R_M, args);
2441 finderCache.removeResult(FINDER_PATH_FETCH_BY_R_M, args);
2442 }
2443 }
2444
2445
2451 @Override
2452 public RepositoryEntry create(long repositoryEntryId) {
2453 RepositoryEntry repositoryEntry = new RepositoryEntryImpl();
2454
2455 repositoryEntry.setNew(true);
2456 repositoryEntry.setPrimaryKey(repositoryEntryId);
2457
2458 String uuid = PortalUUIDUtil.generate();
2459
2460 repositoryEntry.setUuid(uuid);
2461
2462 repositoryEntry.setCompanyId(companyProvider.getCompanyId());
2463
2464 return repositoryEntry;
2465 }
2466
2467
2474 @Override
2475 public RepositoryEntry remove(long repositoryEntryId)
2476 throws NoSuchRepositoryEntryException {
2477 return remove((Serializable)repositoryEntryId);
2478 }
2479
2480
2487 @Override
2488 public RepositoryEntry remove(Serializable primaryKey)
2489 throws NoSuchRepositoryEntryException {
2490 Session session = null;
2491
2492 try {
2493 session = openSession();
2494
2495 RepositoryEntry repositoryEntry = (RepositoryEntry)session.get(RepositoryEntryImpl.class,
2496 primaryKey);
2497
2498 if (repositoryEntry == null) {
2499 if (_log.isWarnEnabled()) {
2500 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2501 }
2502
2503 throw new NoSuchRepositoryEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2504 primaryKey);
2505 }
2506
2507 return remove(repositoryEntry);
2508 }
2509 catch (NoSuchRepositoryEntryException nsee) {
2510 throw nsee;
2511 }
2512 catch (Exception e) {
2513 throw processException(e);
2514 }
2515 finally {
2516 closeSession(session);
2517 }
2518 }
2519
2520 @Override
2521 protected RepositoryEntry removeImpl(RepositoryEntry repositoryEntry) {
2522 repositoryEntry = toUnwrappedModel(repositoryEntry);
2523
2524 Session session = null;
2525
2526 try {
2527 session = openSession();
2528
2529 if (!session.contains(repositoryEntry)) {
2530 repositoryEntry = (RepositoryEntry)session.get(RepositoryEntryImpl.class,
2531 repositoryEntry.getPrimaryKeyObj());
2532 }
2533
2534 if (repositoryEntry != null) {
2535 session.delete(repositoryEntry);
2536 }
2537 }
2538 catch (Exception e) {
2539 throw processException(e);
2540 }
2541 finally {
2542 closeSession(session);
2543 }
2544
2545 if (repositoryEntry != null) {
2546 clearCache(repositoryEntry);
2547 }
2548
2549 return repositoryEntry;
2550 }
2551
2552 @Override
2553 public RepositoryEntry updateImpl(RepositoryEntry repositoryEntry) {
2554 repositoryEntry = toUnwrappedModel(repositoryEntry);
2555
2556 boolean isNew = repositoryEntry.isNew();
2557
2558 RepositoryEntryModelImpl repositoryEntryModelImpl = (RepositoryEntryModelImpl)repositoryEntry;
2559
2560 if (Validator.isNull(repositoryEntry.getUuid())) {
2561 String uuid = PortalUUIDUtil.generate();
2562
2563 repositoryEntry.setUuid(uuid);
2564 }
2565
2566 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
2567
2568 Date now = new Date();
2569
2570 if (isNew && (repositoryEntry.getCreateDate() == null)) {
2571 if (serviceContext == null) {
2572 repositoryEntry.setCreateDate(now);
2573 }
2574 else {
2575 repositoryEntry.setCreateDate(serviceContext.getCreateDate(now));
2576 }
2577 }
2578
2579 if (!repositoryEntryModelImpl.hasSetModifiedDate()) {
2580 if (serviceContext == null) {
2581 repositoryEntry.setModifiedDate(now);
2582 }
2583 else {
2584 repositoryEntry.setModifiedDate(serviceContext.getModifiedDate(
2585 now));
2586 }
2587 }
2588
2589 Session session = null;
2590
2591 try {
2592 session = openSession();
2593
2594 if (repositoryEntry.isNew()) {
2595 session.save(repositoryEntry);
2596
2597 repositoryEntry.setNew(false);
2598 }
2599 else {
2600 repositoryEntry = (RepositoryEntry)session.merge(repositoryEntry);
2601 }
2602 }
2603 catch (Exception e) {
2604 throw processException(e);
2605 }
2606 finally {
2607 closeSession(session);
2608 }
2609
2610 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2611
2612 if (isNew || !RepositoryEntryModelImpl.COLUMN_BITMASK_ENABLED) {
2613 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2614 }
2615
2616 else {
2617 if ((repositoryEntryModelImpl.getColumnBitmask() &
2618 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2619 Object[] args = new Object[] {
2620 repositoryEntryModelImpl.getOriginalUuid()
2621 };
2622
2623 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2624 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2625 args);
2626
2627 args = new Object[] { repositoryEntryModelImpl.getUuid() };
2628
2629 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2630 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2631 args);
2632 }
2633
2634 if ((repositoryEntryModelImpl.getColumnBitmask() &
2635 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2636 Object[] args = new Object[] {
2637 repositoryEntryModelImpl.getOriginalUuid(),
2638 repositoryEntryModelImpl.getOriginalCompanyId()
2639 };
2640
2641 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2642 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2643 args);
2644
2645 args = new Object[] {
2646 repositoryEntryModelImpl.getUuid(),
2647 repositoryEntryModelImpl.getCompanyId()
2648 };
2649
2650 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2651 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2652 args);
2653 }
2654
2655 if ((repositoryEntryModelImpl.getColumnBitmask() &
2656 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID.getColumnBitmask()) != 0) {
2657 Object[] args = new Object[] {
2658 repositoryEntryModelImpl.getOriginalRepositoryId()
2659 };
2660
2661 finderCache.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args);
2662 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID,
2663 args);
2664
2665 args = new Object[] { repositoryEntryModelImpl.getRepositoryId() };
2666
2667 finderCache.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID, args);
2668 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID,
2669 args);
2670 }
2671 }
2672
2673 entityCache.putResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2674 RepositoryEntryImpl.class, repositoryEntry.getPrimaryKey(),
2675 repositoryEntry, false);
2676
2677 clearUniqueFindersCache(repositoryEntryModelImpl);
2678 cacheUniqueFindersCache(repositoryEntryModelImpl, isNew);
2679
2680 repositoryEntry.resetOriginalValues();
2681
2682 return repositoryEntry;
2683 }
2684
2685 protected RepositoryEntry toUnwrappedModel(RepositoryEntry repositoryEntry) {
2686 if (repositoryEntry instanceof RepositoryEntryImpl) {
2687 return repositoryEntry;
2688 }
2689
2690 RepositoryEntryImpl repositoryEntryImpl = new RepositoryEntryImpl();
2691
2692 repositoryEntryImpl.setNew(repositoryEntry.isNew());
2693 repositoryEntryImpl.setPrimaryKey(repositoryEntry.getPrimaryKey());
2694
2695 repositoryEntryImpl.setMvccVersion(repositoryEntry.getMvccVersion());
2696 repositoryEntryImpl.setUuid(repositoryEntry.getUuid());
2697 repositoryEntryImpl.setRepositoryEntryId(repositoryEntry.getRepositoryEntryId());
2698 repositoryEntryImpl.setGroupId(repositoryEntry.getGroupId());
2699 repositoryEntryImpl.setCompanyId(repositoryEntry.getCompanyId());
2700 repositoryEntryImpl.setUserId(repositoryEntry.getUserId());
2701 repositoryEntryImpl.setUserName(repositoryEntry.getUserName());
2702 repositoryEntryImpl.setCreateDate(repositoryEntry.getCreateDate());
2703 repositoryEntryImpl.setModifiedDate(repositoryEntry.getModifiedDate());
2704 repositoryEntryImpl.setRepositoryId(repositoryEntry.getRepositoryId());
2705 repositoryEntryImpl.setMappedId(repositoryEntry.getMappedId());
2706 repositoryEntryImpl.setManualCheckInRequired(repositoryEntry.isManualCheckInRequired());
2707 repositoryEntryImpl.setLastPublishDate(repositoryEntry.getLastPublishDate());
2708
2709 return repositoryEntryImpl;
2710 }
2711
2712
2719 @Override
2720 public RepositoryEntry findByPrimaryKey(Serializable primaryKey)
2721 throws NoSuchRepositoryEntryException {
2722 RepositoryEntry repositoryEntry = fetchByPrimaryKey(primaryKey);
2723
2724 if (repositoryEntry == null) {
2725 if (_log.isWarnEnabled()) {
2726 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2727 }
2728
2729 throw new NoSuchRepositoryEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2730 primaryKey);
2731 }
2732
2733 return repositoryEntry;
2734 }
2735
2736
2743 @Override
2744 public RepositoryEntry findByPrimaryKey(long repositoryEntryId)
2745 throws NoSuchRepositoryEntryException {
2746 return findByPrimaryKey((Serializable)repositoryEntryId);
2747 }
2748
2749
2755 @Override
2756 public RepositoryEntry fetchByPrimaryKey(Serializable primaryKey) {
2757 RepositoryEntry repositoryEntry = (RepositoryEntry)entityCache.getResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2758 RepositoryEntryImpl.class, primaryKey);
2759
2760 if (repositoryEntry == _nullRepositoryEntry) {
2761 return null;
2762 }
2763
2764 if (repositoryEntry == null) {
2765 Session session = null;
2766
2767 try {
2768 session = openSession();
2769
2770 repositoryEntry = (RepositoryEntry)session.get(RepositoryEntryImpl.class,
2771 primaryKey);
2772
2773 if (repositoryEntry != null) {
2774 cacheResult(repositoryEntry);
2775 }
2776 else {
2777 entityCache.putResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2778 RepositoryEntryImpl.class, primaryKey,
2779 _nullRepositoryEntry);
2780 }
2781 }
2782 catch (Exception e) {
2783 entityCache.removeResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2784 RepositoryEntryImpl.class, primaryKey);
2785
2786 throw processException(e);
2787 }
2788 finally {
2789 closeSession(session);
2790 }
2791 }
2792
2793 return repositoryEntry;
2794 }
2795
2796
2802 @Override
2803 public RepositoryEntry fetchByPrimaryKey(long repositoryEntryId) {
2804 return fetchByPrimaryKey((Serializable)repositoryEntryId);
2805 }
2806
2807 @Override
2808 public Map<Serializable, RepositoryEntry> fetchByPrimaryKeys(
2809 Set<Serializable> primaryKeys) {
2810 if (primaryKeys.isEmpty()) {
2811 return Collections.emptyMap();
2812 }
2813
2814 Map<Serializable, RepositoryEntry> map = new HashMap<Serializable, RepositoryEntry>();
2815
2816 if (primaryKeys.size() == 1) {
2817 Iterator<Serializable> iterator = primaryKeys.iterator();
2818
2819 Serializable primaryKey = iterator.next();
2820
2821 RepositoryEntry repositoryEntry = fetchByPrimaryKey(primaryKey);
2822
2823 if (repositoryEntry != null) {
2824 map.put(primaryKey, repositoryEntry);
2825 }
2826
2827 return map;
2828 }
2829
2830 Set<Serializable> uncachedPrimaryKeys = null;
2831
2832 for (Serializable primaryKey : primaryKeys) {
2833 RepositoryEntry repositoryEntry = (RepositoryEntry)entityCache.getResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2834 RepositoryEntryImpl.class, primaryKey);
2835
2836 if (repositoryEntry == null) {
2837 if (uncachedPrimaryKeys == null) {
2838 uncachedPrimaryKeys = new HashSet<Serializable>();
2839 }
2840
2841 uncachedPrimaryKeys.add(primaryKey);
2842 }
2843 else {
2844 map.put(primaryKey, repositoryEntry);
2845 }
2846 }
2847
2848 if (uncachedPrimaryKeys == null) {
2849 return map;
2850 }
2851
2852 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2853 1);
2854
2855 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE_PKS_IN);
2856
2857 for (Serializable primaryKey : uncachedPrimaryKeys) {
2858 query.append(String.valueOf(primaryKey));
2859
2860 query.append(StringPool.COMMA);
2861 }
2862
2863 query.setIndex(query.index() - 1);
2864
2865 query.append(StringPool.CLOSE_PARENTHESIS);
2866
2867 String sql = query.toString();
2868
2869 Session session = null;
2870
2871 try {
2872 session = openSession();
2873
2874 Query q = session.createQuery(sql);
2875
2876 for (RepositoryEntry repositoryEntry : (List<RepositoryEntry>)q.list()) {
2877 map.put(repositoryEntry.getPrimaryKeyObj(), repositoryEntry);
2878
2879 cacheResult(repositoryEntry);
2880
2881 uncachedPrimaryKeys.remove(repositoryEntry.getPrimaryKeyObj());
2882 }
2883
2884 for (Serializable primaryKey : uncachedPrimaryKeys) {
2885 entityCache.putResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2886 RepositoryEntryImpl.class, primaryKey, _nullRepositoryEntry);
2887 }
2888 }
2889 catch (Exception e) {
2890 throw processException(e);
2891 }
2892 finally {
2893 closeSession(session);
2894 }
2895
2896 return map;
2897 }
2898
2899
2904 @Override
2905 public List<RepositoryEntry> findAll() {
2906 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2907 }
2908
2909
2920 @Override
2921 public List<RepositoryEntry> findAll(int start, int end) {
2922 return findAll(start, end, null);
2923 }
2924
2925
2937 @Override
2938 public List<RepositoryEntry> findAll(int start, int end,
2939 OrderByComparator<RepositoryEntry> orderByComparator) {
2940 return findAll(start, end, orderByComparator, true);
2941 }
2942
2943
2956 @Override
2957 public List<RepositoryEntry> findAll(int start, int end,
2958 OrderByComparator<RepositoryEntry> orderByComparator,
2959 boolean retrieveFromCache) {
2960 boolean pagination = true;
2961 FinderPath finderPath = null;
2962 Object[] finderArgs = null;
2963
2964 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2965 (orderByComparator == null)) {
2966 pagination = false;
2967 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2968 finderArgs = FINDER_ARGS_EMPTY;
2969 }
2970 else {
2971 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2972 finderArgs = new Object[] { start, end, orderByComparator };
2973 }
2974
2975 List<RepositoryEntry> list = null;
2976
2977 if (retrieveFromCache) {
2978 list = (List<RepositoryEntry>)finderCache.getResult(finderPath,
2979 finderArgs, this);
2980 }
2981
2982 if (list == null) {
2983 StringBundler query = null;
2984 String sql = null;
2985
2986 if (orderByComparator != null) {
2987 query = new StringBundler(2 +
2988 (orderByComparator.getOrderByFields().length * 2));
2989
2990 query.append(_SQL_SELECT_REPOSITORYENTRY);
2991
2992 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2993 orderByComparator);
2994
2995 sql = query.toString();
2996 }
2997 else {
2998 sql = _SQL_SELECT_REPOSITORYENTRY;
2999
3000 if (pagination) {
3001 sql = sql.concat(RepositoryEntryModelImpl.ORDER_BY_JPQL);
3002 }
3003 }
3004
3005 Session session = null;
3006
3007 try {
3008 session = openSession();
3009
3010 Query q = session.createQuery(sql);
3011
3012 if (!pagination) {
3013 list = (List<RepositoryEntry>)QueryUtil.list(q,
3014 getDialect(), start, end, false);
3015
3016 Collections.sort(list);
3017
3018 list = Collections.unmodifiableList(list);
3019 }
3020 else {
3021 list = (List<RepositoryEntry>)QueryUtil.list(q,
3022 getDialect(), start, end);
3023 }
3024
3025 cacheResult(list);
3026
3027 finderCache.putResult(finderPath, finderArgs, list);
3028 }
3029 catch (Exception e) {
3030 finderCache.removeResult(finderPath, finderArgs);
3031
3032 throw processException(e);
3033 }
3034 finally {
3035 closeSession(session);
3036 }
3037 }
3038
3039 return list;
3040 }
3041
3042
3046 @Override
3047 public void removeAll() {
3048 for (RepositoryEntry repositoryEntry : findAll()) {
3049 remove(repositoryEntry);
3050 }
3051 }
3052
3053
3058 @Override
3059 public int countAll() {
3060 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
3061 FINDER_ARGS_EMPTY, this);
3062
3063 if (count == null) {
3064 Session session = null;
3065
3066 try {
3067 session = openSession();
3068
3069 Query q = session.createQuery(_SQL_COUNT_REPOSITORYENTRY);
3070
3071 count = (Long)q.uniqueResult();
3072
3073 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
3074 count);
3075 }
3076 catch (Exception e) {
3077 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
3078 FINDER_ARGS_EMPTY);
3079
3080 throw processException(e);
3081 }
3082 finally {
3083 closeSession(session);
3084 }
3085 }
3086
3087 return count.intValue();
3088 }
3089
3090 @Override
3091 public Set<String> getBadColumnNames() {
3092 return _badColumnNames;
3093 }
3094
3095 @Override
3096 protected Map<String, Integer> getTableColumnsMap() {
3097 return RepositoryEntryModelImpl.TABLE_COLUMNS_MAP;
3098 }
3099
3100
3103 public void afterPropertiesSet() {
3104 }
3105
3106 public void destroy() {
3107 entityCache.removeCache(RepositoryEntryImpl.class.getName());
3108 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
3109 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3110 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3111 }
3112
3113 @BeanReference(type = CompanyProviderWrapper.class)
3114 protected CompanyProvider companyProvider;
3115 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
3116 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
3117 private static final String _SQL_SELECT_REPOSITORYENTRY = "SELECT repositoryEntry FROM RepositoryEntry repositoryEntry";
3118 private static final String _SQL_SELECT_REPOSITORYENTRY_WHERE_PKS_IN = "SELECT repositoryEntry FROM RepositoryEntry repositoryEntry WHERE repositoryEntryId IN (";
3119 private static final String _SQL_SELECT_REPOSITORYENTRY_WHERE = "SELECT repositoryEntry FROM RepositoryEntry repositoryEntry WHERE ";
3120 private static final String _SQL_COUNT_REPOSITORYENTRY = "SELECT COUNT(repositoryEntry) FROM RepositoryEntry repositoryEntry";
3121 private static final String _SQL_COUNT_REPOSITORYENTRY_WHERE = "SELECT COUNT(repositoryEntry) FROM RepositoryEntry repositoryEntry WHERE ";
3122 private static final String _ORDER_BY_ENTITY_ALIAS = "repositoryEntry.";
3123 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RepositoryEntry exists with the primary key ";
3124 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RepositoryEntry exists with the key {";
3125 private static final Log _log = LogFactoryUtil.getLog(RepositoryEntryPersistenceImpl.class);
3126 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3127 "uuid"
3128 });
3129 private static final RepositoryEntry _nullRepositoryEntry = new RepositoryEntryImpl() {
3130 @Override
3131 public Object clone() {
3132 return this;
3133 }
3134
3135 @Override
3136 public CacheModel<RepositoryEntry> toCacheModel() {
3137 return _nullRepositoryEntryCacheModel;
3138 }
3139 };
3140
3141 private static final CacheModel<RepositoryEntry> _nullRepositoryEntryCacheModel =
3142 new NullCacheModel();
3143
3144 private static class NullCacheModel implements CacheModel<RepositoryEntry>,
3145 MVCCModel {
3146 @Override
3147 public long getMvccVersion() {
3148 return -1;
3149 }
3150
3151 @Override
3152 public void setMvccVersion(long mvccVersion) {
3153 }
3154
3155 @Override
3156 public RepositoryEntry toEntityModel() {
3157 return _nullRepositoryEntry;
3158 }
3159 }
3160 }