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