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