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.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.OrderByComparator;
030 import com.liferay.portal.kernel.util.SetUtil;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.Validator;
034 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.model.MVCCModel;
037 import com.liferay.portal.model.RepositoryEntry;
038 import com.liferay.portal.model.impl.RepositoryEntryImpl;
039 import com.liferay.portal.model.impl.RepositoryEntryModelImpl;
040 import com.liferay.portal.service.ServiceContext;
041 import com.liferay.portal.service.ServiceContextThreadLocal;
042 import com.liferay.portal.service.persistence.RepositoryEntryPersistence;
043
044 import java.io.Serializable;
045
046 import java.util.Collections;
047 import java.util.Date;
048 import java.util.HashMap;
049 import java.util.HashSet;
050 import java.util.Iterator;
051 import java.util.List;
052 import java.util.Map;
053 import java.util.Set;
054
055
067 @ProviderType
068 public class RepositoryEntryPersistenceImpl extends BasePersistenceImpl<RepositoryEntry>
069 implements RepositoryEntryPersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = RepositoryEntryImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
081 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
082 RepositoryEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083 "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
085 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
086 RepositoryEntryImpl.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
089 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
092 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
093 RepositoryEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
094 "findByUuid",
095 new String[] {
096 String.class.getName(),
097
098 Integer.class.getName(), Integer.class.getName(),
099 OrderByComparator.class.getName()
100 });
101 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
102 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
103 RepositoryEntryImpl.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
105 new String[] { String.class.getName() },
106 RepositoryEntryModelImpl.UUID_COLUMN_BITMASK);
107 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
108 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
109 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
110 new String[] { String.class.getName() });
111
112
118 @Override
119 public List<RepositoryEntry> findByUuid(String uuid) {
120 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
121 }
122
123
135 @Override
136 public List<RepositoryEntry> findByUuid(String uuid, int start, int end) {
137 return findByUuid(uuid, start, end, null);
138 }
139
140
153 @Override
154 public List<RepositoryEntry> findByUuid(String uuid, int start, int end,
155 OrderByComparator<RepositoryEntry> orderByComparator) {
156 boolean pagination = true;
157 FinderPath finderPath = null;
158 Object[] finderArgs = null;
159
160 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
161 (orderByComparator == null)) {
162 pagination = false;
163 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
164 finderArgs = new Object[] { uuid };
165 }
166 else {
167 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
168 finderArgs = new Object[] { uuid, start, end, orderByComparator };
169 }
170
171 List<RepositoryEntry> list = (List<RepositoryEntry>)FinderCacheUtil.getResult(finderPath,
172 finderArgs, this);
173
174 if ((list != null) && !list.isEmpty()) {
175 for (RepositoryEntry repositoryEntry : list) {
176 if (!Validator.equals(uuid, repositoryEntry.getUuid())) {
177 list = null;
178
179 break;
180 }
181 }
182 }
183
184 if (list == null) {
185 StringBundler query = null;
186
187 if (orderByComparator != null) {
188 query = new StringBundler(3 +
189 (orderByComparator.getOrderByFields().length * 3));
190 }
191 else {
192 query = new StringBundler(3);
193 }
194
195 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
196
197 boolean bindUuid = false;
198
199 if (uuid == null) {
200 query.append(_FINDER_COLUMN_UUID_UUID_1);
201 }
202 else if (uuid.equals(StringPool.BLANK)) {
203 query.append(_FINDER_COLUMN_UUID_UUID_3);
204 }
205 else {
206 bindUuid = true;
207
208 query.append(_FINDER_COLUMN_UUID_UUID_2);
209 }
210
211 if (orderByComparator != null) {
212 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
213 orderByComparator);
214 }
215 else
216 if (pagination) {
217 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
218 }
219
220 String sql = query.toString();
221
222 Session session = null;
223
224 try {
225 session = openSession();
226
227 Query q = session.createQuery(sql);
228
229 QueryPos qPos = QueryPos.getInstance(q);
230
231 if (bindUuid) {
232 qPos.add(uuid);
233 }
234
235 if (!pagination) {
236 list = (List<RepositoryEntry>)QueryUtil.list(q,
237 getDialect(), start, end, false);
238
239 Collections.sort(list);
240
241 list = Collections.unmodifiableList(list);
242 }
243 else {
244 list = (List<RepositoryEntry>)QueryUtil.list(q,
245 getDialect(), start, end);
246 }
247
248 cacheResult(list);
249
250 FinderCacheUtil.putResult(finderPath, finderArgs, list);
251 }
252 catch (Exception e) {
253 FinderCacheUtil.removeResult(finderPath, finderArgs);
254
255 throw processException(e);
256 }
257 finally {
258 closeSession(session);
259 }
260 }
261
262 return list;
263 }
264
265
273 @Override
274 public RepositoryEntry findByUuid_First(String uuid,
275 OrderByComparator<RepositoryEntry> orderByComparator)
276 throws NoSuchRepositoryEntryException {
277 RepositoryEntry repositoryEntry = fetchByUuid_First(uuid,
278 orderByComparator);
279
280 if (repositoryEntry != null) {
281 return repositoryEntry;
282 }
283
284 StringBundler msg = new StringBundler(4);
285
286 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
287
288 msg.append("uuid=");
289 msg.append(uuid);
290
291 msg.append(StringPool.CLOSE_CURLY_BRACE);
292
293 throw new NoSuchRepositoryEntryException(msg.toString());
294 }
295
296
303 @Override
304 public RepositoryEntry fetchByUuid_First(String uuid,
305 OrderByComparator<RepositoryEntry> orderByComparator) {
306 List<RepositoryEntry> list = findByUuid(uuid, 0, 1, orderByComparator);
307
308 if (!list.isEmpty()) {
309 return list.get(0);
310 }
311
312 return null;
313 }
314
315
323 @Override
324 public RepositoryEntry findByUuid_Last(String uuid,
325 OrderByComparator<RepositoryEntry> orderByComparator)
326 throws NoSuchRepositoryEntryException {
327 RepositoryEntry repositoryEntry = fetchByUuid_Last(uuid,
328 orderByComparator);
329
330 if (repositoryEntry != null) {
331 return repositoryEntry;
332 }
333
334 StringBundler msg = new StringBundler(4);
335
336 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
337
338 msg.append("uuid=");
339 msg.append(uuid);
340
341 msg.append(StringPool.CLOSE_CURLY_BRACE);
342
343 throw new NoSuchRepositoryEntryException(msg.toString());
344 }
345
346
353 @Override
354 public RepositoryEntry fetchByUuid_Last(String uuid,
355 OrderByComparator<RepositoryEntry> orderByComparator) {
356 int count = countByUuid(uuid);
357
358 if (count == 0) {
359 return null;
360 }
361
362 List<RepositoryEntry> list = findByUuid(uuid, count - 1, count,
363 orderByComparator);
364
365 if (!list.isEmpty()) {
366 return list.get(0);
367 }
368
369 return null;
370 }
371
372
381 @Override
382 public RepositoryEntry[] findByUuid_PrevAndNext(long repositoryEntryId,
383 String uuid, OrderByComparator<RepositoryEntry> orderByComparator)
384 throws NoSuchRepositoryEntryException {
385 RepositoryEntry repositoryEntry = findByPrimaryKey(repositoryEntryId);
386
387 Session session = null;
388
389 try {
390 session = openSession();
391
392 RepositoryEntry[] array = new RepositoryEntryImpl[3];
393
394 array[0] = getByUuid_PrevAndNext(session, repositoryEntry, uuid,
395 orderByComparator, true);
396
397 array[1] = repositoryEntry;
398
399 array[2] = getByUuid_PrevAndNext(session, repositoryEntry, uuid,
400 orderByComparator, false);
401
402 return array;
403 }
404 catch (Exception e) {
405 throw processException(e);
406 }
407 finally {
408 closeSession(session);
409 }
410 }
411
412 protected RepositoryEntry getByUuid_PrevAndNext(Session session,
413 RepositoryEntry repositoryEntry, String uuid,
414 OrderByComparator<RepositoryEntry> orderByComparator, boolean previous) {
415 StringBundler query = null;
416
417 if (orderByComparator != null) {
418 query = new StringBundler(6 +
419 (orderByComparator.getOrderByFields().length * 6));
420 }
421 else {
422 query = new StringBundler(3);
423 }
424
425 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
426
427 boolean bindUuid = false;
428
429 if (uuid == null) {
430 query.append(_FINDER_COLUMN_UUID_UUID_1);
431 }
432 else if (uuid.equals(StringPool.BLANK)) {
433 query.append(_FINDER_COLUMN_UUID_UUID_3);
434 }
435 else {
436 bindUuid = true;
437
438 query.append(_FINDER_COLUMN_UUID_UUID_2);
439 }
440
441 if (orderByComparator != null) {
442 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
443
444 if (orderByConditionFields.length > 0) {
445 query.append(WHERE_AND);
446 }
447
448 for (int i = 0; i < orderByConditionFields.length; i++) {
449 query.append(_ORDER_BY_ENTITY_ALIAS);
450 query.append(orderByConditionFields[i]);
451
452 if ((i + 1) < orderByConditionFields.length) {
453 if (orderByComparator.isAscending() ^ previous) {
454 query.append(WHERE_GREATER_THAN_HAS_NEXT);
455 }
456 else {
457 query.append(WHERE_LESSER_THAN_HAS_NEXT);
458 }
459 }
460 else {
461 if (orderByComparator.isAscending() ^ previous) {
462 query.append(WHERE_GREATER_THAN);
463 }
464 else {
465 query.append(WHERE_LESSER_THAN);
466 }
467 }
468 }
469
470 query.append(ORDER_BY_CLAUSE);
471
472 String[] orderByFields = orderByComparator.getOrderByFields();
473
474 for (int i = 0; i < orderByFields.length; i++) {
475 query.append(_ORDER_BY_ENTITY_ALIAS);
476 query.append(orderByFields[i]);
477
478 if ((i + 1) < orderByFields.length) {
479 if (orderByComparator.isAscending() ^ previous) {
480 query.append(ORDER_BY_ASC_HAS_NEXT);
481 }
482 else {
483 query.append(ORDER_BY_DESC_HAS_NEXT);
484 }
485 }
486 else {
487 if (orderByComparator.isAscending() ^ previous) {
488 query.append(ORDER_BY_ASC);
489 }
490 else {
491 query.append(ORDER_BY_DESC);
492 }
493 }
494 }
495 }
496 else {
497 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
498 }
499
500 String sql = query.toString();
501
502 Query q = session.createQuery(sql);
503
504 q.setFirstResult(0);
505 q.setMaxResults(2);
506
507 QueryPos qPos = QueryPos.getInstance(q);
508
509 if (bindUuid) {
510 qPos.add(uuid);
511 }
512
513 if (orderByComparator != null) {
514 Object[] values = orderByComparator.getOrderByConditionValues(repositoryEntry);
515
516 for (Object value : values) {
517 qPos.add(value);
518 }
519 }
520
521 List<RepositoryEntry> list = q.list();
522
523 if (list.size() == 2) {
524 return list.get(1);
525 }
526 else {
527 return null;
528 }
529 }
530
531
536 @Override
537 public void removeByUuid(String uuid) {
538 for (RepositoryEntry repositoryEntry : findByUuid(uuid,
539 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
540 remove(repositoryEntry);
541 }
542 }
543
544
550 @Override
551 public int countByUuid(String uuid) {
552 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
553
554 Object[] finderArgs = new Object[] { uuid };
555
556 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
557 this);
558
559 if (count == null) {
560 StringBundler query = new StringBundler(2);
561
562 query.append(_SQL_COUNT_REPOSITORYENTRY_WHERE);
563
564 boolean bindUuid = false;
565
566 if (uuid == null) {
567 query.append(_FINDER_COLUMN_UUID_UUID_1);
568 }
569 else if (uuid.equals(StringPool.BLANK)) {
570 query.append(_FINDER_COLUMN_UUID_UUID_3);
571 }
572 else {
573 bindUuid = true;
574
575 query.append(_FINDER_COLUMN_UUID_UUID_2);
576 }
577
578 String sql = query.toString();
579
580 Session session = null;
581
582 try {
583 session = openSession();
584
585 Query q = session.createQuery(sql);
586
587 QueryPos qPos = QueryPos.getInstance(q);
588
589 if (bindUuid) {
590 qPos.add(uuid);
591 }
592
593 count = (Long)q.uniqueResult();
594
595 FinderCacheUtil.putResult(finderPath, finderArgs, count);
596 }
597 catch (Exception e) {
598 FinderCacheUtil.removeResult(finderPath, finderArgs);
599
600 throw processException(e);
601 }
602 finally {
603 closeSession(session);
604 }
605 }
606
607 return count.intValue();
608 }
609
610 private static final String _FINDER_COLUMN_UUID_UUID_1 = "repositoryEntry.uuid IS NULL";
611 private static final String _FINDER_COLUMN_UUID_UUID_2 = "repositoryEntry.uuid = ?";
612 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(repositoryEntry.uuid IS NULL OR repositoryEntry.uuid = '')";
613 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
614 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
615 RepositoryEntryImpl.class, FINDER_CLASS_NAME_ENTITY,
616 "fetchByUUID_G",
617 new String[] { String.class.getName(), Long.class.getName() },
618 RepositoryEntryModelImpl.UUID_COLUMN_BITMASK |
619 RepositoryEntryModelImpl.GROUPID_COLUMN_BITMASK);
620 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
621 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
622 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
623 new String[] { String.class.getName(), Long.class.getName() });
624
625
633 @Override
634 public RepositoryEntry findByUUID_G(String uuid, long groupId)
635 throws NoSuchRepositoryEntryException {
636 RepositoryEntry repositoryEntry = fetchByUUID_G(uuid, groupId);
637
638 if (repositoryEntry == null) {
639 StringBundler msg = new StringBundler(6);
640
641 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
642
643 msg.append("uuid=");
644 msg.append(uuid);
645
646 msg.append(", groupId=");
647 msg.append(groupId);
648
649 msg.append(StringPool.CLOSE_CURLY_BRACE);
650
651 if (_log.isWarnEnabled()) {
652 _log.warn(msg.toString());
653 }
654
655 throw new NoSuchRepositoryEntryException(msg.toString());
656 }
657
658 return repositoryEntry;
659 }
660
661
668 @Override
669 public RepositoryEntry fetchByUUID_G(String uuid, long groupId) {
670 return fetchByUUID_G(uuid, groupId, true);
671 }
672
673
681 @Override
682 public RepositoryEntry fetchByUUID_G(String uuid, long groupId,
683 boolean retrieveFromCache) {
684 Object[] finderArgs = new Object[] { uuid, groupId };
685
686 Object result = null;
687
688 if (retrieveFromCache) {
689 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
690 finderArgs, this);
691 }
692
693 if (result instanceof RepositoryEntry) {
694 RepositoryEntry repositoryEntry = (RepositoryEntry)result;
695
696 if (!Validator.equals(uuid, repositoryEntry.getUuid()) ||
697 (groupId != repositoryEntry.getGroupId())) {
698 result = null;
699 }
700 }
701
702 if (result == null) {
703 StringBundler query = new StringBundler(4);
704
705 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
706
707 boolean bindUuid = false;
708
709 if (uuid == null) {
710 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
711 }
712 else if (uuid.equals(StringPool.BLANK)) {
713 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
714 }
715 else {
716 bindUuid = true;
717
718 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
719 }
720
721 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
722
723 String sql = query.toString();
724
725 Session session = null;
726
727 try {
728 session = openSession();
729
730 Query q = session.createQuery(sql);
731
732 QueryPos qPos = QueryPos.getInstance(q);
733
734 if (bindUuid) {
735 qPos.add(uuid);
736 }
737
738 qPos.add(groupId);
739
740 List<RepositoryEntry> list = q.list();
741
742 if (list.isEmpty()) {
743 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
744 finderArgs, list);
745 }
746 else {
747 RepositoryEntry repositoryEntry = list.get(0);
748
749 result = repositoryEntry;
750
751 cacheResult(repositoryEntry);
752
753 if ((repositoryEntry.getUuid() == null) ||
754 !repositoryEntry.getUuid().equals(uuid) ||
755 (repositoryEntry.getGroupId() != groupId)) {
756 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
757 finderArgs, repositoryEntry);
758 }
759 }
760 }
761 catch (Exception e) {
762 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
763 finderArgs);
764
765 throw processException(e);
766 }
767 finally {
768 closeSession(session);
769 }
770 }
771
772 if (result instanceof List<?>) {
773 return null;
774 }
775 else {
776 return (RepositoryEntry)result;
777 }
778 }
779
780
787 @Override
788 public RepositoryEntry removeByUUID_G(String uuid, long groupId)
789 throws NoSuchRepositoryEntryException {
790 RepositoryEntry repositoryEntry = findByUUID_G(uuid, groupId);
791
792 return remove(repositoryEntry);
793 }
794
795
802 @Override
803 public int countByUUID_G(String uuid, long groupId) {
804 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
805
806 Object[] finderArgs = new Object[] { uuid, groupId };
807
808 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
809 this);
810
811 if (count == null) {
812 StringBundler query = new StringBundler(3);
813
814 query.append(_SQL_COUNT_REPOSITORYENTRY_WHERE);
815
816 boolean bindUuid = false;
817
818 if (uuid == null) {
819 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
820 }
821 else if (uuid.equals(StringPool.BLANK)) {
822 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
823 }
824 else {
825 bindUuid = true;
826
827 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
828 }
829
830 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
831
832 String sql = query.toString();
833
834 Session session = null;
835
836 try {
837 session = openSession();
838
839 Query q = session.createQuery(sql);
840
841 QueryPos qPos = QueryPos.getInstance(q);
842
843 if (bindUuid) {
844 qPos.add(uuid);
845 }
846
847 qPos.add(groupId);
848
849 count = (Long)q.uniqueResult();
850
851 FinderCacheUtil.putResult(finderPath, finderArgs, count);
852 }
853 catch (Exception e) {
854 FinderCacheUtil.removeResult(finderPath, finderArgs);
855
856 throw processException(e);
857 }
858 finally {
859 closeSession(session);
860 }
861 }
862
863 return count.intValue();
864 }
865
866 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "repositoryEntry.uuid IS NULL AND ";
867 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "repositoryEntry.uuid = ? AND ";
868 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(repositoryEntry.uuid IS NULL OR repositoryEntry.uuid = '') AND ";
869 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "repositoryEntry.groupId = ?";
870 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
871 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
872 RepositoryEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
873 "findByUuid_C",
874 new String[] {
875 String.class.getName(), Long.class.getName(),
876
877 Integer.class.getName(), Integer.class.getName(),
878 OrderByComparator.class.getName()
879 });
880 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
881 new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
882 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
883 RepositoryEntryImpl.class,
884 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
885 new String[] { String.class.getName(), Long.class.getName() },
886 RepositoryEntryModelImpl.UUID_COLUMN_BITMASK |
887 RepositoryEntryModelImpl.COMPANYID_COLUMN_BITMASK);
888 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
889 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
890 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
891 new String[] { String.class.getName(), Long.class.getName() });
892
893
900 @Override
901 public List<RepositoryEntry> findByUuid_C(String uuid, long companyId) {
902 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
903 QueryUtil.ALL_POS, null);
904 }
905
906
919 @Override
920 public List<RepositoryEntry> findByUuid_C(String uuid, long companyId,
921 int start, int end) {
922 return findByUuid_C(uuid, companyId, start, end, null);
923 }
924
925
939 @Override
940 public List<RepositoryEntry> findByUuid_C(String uuid, long companyId,
941 int start, int end, OrderByComparator<RepositoryEntry> orderByComparator) {
942 boolean pagination = true;
943 FinderPath finderPath = null;
944 Object[] finderArgs = null;
945
946 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
947 (orderByComparator == null)) {
948 pagination = false;
949 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
950 finderArgs = new Object[] { uuid, companyId };
951 }
952 else {
953 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
954 finderArgs = new Object[] {
955 uuid, companyId,
956
957 start, end, orderByComparator
958 };
959 }
960
961 List<RepositoryEntry> list = (List<RepositoryEntry>)FinderCacheUtil.getResult(finderPath,
962 finderArgs, this);
963
964 if ((list != null) && !list.isEmpty()) {
965 for (RepositoryEntry repositoryEntry : list) {
966 if (!Validator.equals(uuid, repositoryEntry.getUuid()) ||
967 (companyId != repositoryEntry.getCompanyId())) {
968 list = null;
969
970 break;
971 }
972 }
973 }
974
975 if (list == null) {
976 StringBundler query = null;
977
978 if (orderByComparator != null) {
979 query = new StringBundler(4 +
980 (orderByComparator.getOrderByFields().length * 3));
981 }
982 else {
983 query = new StringBundler(4);
984 }
985
986 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
987
988 boolean bindUuid = false;
989
990 if (uuid == null) {
991 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
992 }
993 else if (uuid.equals(StringPool.BLANK)) {
994 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
995 }
996 else {
997 bindUuid = true;
998
999 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1000 }
1001
1002 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1003
1004 if (orderByComparator != null) {
1005 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1006 orderByComparator);
1007 }
1008 else
1009 if (pagination) {
1010 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
1011 }
1012
1013 String sql = query.toString();
1014
1015 Session session = null;
1016
1017 try {
1018 session = openSession();
1019
1020 Query q = session.createQuery(sql);
1021
1022 QueryPos qPos = QueryPos.getInstance(q);
1023
1024 if (bindUuid) {
1025 qPos.add(uuid);
1026 }
1027
1028 qPos.add(companyId);
1029
1030 if (!pagination) {
1031 list = (List<RepositoryEntry>)QueryUtil.list(q,
1032 getDialect(), start, end, false);
1033
1034 Collections.sort(list);
1035
1036 list = Collections.unmodifiableList(list);
1037 }
1038 else {
1039 list = (List<RepositoryEntry>)QueryUtil.list(q,
1040 getDialect(), start, end);
1041 }
1042
1043 cacheResult(list);
1044
1045 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1046 }
1047 catch (Exception e) {
1048 FinderCacheUtil.removeResult(finderPath, finderArgs);
1049
1050 throw processException(e);
1051 }
1052 finally {
1053 closeSession(session);
1054 }
1055 }
1056
1057 return list;
1058 }
1059
1060
1069 @Override
1070 public RepositoryEntry findByUuid_C_First(String uuid, long companyId,
1071 OrderByComparator<RepositoryEntry> orderByComparator)
1072 throws NoSuchRepositoryEntryException {
1073 RepositoryEntry repositoryEntry = fetchByUuid_C_First(uuid, companyId,
1074 orderByComparator);
1075
1076 if (repositoryEntry != null) {
1077 return repositoryEntry;
1078 }
1079
1080 StringBundler msg = new StringBundler(6);
1081
1082 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1083
1084 msg.append("uuid=");
1085 msg.append(uuid);
1086
1087 msg.append(", companyId=");
1088 msg.append(companyId);
1089
1090 msg.append(StringPool.CLOSE_CURLY_BRACE);
1091
1092 throw new NoSuchRepositoryEntryException(msg.toString());
1093 }
1094
1095
1103 @Override
1104 public RepositoryEntry fetchByUuid_C_First(String uuid, long companyId,
1105 OrderByComparator<RepositoryEntry> orderByComparator) {
1106 List<RepositoryEntry> list = findByUuid_C(uuid, companyId, 0, 1,
1107 orderByComparator);
1108
1109 if (!list.isEmpty()) {
1110 return list.get(0);
1111 }
1112
1113 return null;
1114 }
1115
1116
1125 @Override
1126 public RepositoryEntry findByUuid_C_Last(String uuid, long companyId,
1127 OrderByComparator<RepositoryEntry> orderByComparator)
1128 throws NoSuchRepositoryEntryException {
1129 RepositoryEntry repositoryEntry = fetchByUuid_C_Last(uuid, companyId,
1130 orderByComparator);
1131
1132 if (repositoryEntry != null) {
1133 return repositoryEntry;
1134 }
1135
1136 StringBundler msg = new StringBundler(6);
1137
1138 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1139
1140 msg.append("uuid=");
1141 msg.append(uuid);
1142
1143 msg.append(", companyId=");
1144 msg.append(companyId);
1145
1146 msg.append(StringPool.CLOSE_CURLY_BRACE);
1147
1148 throw new NoSuchRepositoryEntryException(msg.toString());
1149 }
1150
1151
1159 @Override
1160 public RepositoryEntry fetchByUuid_C_Last(String uuid, long companyId,
1161 OrderByComparator<RepositoryEntry> orderByComparator) {
1162 int count = countByUuid_C(uuid, companyId);
1163
1164 if (count == 0) {
1165 return null;
1166 }
1167
1168 List<RepositoryEntry> list = findByUuid_C(uuid, companyId, count - 1,
1169 count, orderByComparator);
1170
1171 if (!list.isEmpty()) {
1172 return list.get(0);
1173 }
1174
1175 return null;
1176 }
1177
1178
1188 @Override
1189 public RepositoryEntry[] findByUuid_C_PrevAndNext(long repositoryEntryId,
1190 String uuid, long companyId,
1191 OrderByComparator<RepositoryEntry> orderByComparator)
1192 throws NoSuchRepositoryEntryException {
1193 RepositoryEntry repositoryEntry = findByPrimaryKey(repositoryEntryId);
1194
1195 Session session = null;
1196
1197 try {
1198 session = openSession();
1199
1200 RepositoryEntry[] array = new RepositoryEntryImpl[3];
1201
1202 array[0] = getByUuid_C_PrevAndNext(session, repositoryEntry, uuid,
1203 companyId, orderByComparator, true);
1204
1205 array[1] = repositoryEntry;
1206
1207 array[2] = getByUuid_C_PrevAndNext(session, repositoryEntry, uuid,
1208 companyId, orderByComparator, false);
1209
1210 return array;
1211 }
1212 catch (Exception e) {
1213 throw processException(e);
1214 }
1215 finally {
1216 closeSession(session);
1217 }
1218 }
1219
1220 protected RepositoryEntry getByUuid_C_PrevAndNext(Session session,
1221 RepositoryEntry repositoryEntry, String uuid, long companyId,
1222 OrderByComparator<RepositoryEntry> orderByComparator, boolean previous) {
1223 StringBundler query = null;
1224
1225 if (orderByComparator != null) {
1226 query = new StringBundler(6 +
1227 (orderByComparator.getOrderByFields().length * 6));
1228 }
1229 else {
1230 query = new StringBundler(3);
1231 }
1232
1233 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
1234
1235 boolean bindUuid = false;
1236
1237 if (uuid == null) {
1238 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1239 }
1240 else if (uuid.equals(StringPool.BLANK)) {
1241 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1242 }
1243 else {
1244 bindUuid = true;
1245
1246 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1247 }
1248
1249 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1250
1251 if (orderByComparator != null) {
1252 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1253
1254 if (orderByConditionFields.length > 0) {
1255 query.append(WHERE_AND);
1256 }
1257
1258 for (int i = 0; i < orderByConditionFields.length; i++) {
1259 query.append(_ORDER_BY_ENTITY_ALIAS);
1260 query.append(orderByConditionFields[i]);
1261
1262 if ((i + 1) < orderByConditionFields.length) {
1263 if (orderByComparator.isAscending() ^ previous) {
1264 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1265 }
1266 else {
1267 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1268 }
1269 }
1270 else {
1271 if (orderByComparator.isAscending() ^ previous) {
1272 query.append(WHERE_GREATER_THAN);
1273 }
1274 else {
1275 query.append(WHERE_LESSER_THAN);
1276 }
1277 }
1278 }
1279
1280 query.append(ORDER_BY_CLAUSE);
1281
1282 String[] orderByFields = orderByComparator.getOrderByFields();
1283
1284 for (int i = 0; i < orderByFields.length; i++) {
1285 query.append(_ORDER_BY_ENTITY_ALIAS);
1286 query.append(orderByFields[i]);
1287
1288 if ((i + 1) < orderByFields.length) {
1289 if (orderByComparator.isAscending() ^ previous) {
1290 query.append(ORDER_BY_ASC_HAS_NEXT);
1291 }
1292 else {
1293 query.append(ORDER_BY_DESC_HAS_NEXT);
1294 }
1295 }
1296 else {
1297 if (orderByComparator.isAscending() ^ previous) {
1298 query.append(ORDER_BY_ASC);
1299 }
1300 else {
1301 query.append(ORDER_BY_DESC);
1302 }
1303 }
1304 }
1305 }
1306 else {
1307 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
1308 }
1309
1310 String sql = query.toString();
1311
1312 Query q = session.createQuery(sql);
1313
1314 q.setFirstResult(0);
1315 q.setMaxResults(2);
1316
1317 QueryPos qPos = QueryPos.getInstance(q);
1318
1319 if (bindUuid) {
1320 qPos.add(uuid);
1321 }
1322
1323 qPos.add(companyId);
1324
1325 if (orderByComparator != null) {
1326 Object[] values = orderByComparator.getOrderByConditionValues(repositoryEntry);
1327
1328 for (Object value : values) {
1329 qPos.add(value);
1330 }
1331 }
1332
1333 List<RepositoryEntry> list = q.list();
1334
1335 if (list.size() == 2) {
1336 return list.get(1);
1337 }
1338 else {
1339 return null;
1340 }
1341 }
1342
1343
1349 @Override
1350 public void removeByUuid_C(String uuid, long companyId) {
1351 for (RepositoryEntry repositoryEntry : findByUuid_C(uuid, companyId,
1352 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1353 remove(repositoryEntry);
1354 }
1355 }
1356
1357
1364 @Override
1365 public int countByUuid_C(String uuid, long companyId) {
1366 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1367
1368 Object[] finderArgs = new Object[] { uuid, companyId };
1369
1370 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1371 this);
1372
1373 if (count == null) {
1374 StringBundler query = new StringBundler(3);
1375
1376 query.append(_SQL_COUNT_REPOSITORYENTRY_WHERE);
1377
1378 boolean bindUuid = false;
1379
1380 if (uuid == null) {
1381 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1382 }
1383 else if (uuid.equals(StringPool.BLANK)) {
1384 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1385 }
1386 else {
1387 bindUuid = true;
1388
1389 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1390 }
1391
1392 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1393
1394 String sql = query.toString();
1395
1396 Session session = null;
1397
1398 try {
1399 session = openSession();
1400
1401 Query q = session.createQuery(sql);
1402
1403 QueryPos qPos = QueryPos.getInstance(q);
1404
1405 if (bindUuid) {
1406 qPos.add(uuid);
1407 }
1408
1409 qPos.add(companyId);
1410
1411 count = (Long)q.uniqueResult();
1412
1413 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1414 }
1415 catch (Exception e) {
1416 FinderCacheUtil.removeResult(finderPath, finderArgs);
1417
1418 throw processException(e);
1419 }
1420 finally {
1421 closeSession(session);
1422 }
1423 }
1424
1425 return count.intValue();
1426 }
1427
1428 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "repositoryEntry.uuid IS NULL AND ";
1429 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "repositoryEntry.uuid = ? AND ";
1430 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(repositoryEntry.uuid IS NULL OR repositoryEntry.uuid = '') AND ";
1431 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "repositoryEntry.companyId = ?";
1432 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_REPOSITORYID =
1433 new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
1434 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
1435 RepositoryEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1436 "findByRepositoryId",
1437 new String[] {
1438 Long.class.getName(),
1439
1440 Integer.class.getName(), Integer.class.getName(),
1441 OrderByComparator.class.getName()
1442 });
1443 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID =
1444 new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
1445 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
1446 RepositoryEntryImpl.class,
1447 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRepositoryId",
1448 new String[] { Long.class.getName() },
1449 RepositoryEntryModelImpl.REPOSITORYID_COLUMN_BITMASK);
1450 public static final FinderPath FINDER_PATH_COUNT_BY_REPOSITORYID = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
1451 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1452 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRepositoryId",
1453 new String[] { Long.class.getName() });
1454
1455
1461 @Override
1462 public List<RepositoryEntry> findByRepositoryId(long repositoryId) {
1463 return findByRepositoryId(repositoryId, QueryUtil.ALL_POS,
1464 QueryUtil.ALL_POS, null);
1465 }
1466
1467
1479 @Override
1480 public List<RepositoryEntry> findByRepositoryId(long repositoryId,
1481 int start, int end) {
1482 return findByRepositoryId(repositoryId, start, end, null);
1483 }
1484
1485
1498 @Override
1499 public List<RepositoryEntry> findByRepositoryId(long repositoryId,
1500 int start, int end, OrderByComparator<RepositoryEntry> orderByComparator) {
1501 boolean pagination = true;
1502 FinderPath finderPath = null;
1503 Object[] finderArgs = null;
1504
1505 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1506 (orderByComparator == null)) {
1507 pagination = false;
1508 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID;
1509 finderArgs = new Object[] { repositoryId };
1510 }
1511 else {
1512 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_REPOSITORYID;
1513 finderArgs = new Object[] {
1514 repositoryId,
1515
1516 start, end, orderByComparator
1517 };
1518 }
1519
1520 List<RepositoryEntry> list = (List<RepositoryEntry>)FinderCacheUtil.getResult(finderPath,
1521 finderArgs, this);
1522
1523 if ((list != null) && !list.isEmpty()) {
1524 for (RepositoryEntry repositoryEntry : list) {
1525 if ((repositoryId != repositoryEntry.getRepositoryId())) {
1526 list = null;
1527
1528 break;
1529 }
1530 }
1531 }
1532
1533 if (list == null) {
1534 StringBundler query = null;
1535
1536 if (orderByComparator != null) {
1537 query = new StringBundler(3 +
1538 (orderByComparator.getOrderByFields().length * 3));
1539 }
1540 else {
1541 query = new StringBundler(3);
1542 }
1543
1544 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
1545
1546 query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
1547
1548 if (orderByComparator != null) {
1549 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1550 orderByComparator);
1551 }
1552 else
1553 if (pagination) {
1554 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
1555 }
1556
1557 String sql = query.toString();
1558
1559 Session session = null;
1560
1561 try {
1562 session = openSession();
1563
1564 Query q = session.createQuery(sql);
1565
1566 QueryPos qPos = QueryPos.getInstance(q);
1567
1568 qPos.add(repositoryId);
1569
1570 if (!pagination) {
1571 list = (List<RepositoryEntry>)QueryUtil.list(q,
1572 getDialect(), start, end, false);
1573
1574 Collections.sort(list);
1575
1576 list = Collections.unmodifiableList(list);
1577 }
1578 else {
1579 list = (List<RepositoryEntry>)QueryUtil.list(q,
1580 getDialect(), start, end);
1581 }
1582
1583 cacheResult(list);
1584
1585 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1586 }
1587 catch (Exception e) {
1588 FinderCacheUtil.removeResult(finderPath, finderArgs);
1589
1590 throw processException(e);
1591 }
1592 finally {
1593 closeSession(session);
1594 }
1595 }
1596
1597 return list;
1598 }
1599
1600
1608 @Override
1609 public RepositoryEntry findByRepositoryId_First(long repositoryId,
1610 OrderByComparator<RepositoryEntry> orderByComparator)
1611 throws NoSuchRepositoryEntryException {
1612 RepositoryEntry repositoryEntry = fetchByRepositoryId_First(repositoryId,
1613 orderByComparator);
1614
1615 if (repositoryEntry != null) {
1616 return repositoryEntry;
1617 }
1618
1619 StringBundler msg = new StringBundler(4);
1620
1621 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1622
1623 msg.append("repositoryId=");
1624 msg.append(repositoryId);
1625
1626 msg.append(StringPool.CLOSE_CURLY_BRACE);
1627
1628 throw new NoSuchRepositoryEntryException(msg.toString());
1629 }
1630
1631
1638 @Override
1639 public RepositoryEntry fetchByRepositoryId_First(long repositoryId,
1640 OrderByComparator<RepositoryEntry> orderByComparator) {
1641 List<RepositoryEntry> list = findByRepositoryId(repositoryId, 0, 1,
1642 orderByComparator);
1643
1644 if (!list.isEmpty()) {
1645 return list.get(0);
1646 }
1647
1648 return null;
1649 }
1650
1651
1659 @Override
1660 public RepositoryEntry findByRepositoryId_Last(long repositoryId,
1661 OrderByComparator<RepositoryEntry> orderByComparator)
1662 throws NoSuchRepositoryEntryException {
1663 RepositoryEntry repositoryEntry = fetchByRepositoryId_Last(repositoryId,
1664 orderByComparator);
1665
1666 if (repositoryEntry != null) {
1667 return repositoryEntry;
1668 }
1669
1670 StringBundler msg = new StringBundler(4);
1671
1672 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1673
1674 msg.append("repositoryId=");
1675 msg.append(repositoryId);
1676
1677 msg.append(StringPool.CLOSE_CURLY_BRACE);
1678
1679 throw new NoSuchRepositoryEntryException(msg.toString());
1680 }
1681
1682
1689 @Override
1690 public RepositoryEntry fetchByRepositoryId_Last(long repositoryId,
1691 OrderByComparator<RepositoryEntry> orderByComparator) {
1692 int count = countByRepositoryId(repositoryId);
1693
1694 if (count == 0) {
1695 return null;
1696 }
1697
1698 List<RepositoryEntry> list = findByRepositoryId(repositoryId,
1699 count - 1, count, orderByComparator);
1700
1701 if (!list.isEmpty()) {
1702 return list.get(0);
1703 }
1704
1705 return null;
1706 }
1707
1708
1717 @Override
1718 public RepositoryEntry[] findByRepositoryId_PrevAndNext(
1719 long repositoryEntryId, long repositoryId,
1720 OrderByComparator<RepositoryEntry> orderByComparator)
1721 throws NoSuchRepositoryEntryException {
1722 RepositoryEntry repositoryEntry = findByPrimaryKey(repositoryEntryId);
1723
1724 Session session = null;
1725
1726 try {
1727 session = openSession();
1728
1729 RepositoryEntry[] array = new RepositoryEntryImpl[3];
1730
1731 array[0] = getByRepositoryId_PrevAndNext(session, repositoryEntry,
1732 repositoryId, orderByComparator, true);
1733
1734 array[1] = repositoryEntry;
1735
1736 array[2] = getByRepositoryId_PrevAndNext(session, repositoryEntry,
1737 repositoryId, orderByComparator, false);
1738
1739 return array;
1740 }
1741 catch (Exception e) {
1742 throw processException(e);
1743 }
1744 finally {
1745 closeSession(session);
1746 }
1747 }
1748
1749 protected RepositoryEntry getByRepositoryId_PrevAndNext(Session session,
1750 RepositoryEntry repositoryEntry, long repositoryId,
1751 OrderByComparator<RepositoryEntry> orderByComparator, boolean previous) {
1752 StringBundler query = null;
1753
1754 if (orderByComparator != null) {
1755 query = new StringBundler(6 +
1756 (orderByComparator.getOrderByFields().length * 6));
1757 }
1758 else {
1759 query = new StringBundler(3);
1760 }
1761
1762 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
1763
1764 query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
1765
1766 if (orderByComparator != null) {
1767 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1768
1769 if (orderByConditionFields.length > 0) {
1770 query.append(WHERE_AND);
1771 }
1772
1773 for (int i = 0; i < orderByConditionFields.length; i++) {
1774 query.append(_ORDER_BY_ENTITY_ALIAS);
1775 query.append(orderByConditionFields[i]);
1776
1777 if ((i + 1) < orderByConditionFields.length) {
1778 if (orderByComparator.isAscending() ^ previous) {
1779 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1780 }
1781 else {
1782 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1783 }
1784 }
1785 else {
1786 if (orderByComparator.isAscending() ^ previous) {
1787 query.append(WHERE_GREATER_THAN);
1788 }
1789 else {
1790 query.append(WHERE_LESSER_THAN);
1791 }
1792 }
1793 }
1794
1795 query.append(ORDER_BY_CLAUSE);
1796
1797 String[] orderByFields = orderByComparator.getOrderByFields();
1798
1799 for (int i = 0; i < orderByFields.length; i++) {
1800 query.append(_ORDER_BY_ENTITY_ALIAS);
1801 query.append(orderByFields[i]);
1802
1803 if ((i + 1) < orderByFields.length) {
1804 if (orderByComparator.isAscending() ^ previous) {
1805 query.append(ORDER_BY_ASC_HAS_NEXT);
1806 }
1807 else {
1808 query.append(ORDER_BY_DESC_HAS_NEXT);
1809 }
1810 }
1811 else {
1812 if (orderByComparator.isAscending() ^ previous) {
1813 query.append(ORDER_BY_ASC);
1814 }
1815 else {
1816 query.append(ORDER_BY_DESC);
1817 }
1818 }
1819 }
1820 }
1821 else {
1822 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
1823 }
1824
1825 String sql = query.toString();
1826
1827 Query q = session.createQuery(sql);
1828
1829 q.setFirstResult(0);
1830 q.setMaxResults(2);
1831
1832 QueryPos qPos = QueryPos.getInstance(q);
1833
1834 qPos.add(repositoryId);
1835
1836 if (orderByComparator != null) {
1837 Object[] values = orderByComparator.getOrderByConditionValues(repositoryEntry);
1838
1839 for (Object value : values) {
1840 qPos.add(value);
1841 }
1842 }
1843
1844 List<RepositoryEntry> list = q.list();
1845
1846 if (list.size() == 2) {
1847 return list.get(1);
1848 }
1849 else {
1850 return null;
1851 }
1852 }
1853
1854
1859 @Override
1860 public void removeByRepositoryId(long repositoryId) {
1861 for (RepositoryEntry repositoryEntry : findByRepositoryId(
1862 repositoryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1863 remove(repositoryEntry);
1864 }
1865 }
1866
1867
1873 @Override
1874 public int countByRepositoryId(long repositoryId) {
1875 FinderPath finderPath = FINDER_PATH_COUNT_BY_REPOSITORYID;
1876
1877 Object[] finderArgs = new Object[] { repositoryId };
1878
1879 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1880 this);
1881
1882 if (count == null) {
1883 StringBundler query = new StringBundler(2);
1884
1885 query.append(_SQL_COUNT_REPOSITORYENTRY_WHERE);
1886
1887 query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
1888
1889 String sql = query.toString();
1890
1891 Session session = null;
1892
1893 try {
1894 session = openSession();
1895
1896 Query q = session.createQuery(sql);
1897
1898 QueryPos qPos = QueryPos.getInstance(q);
1899
1900 qPos.add(repositoryId);
1901
1902 count = (Long)q.uniqueResult();
1903
1904 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1905 }
1906 catch (Exception e) {
1907 FinderCacheUtil.removeResult(finderPath, finderArgs);
1908
1909 throw processException(e);
1910 }
1911 finally {
1912 closeSession(session);
1913 }
1914 }
1915
1916 return count.intValue();
1917 }
1918
1919 private static final String _FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2 = "repositoryEntry.repositoryId = ?";
1920 public static final FinderPath FINDER_PATH_FETCH_BY_R_M = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
1921 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
1922 RepositoryEntryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByR_M",
1923 new String[] { Long.class.getName(), String.class.getName() },
1924 RepositoryEntryModelImpl.REPOSITORYID_COLUMN_BITMASK |
1925 RepositoryEntryModelImpl.MAPPEDID_COLUMN_BITMASK);
1926 public static final FinderPath FINDER_PATH_COUNT_BY_R_M = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
1927 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1928 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_M",
1929 new String[] { Long.class.getName(), String.class.getName() });
1930
1931
1939 @Override
1940 public RepositoryEntry findByR_M(long repositoryId, String mappedId)
1941 throws NoSuchRepositoryEntryException {
1942 RepositoryEntry repositoryEntry = fetchByR_M(repositoryId, mappedId);
1943
1944 if (repositoryEntry == null) {
1945 StringBundler msg = new StringBundler(6);
1946
1947 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1948
1949 msg.append("repositoryId=");
1950 msg.append(repositoryId);
1951
1952 msg.append(", mappedId=");
1953 msg.append(mappedId);
1954
1955 msg.append(StringPool.CLOSE_CURLY_BRACE);
1956
1957 if (_log.isWarnEnabled()) {
1958 _log.warn(msg.toString());
1959 }
1960
1961 throw new NoSuchRepositoryEntryException(msg.toString());
1962 }
1963
1964 return repositoryEntry;
1965 }
1966
1967
1974 @Override
1975 public RepositoryEntry fetchByR_M(long repositoryId, String mappedId) {
1976 return fetchByR_M(repositoryId, mappedId, true);
1977 }
1978
1979
1987 @Override
1988 public RepositoryEntry fetchByR_M(long repositoryId, String mappedId,
1989 boolean retrieveFromCache) {
1990 Object[] finderArgs = new Object[] { repositoryId, mappedId };
1991
1992 Object result = null;
1993
1994 if (retrieveFromCache) {
1995 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_R_M,
1996 finderArgs, this);
1997 }
1998
1999 if (result instanceof RepositoryEntry) {
2000 RepositoryEntry repositoryEntry = (RepositoryEntry)result;
2001
2002 if ((repositoryId != repositoryEntry.getRepositoryId()) ||
2003 !Validator.equals(mappedId, repositoryEntry.getMappedId())) {
2004 result = null;
2005 }
2006 }
2007
2008 if (result == null) {
2009 StringBundler query = new StringBundler(4);
2010
2011 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
2012
2013 query.append(_FINDER_COLUMN_R_M_REPOSITORYID_2);
2014
2015 boolean bindMappedId = false;
2016
2017 if (mappedId == null) {
2018 query.append(_FINDER_COLUMN_R_M_MAPPEDID_1);
2019 }
2020 else if (mappedId.equals(StringPool.BLANK)) {
2021 query.append(_FINDER_COLUMN_R_M_MAPPEDID_3);
2022 }
2023 else {
2024 bindMappedId = true;
2025
2026 query.append(_FINDER_COLUMN_R_M_MAPPEDID_2);
2027 }
2028
2029 String sql = query.toString();
2030
2031 Session session = null;
2032
2033 try {
2034 session = openSession();
2035
2036 Query q = session.createQuery(sql);
2037
2038 QueryPos qPos = QueryPos.getInstance(q);
2039
2040 qPos.add(repositoryId);
2041
2042 if (bindMappedId) {
2043 qPos.add(mappedId);
2044 }
2045
2046 List<RepositoryEntry> list = q.list();
2047
2048 if (list.isEmpty()) {
2049 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_M,
2050 finderArgs, list);
2051 }
2052 else {
2053 RepositoryEntry repositoryEntry = list.get(0);
2054
2055 result = repositoryEntry;
2056
2057 cacheResult(repositoryEntry);
2058
2059 if ((repositoryEntry.getRepositoryId() != repositoryId) ||
2060 (repositoryEntry.getMappedId() == null) ||
2061 !repositoryEntry.getMappedId().equals(mappedId)) {
2062 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_M,
2063 finderArgs, repositoryEntry);
2064 }
2065 }
2066 }
2067 catch (Exception e) {
2068 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_M,
2069 finderArgs);
2070
2071 throw processException(e);
2072 }
2073 finally {
2074 closeSession(session);
2075 }
2076 }
2077
2078 if (result instanceof List<?>) {
2079 return null;
2080 }
2081 else {
2082 return (RepositoryEntry)result;
2083 }
2084 }
2085
2086
2093 @Override
2094 public RepositoryEntry removeByR_M(long repositoryId, String mappedId)
2095 throws NoSuchRepositoryEntryException {
2096 RepositoryEntry repositoryEntry = findByR_M(repositoryId, mappedId);
2097
2098 return remove(repositoryEntry);
2099 }
2100
2101
2108 @Override
2109 public int countByR_M(long repositoryId, String mappedId) {
2110 FinderPath finderPath = FINDER_PATH_COUNT_BY_R_M;
2111
2112 Object[] finderArgs = new Object[] { repositoryId, mappedId };
2113
2114 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2115 this);
2116
2117 if (count == null) {
2118 StringBundler query = new StringBundler(3);
2119
2120 query.append(_SQL_COUNT_REPOSITORYENTRY_WHERE);
2121
2122 query.append(_FINDER_COLUMN_R_M_REPOSITORYID_2);
2123
2124 boolean bindMappedId = false;
2125
2126 if (mappedId == null) {
2127 query.append(_FINDER_COLUMN_R_M_MAPPEDID_1);
2128 }
2129 else if (mappedId.equals(StringPool.BLANK)) {
2130 query.append(_FINDER_COLUMN_R_M_MAPPEDID_3);
2131 }
2132 else {
2133 bindMappedId = true;
2134
2135 query.append(_FINDER_COLUMN_R_M_MAPPEDID_2);
2136 }
2137
2138 String sql = query.toString();
2139
2140 Session session = null;
2141
2142 try {
2143 session = openSession();
2144
2145 Query q = session.createQuery(sql);
2146
2147 QueryPos qPos = QueryPos.getInstance(q);
2148
2149 qPos.add(repositoryId);
2150
2151 if (bindMappedId) {
2152 qPos.add(mappedId);
2153 }
2154
2155 count = (Long)q.uniqueResult();
2156
2157 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2158 }
2159 catch (Exception e) {
2160 FinderCacheUtil.removeResult(finderPath, finderArgs);
2161
2162 throw processException(e);
2163 }
2164 finally {
2165 closeSession(session);
2166 }
2167 }
2168
2169 return count.intValue();
2170 }
2171
2172 private static final String _FINDER_COLUMN_R_M_REPOSITORYID_2 = "repositoryEntry.repositoryId = ? AND ";
2173 private static final String _FINDER_COLUMN_R_M_MAPPEDID_1 = "repositoryEntry.mappedId IS NULL";
2174 private static final String _FINDER_COLUMN_R_M_MAPPEDID_2 = "repositoryEntry.mappedId = ?";
2175 private static final String _FINDER_COLUMN_R_M_MAPPEDID_3 = "(repositoryEntry.mappedId IS NULL OR repositoryEntry.mappedId = '')";
2176
2177 public RepositoryEntryPersistenceImpl() {
2178 setModelClass(RepositoryEntry.class);
2179 }
2180
2181
2186 @Override
2187 public void cacheResult(RepositoryEntry repositoryEntry) {
2188 EntityCacheUtil.putResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2189 RepositoryEntryImpl.class, repositoryEntry.getPrimaryKey(),
2190 repositoryEntry);
2191
2192 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2193 new Object[] { repositoryEntry.getUuid(), repositoryEntry.getGroupId() },
2194 repositoryEntry);
2195
2196 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_M,
2197 new Object[] {
2198 repositoryEntry.getRepositoryId(), repositoryEntry.getMappedId()
2199 }, repositoryEntry);
2200
2201 repositoryEntry.resetOriginalValues();
2202 }
2203
2204
2209 @Override
2210 public void cacheResult(List<RepositoryEntry> repositoryEntries) {
2211 for (RepositoryEntry repositoryEntry : repositoryEntries) {
2212 if (EntityCacheUtil.getResult(
2213 RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2214 RepositoryEntryImpl.class,
2215 repositoryEntry.getPrimaryKey()) == null) {
2216 cacheResult(repositoryEntry);
2217 }
2218 else {
2219 repositoryEntry.resetOriginalValues();
2220 }
2221 }
2222 }
2223
2224
2231 @Override
2232 public void clearCache() {
2233 EntityCacheUtil.clearCache(RepositoryEntryImpl.class);
2234
2235 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2236 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2237 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2238 }
2239
2240
2247 @Override
2248 public void clearCache(RepositoryEntry repositoryEntry) {
2249 EntityCacheUtil.removeResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2250 RepositoryEntryImpl.class, repositoryEntry.getPrimaryKey());
2251
2252 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2253 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2254
2255 clearUniqueFindersCache(repositoryEntry);
2256 }
2257
2258 @Override
2259 public void clearCache(List<RepositoryEntry> repositoryEntries) {
2260 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2261 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2262
2263 for (RepositoryEntry repositoryEntry : repositoryEntries) {
2264 EntityCacheUtil.removeResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2265 RepositoryEntryImpl.class, repositoryEntry.getPrimaryKey());
2266
2267 clearUniqueFindersCache(repositoryEntry);
2268 }
2269 }
2270
2271 protected void cacheUniqueFindersCache(RepositoryEntry repositoryEntry) {
2272 if (repositoryEntry.isNew()) {
2273 Object[] args = new Object[] {
2274 repositoryEntry.getUuid(), repositoryEntry.getGroupId()
2275 };
2276
2277 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2278 Long.valueOf(1));
2279 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2280 repositoryEntry);
2281
2282 args = new Object[] {
2283 repositoryEntry.getRepositoryId(),
2284 repositoryEntry.getMappedId()
2285 };
2286
2287 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_M, args,
2288 Long.valueOf(1));
2289 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_M, args,
2290 repositoryEntry);
2291 }
2292 else {
2293 RepositoryEntryModelImpl repositoryEntryModelImpl = (RepositoryEntryModelImpl)repositoryEntry;
2294
2295 if ((repositoryEntryModelImpl.getColumnBitmask() &
2296 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2297 Object[] args = new Object[] {
2298 repositoryEntry.getUuid(), repositoryEntry.getGroupId()
2299 };
2300
2301 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2302 Long.valueOf(1));
2303 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2304 repositoryEntry);
2305 }
2306
2307 if ((repositoryEntryModelImpl.getColumnBitmask() &
2308 FINDER_PATH_FETCH_BY_R_M.getColumnBitmask()) != 0) {
2309 Object[] args = new Object[] {
2310 repositoryEntry.getRepositoryId(),
2311 repositoryEntry.getMappedId()
2312 };
2313
2314 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_M, args,
2315 Long.valueOf(1));
2316 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_M, args,
2317 repositoryEntry);
2318 }
2319 }
2320 }
2321
2322 protected void clearUniqueFindersCache(RepositoryEntry repositoryEntry) {
2323 RepositoryEntryModelImpl repositoryEntryModelImpl = (RepositoryEntryModelImpl)repositoryEntry;
2324
2325 Object[] args = new Object[] {
2326 repositoryEntry.getUuid(), repositoryEntry.getGroupId()
2327 };
2328
2329 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2330 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2331
2332 if ((repositoryEntryModelImpl.getColumnBitmask() &
2333 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2334 args = new Object[] {
2335 repositoryEntryModelImpl.getOriginalUuid(),
2336 repositoryEntryModelImpl.getOriginalGroupId()
2337 };
2338
2339 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2340 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2341 }
2342
2343 args = new Object[] {
2344 repositoryEntry.getRepositoryId(), repositoryEntry.getMappedId()
2345 };
2346
2347 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_M, args);
2348 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_M, args);
2349
2350 if ((repositoryEntryModelImpl.getColumnBitmask() &
2351 FINDER_PATH_FETCH_BY_R_M.getColumnBitmask()) != 0) {
2352 args = new Object[] {
2353 repositoryEntryModelImpl.getOriginalRepositoryId(),
2354 repositoryEntryModelImpl.getOriginalMappedId()
2355 };
2356
2357 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_M, args);
2358 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_M, args);
2359 }
2360 }
2361
2362
2368 @Override
2369 public RepositoryEntry create(long repositoryEntryId) {
2370 RepositoryEntry repositoryEntry = new RepositoryEntryImpl();
2371
2372 repositoryEntry.setNew(true);
2373 repositoryEntry.setPrimaryKey(repositoryEntryId);
2374
2375 String uuid = PortalUUIDUtil.generate();
2376
2377 repositoryEntry.setUuid(uuid);
2378
2379 return repositoryEntry;
2380 }
2381
2382
2389 @Override
2390 public RepositoryEntry remove(long repositoryEntryId)
2391 throws NoSuchRepositoryEntryException {
2392 return remove((Serializable)repositoryEntryId);
2393 }
2394
2395
2402 @Override
2403 public RepositoryEntry remove(Serializable primaryKey)
2404 throws NoSuchRepositoryEntryException {
2405 Session session = null;
2406
2407 try {
2408 session = openSession();
2409
2410 RepositoryEntry repositoryEntry = (RepositoryEntry)session.get(RepositoryEntryImpl.class,
2411 primaryKey);
2412
2413 if (repositoryEntry == null) {
2414 if (_log.isWarnEnabled()) {
2415 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2416 }
2417
2418 throw new NoSuchRepositoryEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2419 primaryKey);
2420 }
2421
2422 return remove(repositoryEntry);
2423 }
2424 catch (NoSuchRepositoryEntryException nsee) {
2425 throw nsee;
2426 }
2427 catch (Exception e) {
2428 throw processException(e);
2429 }
2430 finally {
2431 closeSession(session);
2432 }
2433 }
2434
2435 @Override
2436 protected RepositoryEntry removeImpl(RepositoryEntry repositoryEntry) {
2437 repositoryEntry = toUnwrappedModel(repositoryEntry);
2438
2439 Session session = null;
2440
2441 try {
2442 session = openSession();
2443
2444 if (!session.contains(repositoryEntry)) {
2445 repositoryEntry = (RepositoryEntry)session.get(RepositoryEntryImpl.class,
2446 repositoryEntry.getPrimaryKeyObj());
2447 }
2448
2449 if (repositoryEntry != null) {
2450 session.delete(repositoryEntry);
2451 }
2452 }
2453 catch (Exception e) {
2454 throw processException(e);
2455 }
2456 finally {
2457 closeSession(session);
2458 }
2459
2460 if (repositoryEntry != null) {
2461 clearCache(repositoryEntry);
2462 }
2463
2464 return repositoryEntry;
2465 }
2466
2467 @Override
2468 public RepositoryEntry updateImpl(RepositoryEntry repositoryEntry) {
2469 repositoryEntry = toUnwrappedModel(repositoryEntry);
2470
2471 boolean isNew = repositoryEntry.isNew();
2472
2473 RepositoryEntryModelImpl repositoryEntryModelImpl = (RepositoryEntryModelImpl)repositoryEntry;
2474
2475 if (Validator.isNull(repositoryEntry.getUuid())) {
2476 String uuid = PortalUUIDUtil.generate();
2477
2478 repositoryEntry.setUuid(uuid);
2479 }
2480
2481 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
2482
2483 Date now = new Date();
2484
2485 if (isNew && (repositoryEntry.getCreateDate() == null)) {
2486 if (serviceContext == null) {
2487 repositoryEntry.setCreateDate(now);
2488 }
2489 else {
2490 repositoryEntry.setCreateDate(serviceContext.getCreateDate(now));
2491 }
2492 }
2493
2494 if (!repositoryEntryModelImpl.hasSetModifiedDate()) {
2495 if (serviceContext == null) {
2496 repositoryEntry.setModifiedDate(now);
2497 }
2498 else {
2499 repositoryEntry.setModifiedDate(serviceContext.getModifiedDate(
2500 now));
2501 }
2502 }
2503
2504 Session session = null;
2505
2506 try {
2507 session = openSession();
2508
2509 if (repositoryEntry.isNew()) {
2510 session.save(repositoryEntry);
2511
2512 repositoryEntry.setNew(false);
2513 }
2514 else {
2515 session.merge(repositoryEntry);
2516 }
2517 }
2518 catch (Exception e) {
2519 throw processException(e);
2520 }
2521 finally {
2522 closeSession(session);
2523 }
2524
2525 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2526
2527 if (isNew || !RepositoryEntryModelImpl.COLUMN_BITMASK_ENABLED) {
2528 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2529 }
2530
2531 else {
2532 if ((repositoryEntryModelImpl.getColumnBitmask() &
2533 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2534 Object[] args = new Object[] {
2535 repositoryEntryModelImpl.getOriginalUuid()
2536 };
2537
2538 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2539 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2540 args);
2541
2542 args = new Object[] { repositoryEntryModelImpl.getUuid() };
2543
2544 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2545 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2546 args);
2547 }
2548
2549 if ((repositoryEntryModelImpl.getColumnBitmask() &
2550 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2551 Object[] args = new Object[] {
2552 repositoryEntryModelImpl.getOriginalUuid(),
2553 repositoryEntryModelImpl.getOriginalCompanyId()
2554 };
2555
2556 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2557 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2558 args);
2559
2560 args = new Object[] {
2561 repositoryEntryModelImpl.getUuid(),
2562 repositoryEntryModelImpl.getCompanyId()
2563 };
2564
2565 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2566 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2567 args);
2568 }
2569
2570 if ((repositoryEntryModelImpl.getColumnBitmask() &
2571 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID.getColumnBitmask()) != 0) {
2572 Object[] args = new Object[] {
2573 repositoryEntryModelImpl.getOriginalRepositoryId()
2574 };
2575
2576 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID,
2577 args);
2578 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID,
2579 args);
2580
2581 args = new Object[] { repositoryEntryModelImpl.getRepositoryId() };
2582
2583 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID,
2584 args);
2585 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID,
2586 args);
2587 }
2588 }
2589
2590 EntityCacheUtil.putResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2591 RepositoryEntryImpl.class, repositoryEntry.getPrimaryKey(),
2592 repositoryEntry, false);
2593
2594 clearUniqueFindersCache(repositoryEntry);
2595 cacheUniqueFindersCache(repositoryEntry);
2596
2597 repositoryEntry.resetOriginalValues();
2598
2599 return repositoryEntry;
2600 }
2601
2602 protected RepositoryEntry toUnwrappedModel(RepositoryEntry repositoryEntry) {
2603 if (repositoryEntry instanceof RepositoryEntryImpl) {
2604 return repositoryEntry;
2605 }
2606
2607 RepositoryEntryImpl repositoryEntryImpl = new RepositoryEntryImpl();
2608
2609 repositoryEntryImpl.setNew(repositoryEntry.isNew());
2610 repositoryEntryImpl.setPrimaryKey(repositoryEntry.getPrimaryKey());
2611
2612 repositoryEntryImpl.setMvccVersion(repositoryEntry.getMvccVersion());
2613 repositoryEntryImpl.setUuid(repositoryEntry.getUuid());
2614 repositoryEntryImpl.setRepositoryEntryId(repositoryEntry.getRepositoryEntryId());
2615 repositoryEntryImpl.setGroupId(repositoryEntry.getGroupId());
2616 repositoryEntryImpl.setCompanyId(repositoryEntry.getCompanyId());
2617 repositoryEntryImpl.setUserId(repositoryEntry.getUserId());
2618 repositoryEntryImpl.setUserName(repositoryEntry.getUserName());
2619 repositoryEntryImpl.setCreateDate(repositoryEntry.getCreateDate());
2620 repositoryEntryImpl.setModifiedDate(repositoryEntry.getModifiedDate());
2621 repositoryEntryImpl.setRepositoryId(repositoryEntry.getRepositoryId());
2622 repositoryEntryImpl.setMappedId(repositoryEntry.getMappedId());
2623 repositoryEntryImpl.setManualCheckInRequired(repositoryEntry.isManualCheckInRequired());
2624
2625 return repositoryEntryImpl;
2626 }
2627
2628
2635 @Override
2636 public RepositoryEntry findByPrimaryKey(Serializable primaryKey)
2637 throws NoSuchRepositoryEntryException {
2638 RepositoryEntry repositoryEntry = fetchByPrimaryKey(primaryKey);
2639
2640 if (repositoryEntry == null) {
2641 if (_log.isWarnEnabled()) {
2642 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2643 }
2644
2645 throw new NoSuchRepositoryEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2646 primaryKey);
2647 }
2648
2649 return repositoryEntry;
2650 }
2651
2652
2659 @Override
2660 public RepositoryEntry findByPrimaryKey(long repositoryEntryId)
2661 throws NoSuchRepositoryEntryException {
2662 return findByPrimaryKey((Serializable)repositoryEntryId);
2663 }
2664
2665
2671 @Override
2672 public RepositoryEntry fetchByPrimaryKey(Serializable primaryKey) {
2673 RepositoryEntry repositoryEntry = (RepositoryEntry)EntityCacheUtil.getResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2674 RepositoryEntryImpl.class, primaryKey);
2675
2676 if (repositoryEntry == _nullRepositoryEntry) {
2677 return null;
2678 }
2679
2680 if (repositoryEntry == null) {
2681 Session session = null;
2682
2683 try {
2684 session = openSession();
2685
2686 repositoryEntry = (RepositoryEntry)session.get(RepositoryEntryImpl.class,
2687 primaryKey);
2688
2689 if (repositoryEntry != null) {
2690 cacheResult(repositoryEntry);
2691 }
2692 else {
2693 EntityCacheUtil.putResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2694 RepositoryEntryImpl.class, primaryKey,
2695 _nullRepositoryEntry);
2696 }
2697 }
2698 catch (Exception e) {
2699 EntityCacheUtil.removeResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2700 RepositoryEntryImpl.class, primaryKey);
2701
2702 throw processException(e);
2703 }
2704 finally {
2705 closeSession(session);
2706 }
2707 }
2708
2709 return repositoryEntry;
2710 }
2711
2712
2718 @Override
2719 public RepositoryEntry fetchByPrimaryKey(long repositoryEntryId) {
2720 return fetchByPrimaryKey((Serializable)repositoryEntryId);
2721 }
2722
2723 @Override
2724 public Map<Serializable, RepositoryEntry> fetchByPrimaryKeys(
2725 Set<Serializable> primaryKeys) {
2726 if (primaryKeys.isEmpty()) {
2727 return Collections.emptyMap();
2728 }
2729
2730 Map<Serializable, RepositoryEntry> map = new HashMap<Serializable, RepositoryEntry>();
2731
2732 if (primaryKeys.size() == 1) {
2733 Iterator<Serializable> iterator = primaryKeys.iterator();
2734
2735 Serializable primaryKey = iterator.next();
2736
2737 RepositoryEntry repositoryEntry = fetchByPrimaryKey(primaryKey);
2738
2739 if (repositoryEntry != null) {
2740 map.put(primaryKey, repositoryEntry);
2741 }
2742
2743 return map;
2744 }
2745
2746 Set<Serializable> uncachedPrimaryKeys = null;
2747
2748 for (Serializable primaryKey : primaryKeys) {
2749 RepositoryEntry repositoryEntry = (RepositoryEntry)EntityCacheUtil.getResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2750 RepositoryEntryImpl.class, primaryKey);
2751
2752 if (repositoryEntry == null) {
2753 if (uncachedPrimaryKeys == null) {
2754 uncachedPrimaryKeys = new HashSet<Serializable>();
2755 }
2756
2757 uncachedPrimaryKeys.add(primaryKey);
2758 }
2759 else {
2760 map.put(primaryKey, repositoryEntry);
2761 }
2762 }
2763
2764 if (uncachedPrimaryKeys == null) {
2765 return map;
2766 }
2767
2768 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2769 1);
2770
2771 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE_PKS_IN);
2772
2773 for (Serializable primaryKey : uncachedPrimaryKeys) {
2774 query.append(String.valueOf(primaryKey));
2775
2776 query.append(StringPool.COMMA);
2777 }
2778
2779 query.setIndex(query.index() - 1);
2780
2781 query.append(StringPool.CLOSE_PARENTHESIS);
2782
2783 String sql = query.toString();
2784
2785 Session session = null;
2786
2787 try {
2788 session = openSession();
2789
2790 Query q = session.createQuery(sql);
2791
2792 for (RepositoryEntry repositoryEntry : (List<RepositoryEntry>)q.list()) {
2793 map.put(repositoryEntry.getPrimaryKeyObj(), repositoryEntry);
2794
2795 cacheResult(repositoryEntry);
2796
2797 uncachedPrimaryKeys.remove(repositoryEntry.getPrimaryKeyObj());
2798 }
2799
2800 for (Serializable primaryKey : uncachedPrimaryKeys) {
2801 EntityCacheUtil.putResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2802 RepositoryEntryImpl.class, primaryKey, _nullRepositoryEntry);
2803 }
2804 }
2805 catch (Exception e) {
2806 throw processException(e);
2807 }
2808 finally {
2809 closeSession(session);
2810 }
2811
2812 return map;
2813 }
2814
2815
2820 @Override
2821 public List<RepositoryEntry> findAll() {
2822 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2823 }
2824
2825
2836 @Override
2837 public List<RepositoryEntry> findAll(int start, int end) {
2838 return findAll(start, end, null);
2839 }
2840
2841
2853 @Override
2854 public List<RepositoryEntry> findAll(int start, int end,
2855 OrderByComparator<RepositoryEntry> orderByComparator) {
2856 boolean pagination = true;
2857 FinderPath finderPath = null;
2858 Object[] finderArgs = null;
2859
2860 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2861 (orderByComparator == null)) {
2862 pagination = false;
2863 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2864 finderArgs = FINDER_ARGS_EMPTY;
2865 }
2866 else {
2867 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2868 finderArgs = new Object[] { start, end, orderByComparator };
2869 }
2870
2871 List<RepositoryEntry> list = (List<RepositoryEntry>)FinderCacheUtil.getResult(finderPath,
2872 finderArgs, this);
2873
2874 if (list == null) {
2875 StringBundler query = null;
2876 String sql = null;
2877
2878 if (orderByComparator != null) {
2879 query = new StringBundler(2 +
2880 (orderByComparator.getOrderByFields().length * 3));
2881
2882 query.append(_SQL_SELECT_REPOSITORYENTRY);
2883
2884 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2885 orderByComparator);
2886
2887 sql = query.toString();
2888 }
2889 else {
2890 sql = _SQL_SELECT_REPOSITORYENTRY;
2891
2892 if (pagination) {
2893 sql = sql.concat(RepositoryEntryModelImpl.ORDER_BY_JPQL);
2894 }
2895 }
2896
2897 Session session = null;
2898
2899 try {
2900 session = openSession();
2901
2902 Query q = session.createQuery(sql);
2903
2904 if (!pagination) {
2905 list = (List<RepositoryEntry>)QueryUtil.list(q,
2906 getDialect(), start, end, false);
2907
2908 Collections.sort(list);
2909
2910 list = Collections.unmodifiableList(list);
2911 }
2912 else {
2913 list = (List<RepositoryEntry>)QueryUtil.list(q,
2914 getDialect(), start, end);
2915 }
2916
2917 cacheResult(list);
2918
2919 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2920 }
2921 catch (Exception e) {
2922 FinderCacheUtil.removeResult(finderPath, finderArgs);
2923
2924 throw processException(e);
2925 }
2926 finally {
2927 closeSession(session);
2928 }
2929 }
2930
2931 return list;
2932 }
2933
2934
2938 @Override
2939 public void removeAll() {
2940 for (RepositoryEntry repositoryEntry : findAll()) {
2941 remove(repositoryEntry);
2942 }
2943 }
2944
2945
2950 @Override
2951 public int countAll() {
2952 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2953 FINDER_ARGS_EMPTY, this);
2954
2955 if (count == null) {
2956 Session session = null;
2957
2958 try {
2959 session = openSession();
2960
2961 Query q = session.createQuery(_SQL_COUNT_REPOSITORYENTRY);
2962
2963 count = (Long)q.uniqueResult();
2964
2965 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2966 FINDER_ARGS_EMPTY, count);
2967 }
2968 catch (Exception e) {
2969 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2970 FINDER_ARGS_EMPTY);
2971
2972 throw processException(e);
2973 }
2974 finally {
2975 closeSession(session);
2976 }
2977 }
2978
2979 return count.intValue();
2980 }
2981
2982 @Override
2983 protected Set<String> getBadColumnNames() {
2984 return _badColumnNames;
2985 }
2986
2987
2990 public void afterPropertiesSet() {
2991 }
2992
2993 public void destroy() {
2994 EntityCacheUtil.removeCache(RepositoryEntryImpl.class.getName());
2995 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2996 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2997 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2998 }
2999
3000 private static final String _SQL_SELECT_REPOSITORYENTRY = "SELECT repositoryEntry FROM RepositoryEntry repositoryEntry";
3001 private static final String _SQL_SELECT_REPOSITORYENTRY_WHERE_PKS_IN = "SELECT repositoryEntry FROM RepositoryEntry repositoryEntry WHERE repositoryEntryId IN (";
3002 private static final String _SQL_SELECT_REPOSITORYENTRY_WHERE = "SELECT repositoryEntry FROM RepositoryEntry repositoryEntry WHERE ";
3003 private static final String _SQL_COUNT_REPOSITORYENTRY = "SELECT COUNT(repositoryEntry) FROM RepositoryEntry repositoryEntry";
3004 private static final String _SQL_COUNT_REPOSITORYENTRY_WHERE = "SELECT COUNT(repositoryEntry) FROM RepositoryEntry repositoryEntry WHERE ";
3005 private static final String _ORDER_BY_ENTITY_ALIAS = "repositoryEntry.";
3006 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RepositoryEntry exists with the primary key ";
3007 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RepositoryEntry exists with the key {";
3008 private static final Log _log = LogFactoryUtil.getLog(RepositoryEntryPersistenceImpl.class);
3009 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3010 "uuid"
3011 });
3012 private static final RepositoryEntry _nullRepositoryEntry = new RepositoryEntryImpl() {
3013 @Override
3014 public Object clone() {
3015 return this;
3016 }
3017
3018 @Override
3019 public CacheModel<RepositoryEntry> toCacheModel() {
3020 return _nullRepositoryEntryCacheModel;
3021 }
3022 };
3023
3024 private static final CacheModel<RepositoryEntry> _nullRepositoryEntryCacheModel =
3025 new NullCacheModel();
3026
3027 private static class NullCacheModel implements CacheModel<RepositoryEntry>,
3028 MVCCModel {
3029 @Override
3030 public long getMvccVersion() {
3031 return -1;
3032 }
3033
3034 @Override
3035 public void setMvccVersion(long mvccVersion) {
3036 }
3037
3038 @Override
3039 public RepositoryEntry toEntityModel() {
3040 return _nullRepositoryEntry;
3041 }
3042 }
3043 }