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