001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchRepositoryEntryException;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
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.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.CacheModel;
040 import com.liferay.portal.model.ModelListener;
041 import com.liferay.portal.model.RepositoryEntry;
042 import com.liferay.portal.model.impl.RepositoryEntryImpl;
043 import com.liferay.portal.model.impl.RepositoryEntryModelImpl;
044 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045
046 import java.io.Serializable;
047
048 import java.util.ArrayList;
049 import java.util.Collections;
050 import java.util.List;
051
052
064 public class RepositoryEntryPersistenceImpl extends BasePersistenceImpl<RepositoryEntry>
065 implements RepositoryEntryPersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = RepositoryEntryImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
077 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
078 RepositoryEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
079 "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
081 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
082 RepositoryEntryImpl.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
085 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
088 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
089 RepositoryEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
090 "findByUuid",
091 new String[] {
092 String.class.getName(),
093
094 Integer.class.getName(), Integer.class.getName(),
095 OrderByComparator.class.getName()
096 });
097 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
098 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
099 RepositoryEntryImpl.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
101 new String[] { String.class.getName() },
102 RepositoryEntryModelImpl.UUID_COLUMN_BITMASK);
103 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
104 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
106 new String[] { String.class.getName() });
107
108
115 public List<RepositoryEntry> findByUuid(String uuid)
116 throws SystemException {
117 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118 }
119
120
133 public List<RepositoryEntry> findByUuid(String uuid, int start, int end)
134 throws SystemException {
135 return findByUuid(uuid, start, end, null);
136 }
137
138
152 public List<RepositoryEntry> findByUuid(String uuid, int start, int end,
153 OrderByComparator orderByComparator) throws SystemException {
154 boolean pagination = true;
155 FinderPath finderPath = null;
156 Object[] finderArgs = null;
157
158 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159 (orderByComparator == null)) {
160 pagination = false;
161 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
162 finderArgs = new Object[] { uuid };
163 }
164 else {
165 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
166 finderArgs = new Object[] { uuid, start, end, orderByComparator };
167 }
168
169 List<RepositoryEntry> list = (List<RepositoryEntry>)FinderCacheUtil.getResult(finderPath,
170 finderArgs, this);
171
172 if ((list != null) && !list.isEmpty()) {
173 for (RepositoryEntry repositoryEntry : list) {
174 if (!Validator.equals(uuid, repositoryEntry.getUuid())) {
175 list = null;
176
177 break;
178 }
179 }
180 }
181
182 if (list == null) {
183 StringBundler query = null;
184
185 if (orderByComparator != null) {
186 query = new StringBundler(3 +
187 (orderByComparator.getOrderByFields().length * 3));
188 }
189 else {
190 query = new StringBundler(3);
191 }
192
193 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
194
195 if (uuid == null) {
196 query.append(_FINDER_COLUMN_UUID_UUID_1);
197 }
198 else {
199 if (uuid.equals(StringPool.BLANK)) {
200 query.append(_FINDER_COLUMN_UUID_UUID_3);
201 }
202 else {
203 query.append(_FINDER_COLUMN_UUID_UUID_2);
204 }
205 }
206
207 if (orderByComparator != null) {
208 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
209 orderByComparator);
210 }
211 else
212 if (pagination) {
213 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
214 }
215
216 String sql = query.toString();
217
218 Session session = null;
219
220 try {
221 session = openSession();
222
223 Query q = session.createQuery(sql);
224
225 QueryPos qPos = QueryPos.getInstance(q);
226
227 if (uuid != null) {
228 qPos.add(uuid);
229 }
230
231 if (!pagination) {
232 list = (List<RepositoryEntry>)QueryUtil.list(q,
233 getDialect(), start, end, false);
234
235 Collections.sort(list);
236
237 list = new UnmodifiableList<RepositoryEntry>(list);
238 }
239 else {
240 list = (List<RepositoryEntry>)QueryUtil.list(q,
241 getDialect(), start, end);
242 }
243
244 cacheResult(list);
245
246 FinderCacheUtil.putResult(finderPath, finderArgs, list);
247 }
248 catch (Exception e) {
249 FinderCacheUtil.removeResult(finderPath, finderArgs);
250
251 throw processException(e);
252 }
253 finally {
254 closeSession(session);
255 }
256 }
257
258 return list;
259 }
260
261
270 public RepositoryEntry findByUuid_First(String uuid,
271 OrderByComparator orderByComparator)
272 throws NoSuchRepositoryEntryException, SystemException {
273 RepositoryEntry repositoryEntry = fetchByUuid_First(uuid,
274 orderByComparator);
275
276 if (repositoryEntry != null) {
277 return repositoryEntry;
278 }
279
280 StringBundler msg = new StringBundler(4);
281
282 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
283
284 msg.append("uuid=");
285 msg.append(uuid);
286
287 msg.append(StringPool.CLOSE_CURLY_BRACE);
288
289 throw new NoSuchRepositoryEntryException(msg.toString());
290 }
291
292
300 public RepositoryEntry fetchByUuid_First(String uuid,
301 OrderByComparator orderByComparator) throws SystemException {
302 List<RepositoryEntry> list = findByUuid(uuid, 0, 1, orderByComparator);
303
304 if (!list.isEmpty()) {
305 return list.get(0);
306 }
307
308 return null;
309 }
310
311
320 public RepositoryEntry findByUuid_Last(String uuid,
321 OrderByComparator orderByComparator)
322 throws NoSuchRepositoryEntryException, SystemException {
323 RepositoryEntry repositoryEntry = fetchByUuid_Last(uuid,
324 orderByComparator);
325
326 if (repositoryEntry != null) {
327 return repositoryEntry;
328 }
329
330 StringBundler msg = new StringBundler(4);
331
332 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
333
334 msg.append("uuid=");
335 msg.append(uuid);
336
337 msg.append(StringPool.CLOSE_CURLY_BRACE);
338
339 throw new NoSuchRepositoryEntryException(msg.toString());
340 }
341
342
350 public RepositoryEntry fetchByUuid_Last(String uuid,
351 OrderByComparator orderByComparator) throws SystemException {
352 int count = countByUuid(uuid);
353
354 List<RepositoryEntry> list = findByUuid(uuid, count - 1, count,
355 orderByComparator);
356
357 if (!list.isEmpty()) {
358 return list.get(0);
359 }
360
361 return null;
362 }
363
364
374 public RepositoryEntry[] findByUuid_PrevAndNext(long repositoryEntryId,
375 String uuid, OrderByComparator orderByComparator)
376 throws NoSuchRepositoryEntryException, SystemException {
377 RepositoryEntry repositoryEntry = findByPrimaryKey(repositoryEntryId);
378
379 Session session = null;
380
381 try {
382 session = openSession();
383
384 RepositoryEntry[] array = new RepositoryEntryImpl[3];
385
386 array[0] = getByUuid_PrevAndNext(session, repositoryEntry, uuid,
387 orderByComparator, true);
388
389 array[1] = repositoryEntry;
390
391 array[2] = getByUuid_PrevAndNext(session, repositoryEntry, uuid,
392 orderByComparator, false);
393
394 return array;
395 }
396 catch (Exception e) {
397 throw processException(e);
398 }
399 finally {
400 closeSession(session);
401 }
402 }
403
404 protected RepositoryEntry getByUuid_PrevAndNext(Session session,
405 RepositoryEntry repositoryEntry, String uuid,
406 OrderByComparator orderByComparator, boolean previous) {
407 StringBundler query = null;
408
409 if (orderByComparator != null) {
410 query = new StringBundler(6 +
411 (orderByComparator.getOrderByFields().length * 6));
412 }
413 else {
414 query = new StringBundler(3);
415 }
416
417 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
418
419 if (uuid == null) {
420 query.append(_FINDER_COLUMN_UUID_UUID_1);
421 }
422 else {
423 if (uuid.equals(StringPool.BLANK)) {
424 query.append(_FINDER_COLUMN_UUID_UUID_3);
425 }
426 else {
427 query.append(_FINDER_COLUMN_UUID_UUID_2);
428 }
429 }
430
431 if (orderByComparator != null) {
432 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
433
434 if (orderByConditionFields.length > 0) {
435 query.append(WHERE_AND);
436 }
437
438 for (int i = 0; i < orderByConditionFields.length; i++) {
439 query.append(_ORDER_BY_ENTITY_ALIAS);
440 query.append(orderByConditionFields[i]);
441
442 if ((i + 1) < orderByConditionFields.length) {
443 if (orderByComparator.isAscending() ^ previous) {
444 query.append(WHERE_GREATER_THAN_HAS_NEXT);
445 }
446 else {
447 query.append(WHERE_LESSER_THAN_HAS_NEXT);
448 }
449 }
450 else {
451 if (orderByComparator.isAscending() ^ previous) {
452 query.append(WHERE_GREATER_THAN);
453 }
454 else {
455 query.append(WHERE_LESSER_THAN);
456 }
457 }
458 }
459
460 query.append(ORDER_BY_CLAUSE);
461
462 String[] orderByFields = orderByComparator.getOrderByFields();
463
464 for (int i = 0; i < orderByFields.length; i++) {
465 query.append(_ORDER_BY_ENTITY_ALIAS);
466 query.append(orderByFields[i]);
467
468 if ((i + 1) < orderByFields.length) {
469 if (orderByComparator.isAscending() ^ previous) {
470 query.append(ORDER_BY_ASC_HAS_NEXT);
471 }
472 else {
473 query.append(ORDER_BY_DESC_HAS_NEXT);
474 }
475 }
476 else {
477 if (orderByComparator.isAscending() ^ previous) {
478 query.append(ORDER_BY_ASC);
479 }
480 else {
481 query.append(ORDER_BY_DESC);
482 }
483 }
484 }
485 }
486 else {
487 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
488 }
489
490 String sql = query.toString();
491
492 Query q = session.createQuery(sql);
493
494 q.setFirstResult(0);
495 q.setMaxResults(2);
496
497 QueryPos qPos = QueryPos.getInstance(q);
498
499 if (uuid != null) {
500 qPos.add(uuid);
501 }
502
503 if (orderByComparator != null) {
504 Object[] values = orderByComparator.getOrderByConditionValues(repositoryEntry);
505
506 for (Object value : values) {
507 qPos.add(value);
508 }
509 }
510
511 List<RepositoryEntry> list = q.list();
512
513 if (list.size() == 2) {
514 return list.get(1);
515 }
516 else {
517 return null;
518 }
519 }
520
521
527 public void removeByUuid(String uuid) throws SystemException {
528 for (RepositoryEntry repositoryEntry : findByUuid(uuid,
529 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
530 remove(repositoryEntry);
531 }
532 }
533
534
541 public int countByUuid(String uuid) throws SystemException {
542 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
543
544 Object[] finderArgs = new Object[] { uuid };
545
546 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
547 this);
548
549 if (count == null) {
550 StringBundler query = new StringBundler(2);
551
552 query.append(_SQL_COUNT_REPOSITORYENTRY_WHERE);
553
554 if (uuid == null) {
555 query.append(_FINDER_COLUMN_UUID_UUID_1);
556 }
557 else {
558 if (uuid.equals(StringPool.BLANK)) {
559 query.append(_FINDER_COLUMN_UUID_UUID_3);
560 }
561 else {
562 query.append(_FINDER_COLUMN_UUID_UUID_2);
563 }
564 }
565
566 String sql = query.toString();
567
568 Session session = null;
569
570 try {
571 session = openSession();
572
573 Query q = session.createQuery(sql);
574
575 QueryPos qPos = QueryPos.getInstance(q);
576
577 if (uuid != null) {
578 qPos.add(uuid);
579 }
580
581 count = (Long)q.uniqueResult();
582
583 FinderCacheUtil.putResult(finderPath, finderArgs, count);
584 }
585 catch (Exception e) {
586 FinderCacheUtil.removeResult(finderPath, finderArgs);
587
588 throw processException(e);
589 }
590 finally {
591 closeSession(session);
592 }
593 }
594
595 return count.intValue();
596 }
597
598 private static final String _FINDER_COLUMN_UUID_UUID_1 = "repositoryEntry.uuid IS NULL";
599 private static final String _FINDER_COLUMN_UUID_UUID_2 = "repositoryEntry.uuid = ?";
600 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(repositoryEntry.uuid IS NULL OR repositoryEntry.uuid = ?)";
601 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
602 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
603 RepositoryEntryImpl.class, FINDER_CLASS_NAME_ENTITY,
604 "fetchByUUID_G",
605 new String[] { String.class.getName(), Long.class.getName() },
606 RepositoryEntryModelImpl.UUID_COLUMN_BITMASK |
607 RepositoryEntryModelImpl.GROUPID_COLUMN_BITMASK);
608 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
609 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
610 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
611 new String[] { String.class.getName(), Long.class.getName() });
612
613
622 public RepositoryEntry findByUUID_G(String uuid, long groupId)
623 throws NoSuchRepositoryEntryException, SystemException {
624 RepositoryEntry repositoryEntry = fetchByUUID_G(uuid, groupId);
625
626 if (repositoryEntry == null) {
627 StringBundler msg = new StringBundler(6);
628
629 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
630
631 msg.append("uuid=");
632 msg.append(uuid);
633
634 msg.append(", groupId=");
635 msg.append(groupId);
636
637 msg.append(StringPool.CLOSE_CURLY_BRACE);
638
639 if (_log.isWarnEnabled()) {
640 _log.warn(msg.toString());
641 }
642
643 throw new NoSuchRepositoryEntryException(msg.toString());
644 }
645
646 return repositoryEntry;
647 }
648
649
657 public RepositoryEntry fetchByUUID_G(String uuid, long groupId)
658 throws SystemException {
659 return fetchByUUID_G(uuid, groupId, true);
660 }
661
662
671 public RepositoryEntry fetchByUUID_G(String uuid, long groupId,
672 boolean retrieveFromCache) throws SystemException {
673 Object[] finderArgs = new Object[] { uuid, groupId };
674
675 Object result = null;
676
677 if (retrieveFromCache) {
678 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
679 finderArgs, this);
680 }
681
682 if (result instanceof RepositoryEntry) {
683 RepositoryEntry repositoryEntry = (RepositoryEntry)result;
684
685 if (!Validator.equals(uuid, repositoryEntry.getUuid()) ||
686 (groupId != repositoryEntry.getGroupId())) {
687 result = null;
688 }
689 }
690
691 if (result == null) {
692 StringBundler query = new StringBundler(4);
693
694 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
695
696 if (uuid == null) {
697 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
698 }
699 else {
700 if (uuid.equals(StringPool.BLANK)) {
701 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
702 }
703 else {
704 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
705 }
706 }
707
708 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
709
710 String sql = query.toString();
711
712 Session session = null;
713
714 try {
715 session = openSession();
716
717 Query q = session.createQuery(sql);
718
719 QueryPos qPos = QueryPos.getInstance(q);
720
721 if (uuid != null) {
722 qPos.add(uuid);
723 }
724
725 qPos.add(groupId);
726
727 List<RepositoryEntry> list = q.list();
728
729 if (list.isEmpty()) {
730 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
731 finderArgs, list);
732 }
733 else {
734 RepositoryEntry repositoryEntry = list.get(0);
735
736 result = repositoryEntry;
737
738 cacheResult(repositoryEntry);
739
740 if ((repositoryEntry.getUuid() == null) ||
741 !repositoryEntry.getUuid().equals(uuid) ||
742 (repositoryEntry.getGroupId() != groupId)) {
743 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
744 finderArgs, repositoryEntry);
745 }
746 }
747 }
748 catch (Exception e) {
749 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
750 finderArgs);
751
752 throw processException(e);
753 }
754 finally {
755 closeSession(session);
756 }
757 }
758
759 if (result instanceof List<?>) {
760 return null;
761 }
762 else {
763 return (RepositoryEntry)result;
764 }
765 }
766
767
775 public RepositoryEntry removeByUUID_G(String uuid, long groupId)
776 throws NoSuchRepositoryEntryException, SystemException {
777 RepositoryEntry repositoryEntry = findByUUID_G(uuid, groupId);
778
779 return remove(repositoryEntry);
780 }
781
782
790 public int countByUUID_G(String uuid, long groupId)
791 throws SystemException {
792 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
793
794 Object[] finderArgs = new Object[] { uuid, groupId };
795
796 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
797 this);
798
799 if (count == null) {
800 StringBundler query = new StringBundler(3);
801
802 query.append(_SQL_COUNT_REPOSITORYENTRY_WHERE);
803
804 if (uuid == null) {
805 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
806 }
807 else {
808 if (uuid.equals(StringPool.BLANK)) {
809 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
810 }
811 else {
812 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
813 }
814 }
815
816 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
817
818 String sql = query.toString();
819
820 Session session = null;
821
822 try {
823 session = openSession();
824
825 Query q = session.createQuery(sql);
826
827 QueryPos qPos = QueryPos.getInstance(q);
828
829 if (uuid != null) {
830 qPos.add(uuid);
831 }
832
833 qPos.add(groupId);
834
835 count = (Long)q.uniqueResult();
836
837 FinderCacheUtil.putResult(finderPath, finderArgs, count);
838 }
839 catch (Exception e) {
840 FinderCacheUtil.removeResult(finderPath, finderArgs);
841
842 throw processException(e);
843 }
844 finally {
845 closeSession(session);
846 }
847 }
848
849 return count.intValue();
850 }
851
852 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "repositoryEntry.uuid IS NULL AND ";
853 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "repositoryEntry.uuid = ? AND ";
854 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(repositoryEntry.uuid IS NULL OR repositoryEntry.uuid = ?) AND ";
855 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "repositoryEntry.groupId = ?";
856 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_REPOSITORYID =
857 new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
858 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
859 RepositoryEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
860 "findByRepositoryId",
861 new String[] {
862 Long.class.getName(),
863
864 Integer.class.getName(), Integer.class.getName(),
865 OrderByComparator.class.getName()
866 });
867 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID =
868 new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
869 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
870 RepositoryEntryImpl.class,
871 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRepositoryId",
872 new String[] { Long.class.getName() },
873 RepositoryEntryModelImpl.REPOSITORYID_COLUMN_BITMASK);
874 public static final FinderPath FINDER_PATH_COUNT_BY_REPOSITORYID = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
875 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
876 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRepositoryId",
877 new String[] { Long.class.getName() });
878
879
886 public List<RepositoryEntry> findByRepositoryId(long repositoryId)
887 throws SystemException {
888 return findByRepositoryId(repositoryId, QueryUtil.ALL_POS,
889 QueryUtil.ALL_POS, null);
890 }
891
892
905 public List<RepositoryEntry> findByRepositoryId(long repositoryId,
906 int start, int end) throws SystemException {
907 return findByRepositoryId(repositoryId, start, end, null);
908 }
909
910
924 public List<RepositoryEntry> findByRepositoryId(long repositoryId,
925 int start, int end, OrderByComparator orderByComparator)
926 throws SystemException {
927 boolean pagination = true;
928 FinderPath finderPath = null;
929 Object[] finderArgs = null;
930
931 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
932 (orderByComparator == null)) {
933 pagination = false;
934 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID;
935 finderArgs = new Object[] { repositoryId };
936 }
937 else {
938 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_REPOSITORYID;
939 finderArgs = new Object[] {
940 repositoryId,
941
942 start, end, orderByComparator
943 };
944 }
945
946 List<RepositoryEntry> list = (List<RepositoryEntry>)FinderCacheUtil.getResult(finderPath,
947 finderArgs, this);
948
949 if ((list != null) && !list.isEmpty()) {
950 for (RepositoryEntry repositoryEntry : list) {
951 if ((repositoryId != repositoryEntry.getRepositoryId())) {
952 list = null;
953
954 break;
955 }
956 }
957 }
958
959 if (list == null) {
960 StringBundler query = null;
961
962 if (orderByComparator != null) {
963 query = new StringBundler(3 +
964 (orderByComparator.getOrderByFields().length * 3));
965 }
966 else {
967 query = new StringBundler(3);
968 }
969
970 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
971
972 query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
973
974 if (orderByComparator != null) {
975 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
976 orderByComparator);
977 }
978 else
979 if (pagination) {
980 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
981 }
982
983 String sql = query.toString();
984
985 Session session = null;
986
987 try {
988 session = openSession();
989
990 Query q = session.createQuery(sql);
991
992 QueryPos qPos = QueryPos.getInstance(q);
993
994 qPos.add(repositoryId);
995
996 if (!pagination) {
997 list = (List<RepositoryEntry>)QueryUtil.list(q,
998 getDialect(), start, end, false);
999
1000 Collections.sort(list);
1001
1002 list = new UnmodifiableList<RepositoryEntry>(list);
1003 }
1004 else {
1005 list = (List<RepositoryEntry>)QueryUtil.list(q,
1006 getDialect(), start, end);
1007 }
1008
1009 cacheResult(list);
1010
1011 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1012 }
1013 catch (Exception e) {
1014 FinderCacheUtil.removeResult(finderPath, finderArgs);
1015
1016 throw processException(e);
1017 }
1018 finally {
1019 closeSession(session);
1020 }
1021 }
1022
1023 return list;
1024 }
1025
1026
1035 public RepositoryEntry findByRepositoryId_First(long repositoryId,
1036 OrderByComparator orderByComparator)
1037 throws NoSuchRepositoryEntryException, SystemException {
1038 RepositoryEntry repositoryEntry = fetchByRepositoryId_First(repositoryId,
1039 orderByComparator);
1040
1041 if (repositoryEntry != null) {
1042 return repositoryEntry;
1043 }
1044
1045 StringBundler msg = new StringBundler(4);
1046
1047 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1048
1049 msg.append("repositoryId=");
1050 msg.append(repositoryId);
1051
1052 msg.append(StringPool.CLOSE_CURLY_BRACE);
1053
1054 throw new NoSuchRepositoryEntryException(msg.toString());
1055 }
1056
1057
1065 public RepositoryEntry fetchByRepositoryId_First(long repositoryId,
1066 OrderByComparator orderByComparator) throws SystemException {
1067 List<RepositoryEntry> list = findByRepositoryId(repositoryId, 0, 1,
1068 orderByComparator);
1069
1070 if (!list.isEmpty()) {
1071 return list.get(0);
1072 }
1073
1074 return null;
1075 }
1076
1077
1086 public RepositoryEntry findByRepositoryId_Last(long repositoryId,
1087 OrderByComparator orderByComparator)
1088 throws NoSuchRepositoryEntryException, SystemException {
1089 RepositoryEntry repositoryEntry = fetchByRepositoryId_Last(repositoryId,
1090 orderByComparator);
1091
1092 if (repositoryEntry != null) {
1093 return repositoryEntry;
1094 }
1095
1096 StringBundler msg = new StringBundler(4);
1097
1098 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1099
1100 msg.append("repositoryId=");
1101 msg.append(repositoryId);
1102
1103 msg.append(StringPool.CLOSE_CURLY_BRACE);
1104
1105 throw new NoSuchRepositoryEntryException(msg.toString());
1106 }
1107
1108
1116 public RepositoryEntry fetchByRepositoryId_Last(long repositoryId,
1117 OrderByComparator orderByComparator) throws SystemException {
1118 int count = countByRepositoryId(repositoryId);
1119
1120 List<RepositoryEntry> list = findByRepositoryId(repositoryId,
1121 count - 1, count, orderByComparator);
1122
1123 if (!list.isEmpty()) {
1124 return list.get(0);
1125 }
1126
1127 return null;
1128 }
1129
1130
1140 public RepositoryEntry[] findByRepositoryId_PrevAndNext(
1141 long repositoryEntryId, long repositoryId,
1142 OrderByComparator orderByComparator)
1143 throws NoSuchRepositoryEntryException, SystemException {
1144 RepositoryEntry repositoryEntry = findByPrimaryKey(repositoryEntryId);
1145
1146 Session session = null;
1147
1148 try {
1149 session = openSession();
1150
1151 RepositoryEntry[] array = new RepositoryEntryImpl[3];
1152
1153 array[0] = getByRepositoryId_PrevAndNext(session, repositoryEntry,
1154 repositoryId, orderByComparator, true);
1155
1156 array[1] = repositoryEntry;
1157
1158 array[2] = getByRepositoryId_PrevAndNext(session, repositoryEntry,
1159 repositoryId, orderByComparator, false);
1160
1161 return array;
1162 }
1163 catch (Exception e) {
1164 throw processException(e);
1165 }
1166 finally {
1167 closeSession(session);
1168 }
1169 }
1170
1171 protected RepositoryEntry getByRepositoryId_PrevAndNext(Session session,
1172 RepositoryEntry repositoryEntry, long repositoryId,
1173 OrderByComparator orderByComparator, boolean previous) {
1174 StringBundler query = null;
1175
1176 if (orderByComparator != null) {
1177 query = new StringBundler(6 +
1178 (orderByComparator.getOrderByFields().length * 6));
1179 }
1180 else {
1181 query = new StringBundler(3);
1182 }
1183
1184 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
1185
1186 query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
1187
1188 if (orderByComparator != null) {
1189 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1190
1191 if (orderByConditionFields.length > 0) {
1192 query.append(WHERE_AND);
1193 }
1194
1195 for (int i = 0; i < orderByConditionFields.length; i++) {
1196 query.append(_ORDER_BY_ENTITY_ALIAS);
1197 query.append(orderByConditionFields[i]);
1198
1199 if ((i + 1) < orderByConditionFields.length) {
1200 if (orderByComparator.isAscending() ^ previous) {
1201 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1202 }
1203 else {
1204 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1205 }
1206 }
1207 else {
1208 if (orderByComparator.isAscending() ^ previous) {
1209 query.append(WHERE_GREATER_THAN);
1210 }
1211 else {
1212 query.append(WHERE_LESSER_THAN);
1213 }
1214 }
1215 }
1216
1217 query.append(ORDER_BY_CLAUSE);
1218
1219 String[] orderByFields = orderByComparator.getOrderByFields();
1220
1221 for (int i = 0; i < orderByFields.length; i++) {
1222 query.append(_ORDER_BY_ENTITY_ALIAS);
1223 query.append(orderByFields[i]);
1224
1225 if ((i + 1) < orderByFields.length) {
1226 if (orderByComparator.isAscending() ^ previous) {
1227 query.append(ORDER_BY_ASC_HAS_NEXT);
1228 }
1229 else {
1230 query.append(ORDER_BY_DESC_HAS_NEXT);
1231 }
1232 }
1233 else {
1234 if (orderByComparator.isAscending() ^ previous) {
1235 query.append(ORDER_BY_ASC);
1236 }
1237 else {
1238 query.append(ORDER_BY_DESC);
1239 }
1240 }
1241 }
1242 }
1243 else {
1244 query.append(RepositoryEntryModelImpl.ORDER_BY_JPQL);
1245 }
1246
1247 String sql = query.toString();
1248
1249 Query q = session.createQuery(sql);
1250
1251 q.setFirstResult(0);
1252 q.setMaxResults(2);
1253
1254 QueryPos qPos = QueryPos.getInstance(q);
1255
1256 qPos.add(repositoryId);
1257
1258 if (orderByComparator != null) {
1259 Object[] values = orderByComparator.getOrderByConditionValues(repositoryEntry);
1260
1261 for (Object value : values) {
1262 qPos.add(value);
1263 }
1264 }
1265
1266 List<RepositoryEntry> list = q.list();
1267
1268 if (list.size() == 2) {
1269 return list.get(1);
1270 }
1271 else {
1272 return null;
1273 }
1274 }
1275
1276
1282 public void removeByRepositoryId(long repositoryId)
1283 throws SystemException {
1284 for (RepositoryEntry repositoryEntry : findByRepositoryId(
1285 repositoryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1286 remove(repositoryEntry);
1287 }
1288 }
1289
1290
1297 public int countByRepositoryId(long repositoryId) throws SystemException {
1298 FinderPath finderPath = FINDER_PATH_COUNT_BY_REPOSITORYID;
1299
1300 Object[] finderArgs = new Object[] { repositoryId };
1301
1302 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1303 this);
1304
1305 if (count == null) {
1306 StringBundler query = new StringBundler(2);
1307
1308 query.append(_SQL_COUNT_REPOSITORYENTRY_WHERE);
1309
1310 query.append(_FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2);
1311
1312 String sql = query.toString();
1313
1314 Session session = null;
1315
1316 try {
1317 session = openSession();
1318
1319 Query q = session.createQuery(sql);
1320
1321 QueryPos qPos = QueryPos.getInstance(q);
1322
1323 qPos.add(repositoryId);
1324
1325 count = (Long)q.uniqueResult();
1326
1327 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1328 }
1329 catch (Exception e) {
1330 FinderCacheUtil.removeResult(finderPath, finderArgs);
1331
1332 throw processException(e);
1333 }
1334 finally {
1335 closeSession(session);
1336 }
1337 }
1338
1339 return count.intValue();
1340 }
1341
1342 private static final String _FINDER_COLUMN_REPOSITORYID_REPOSITORYID_2 = "repositoryEntry.repositoryId = ?";
1343 public static final FinderPath FINDER_PATH_FETCH_BY_R_M = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
1344 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED,
1345 RepositoryEntryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByR_M",
1346 new String[] { Long.class.getName(), String.class.getName() },
1347 RepositoryEntryModelImpl.REPOSITORYID_COLUMN_BITMASK |
1348 RepositoryEntryModelImpl.MAPPEDID_COLUMN_BITMASK);
1349 public static final FinderPath FINDER_PATH_COUNT_BY_R_M = new FinderPath(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
1350 RepositoryEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1351 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_M",
1352 new String[] { Long.class.getName(), String.class.getName() });
1353
1354
1363 public RepositoryEntry findByR_M(long repositoryId, String mappedId)
1364 throws NoSuchRepositoryEntryException, SystemException {
1365 RepositoryEntry repositoryEntry = fetchByR_M(repositoryId, mappedId);
1366
1367 if (repositoryEntry == null) {
1368 StringBundler msg = new StringBundler(6);
1369
1370 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1371
1372 msg.append("repositoryId=");
1373 msg.append(repositoryId);
1374
1375 msg.append(", mappedId=");
1376 msg.append(mappedId);
1377
1378 msg.append(StringPool.CLOSE_CURLY_BRACE);
1379
1380 if (_log.isWarnEnabled()) {
1381 _log.warn(msg.toString());
1382 }
1383
1384 throw new NoSuchRepositoryEntryException(msg.toString());
1385 }
1386
1387 return repositoryEntry;
1388 }
1389
1390
1398 public RepositoryEntry fetchByR_M(long repositoryId, String mappedId)
1399 throws SystemException {
1400 return fetchByR_M(repositoryId, mappedId, true);
1401 }
1402
1403
1412 public RepositoryEntry fetchByR_M(long repositoryId, String mappedId,
1413 boolean retrieveFromCache) throws SystemException {
1414 Object[] finderArgs = new Object[] { repositoryId, mappedId };
1415
1416 Object result = null;
1417
1418 if (retrieveFromCache) {
1419 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_R_M,
1420 finderArgs, this);
1421 }
1422
1423 if (result instanceof RepositoryEntry) {
1424 RepositoryEntry repositoryEntry = (RepositoryEntry)result;
1425
1426 if ((repositoryId != repositoryEntry.getRepositoryId()) ||
1427 !Validator.equals(mappedId, repositoryEntry.getMappedId())) {
1428 result = null;
1429 }
1430 }
1431
1432 if (result == null) {
1433 StringBundler query = new StringBundler(4);
1434
1435 query.append(_SQL_SELECT_REPOSITORYENTRY_WHERE);
1436
1437 query.append(_FINDER_COLUMN_R_M_REPOSITORYID_2);
1438
1439 if (mappedId == null) {
1440 query.append(_FINDER_COLUMN_R_M_MAPPEDID_1);
1441 }
1442 else {
1443 if (mappedId.equals(StringPool.BLANK)) {
1444 query.append(_FINDER_COLUMN_R_M_MAPPEDID_3);
1445 }
1446 else {
1447 query.append(_FINDER_COLUMN_R_M_MAPPEDID_2);
1448 }
1449 }
1450
1451 String sql = query.toString();
1452
1453 Session session = null;
1454
1455 try {
1456 session = openSession();
1457
1458 Query q = session.createQuery(sql);
1459
1460 QueryPos qPos = QueryPos.getInstance(q);
1461
1462 qPos.add(repositoryId);
1463
1464 if (mappedId != null) {
1465 qPos.add(mappedId);
1466 }
1467
1468 List<RepositoryEntry> list = q.list();
1469
1470 if (list.isEmpty()) {
1471 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_M,
1472 finderArgs, list);
1473 }
1474 else {
1475 RepositoryEntry repositoryEntry = list.get(0);
1476
1477 result = repositoryEntry;
1478
1479 cacheResult(repositoryEntry);
1480
1481 if ((repositoryEntry.getRepositoryId() != repositoryId) ||
1482 (repositoryEntry.getMappedId() == null) ||
1483 !repositoryEntry.getMappedId().equals(mappedId)) {
1484 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_M,
1485 finderArgs, repositoryEntry);
1486 }
1487 }
1488 }
1489 catch (Exception e) {
1490 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_M,
1491 finderArgs);
1492
1493 throw processException(e);
1494 }
1495 finally {
1496 closeSession(session);
1497 }
1498 }
1499
1500 if (result instanceof List<?>) {
1501 return null;
1502 }
1503 else {
1504 return (RepositoryEntry)result;
1505 }
1506 }
1507
1508
1516 public RepositoryEntry removeByR_M(long repositoryId, String mappedId)
1517 throws NoSuchRepositoryEntryException, SystemException {
1518 RepositoryEntry repositoryEntry = findByR_M(repositoryId, mappedId);
1519
1520 return remove(repositoryEntry);
1521 }
1522
1523
1531 public int countByR_M(long repositoryId, String mappedId)
1532 throws SystemException {
1533 FinderPath finderPath = FINDER_PATH_COUNT_BY_R_M;
1534
1535 Object[] finderArgs = new Object[] { repositoryId, mappedId };
1536
1537 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1538 this);
1539
1540 if (count == null) {
1541 StringBundler query = new StringBundler(3);
1542
1543 query.append(_SQL_COUNT_REPOSITORYENTRY_WHERE);
1544
1545 query.append(_FINDER_COLUMN_R_M_REPOSITORYID_2);
1546
1547 if (mappedId == null) {
1548 query.append(_FINDER_COLUMN_R_M_MAPPEDID_1);
1549 }
1550 else {
1551 if (mappedId.equals(StringPool.BLANK)) {
1552 query.append(_FINDER_COLUMN_R_M_MAPPEDID_3);
1553 }
1554 else {
1555 query.append(_FINDER_COLUMN_R_M_MAPPEDID_2);
1556 }
1557 }
1558
1559 String sql = query.toString();
1560
1561 Session session = null;
1562
1563 try {
1564 session = openSession();
1565
1566 Query q = session.createQuery(sql);
1567
1568 QueryPos qPos = QueryPos.getInstance(q);
1569
1570 qPos.add(repositoryId);
1571
1572 if (mappedId != null) {
1573 qPos.add(mappedId);
1574 }
1575
1576 count = (Long)q.uniqueResult();
1577
1578 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1579 }
1580 catch (Exception e) {
1581 FinderCacheUtil.removeResult(finderPath, finderArgs);
1582
1583 throw processException(e);
1584 }
1585 finally {
1586 closeSession(session);
1587 }
1588 }
1589
1590 return count.intValue();
1591 }
1592
1593 private static final String _FINDER_COLUMN_R_M_REPOSITORYID_2 = "repositoryEntry.repositoryId = ? AND ";
1594 private static final String _FINDER_COLUMN_R_M_MAPPEDID_1 = "repositoryEntry.mappedId IS NULL";
1595 private static final String _FINDER_COLUMN_R_M_MAPPEDID_2 = "repositoryEntry.mappedId = ?";
1596 private static final String _FINDER_COLUMN_R_M_MAPPEDID_3 = "(repositoryEntry.mappedId IS NULL OR repositoryEntry.mappedId = ?)";
1597
1598
1603 public void cacheResult(RepositoryEntry repositoryEntry) {
1604 EntityCacheUtil.putResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
1605 RepositoryEntryImpl.class, repositoryEntry.getPrimaryKey(),
1606 repositoryEntry);
1607
1608 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1609 new Object[] {
1610 repositoryEntry.getUuid(),
1611 Long.valueOf(repositoryEntry.getGroupId())
1612 }, repositoryEntry);
1613
1614 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_M,
1615 new Object[] {
1616 Long.valueOf(repositoryEntry.getRepositoryId()),
1617
1618 repositoryEntry.getMappedId()
1619 }, repositoryEntry);
1620
1621 repositoryEntry.resetOriginalValues();
1622 }
1623
1624
1629 public void cacheResult(List<RepositoryEntry> repositoryEntries) {
1630 for (RepositoryEntry repositoryEntry : repositoryEntries) {
1631 if (EntityCacheUtil.getResult(
1632 RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
1633 RepositoryEntryImpl.class,
1634 repositoryEntry.getPrimaryKey()) == null) {
1635 cacheResult(repositoryEntry);
1636 }
1637 else {
1638 repositoryEntry.resetOriginalValues();
1639 }
1640 }
1641 }
1642
1643
1650 @Override
1651 public void clearCache() {
1652 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1653 CacheRegistryUtil.clear(RepositoryEntryImpl.class.getName());
1654 }
1655
1656 EntityCacheUtil.clearCache(RepositoryEntryImpl.class.getName());
1657
1658 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1659 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1660 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1661 }
1662
1663
1670 @Override
1671 public void clearCache(RepositoryEntry repositoryEntry) {
1672 EntityCacheUtil.removeResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
1673 RepositoryEntryImpl.class, repositoryEntry.getPrimaryKey());
1674
1675 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1676 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1677
1678 clearUniqueFindersCache(repositoryEntry);
1679 }
1680
1681 @Override
1682 public void clearCache(List<RepositoryEntry> repositoryEntries) {
1683 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1684 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1685
1686 for (RepositoryEntry repositoryEntry : repositoryEntries) {
1687 EntityCacheUtil.removeResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
1688 RepositoryEntryImpl.class, repositoryEntry.getPrimaryKey());
1689
1690 clearUniqueFindersCache(repositoryEntry);
1691 }
1692 }
1693
1694 protected void cacheUniqueFindersCache(RepositoryEntry repositoryEntry) {
1695 if (repositoryEntry.isNew()) {
1696 Object[] args = new Object[] {
1697 repositoryEntry.getUuid(),
1698 Long.valueOf(repositoryEntry.getGroupId())
1699 };
1700
1701 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
1702 Long.valueOf(1));
1703 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
1704 repositoryEntry);
1705
1706 args = new Object[] {
1707 Long.valueOf(repositoryEntry.getRepositoryId()),
1708
1709 repositoryEntry.getMappedId()
1710 };
1711
1712 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_M, args,
1713 Long.valueOf(1));
1714 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_M, args,
1715 repositoryEntry);
1716 }
1717 else {
1718 RepositoryEntryModelImpl repositoryEntryModelImpl = (RepositoryEntryModelImpl)repositoryEntry;
1719
1720 if ((repositoryEntryModelImpl.getColumnBitmask() &
1721 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
1722 Object[] args = new Object[] {
1723 repositoryEntry.getUuid(),
1724 Long.valueOf(repositoryEntry.getGroupId())
1725 };
1726
1727 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
1728 Long.valueOf(1));
1729 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
1730 repositoryEntry);
1731 }
1732
1733 if ((repositoryEntryModelImpl.getColumnBitmask() &
1734 FINDER_PATH_FETCH_BY_R_M.getColumnBitmask()) != 0) {
1735 Object[] args = new Object[] {
1736 Long.valueOf(repositoryEntry.getRepositoryId()),
1737
1738 repositoryEntry.getMappedId()
1739 };
1740
1741 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_M, args,
1742 Long.valueOf(1));
1743 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_M, args,
1744 repositoryEntry);
1745 }
1746 }
1747 }
1748
1749 protected void clearUniqueFindersCache(RepositoryEntry repositoryEntry) {
1750 RepositoryEntryModelImpl repositoryEntryModelImpl = (RepositoryEntryModelImpl)repositoryEntry;
1751
1752 Object[] args = new Object[] {
1753 repositoryEntry.getUuid(),
1754 Long.valueOf(repositoryEntry.getGroupId())
1755 };
1756
1757 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
1758 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
1759
1760 if ((repositoryEntryModelImpl.getColumnBitmask() &
1761 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
1762 args = new Object[] {
1763 repositoryEntryModelImpl.getOriginalUuid(),
1764 Long.valueOf(repositoryEntryModelImpl.getOriginalGroupId())
1765 };
1766
1767 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
1768 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
1769 }
1770
1771 args = new Object[] {
1772 Long.valueOf(repositoryEntry.getRepositoryId()),
1773
1774 repositoryEntry.getMappedId()
1775 };
1776
1777 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_M, args);
1778 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_M, args);
1779
1780 if ((repositoryEntryModelImpl.getColumnBitmask() &
1781 FINDER_PATH_FETCH_BY_R_M.getColumnBitmask()) != 0) {
1782 args = new Object[] {
1783 Long.valueOf(repositoryEntryModelImpl.getOriginalRepositoryId()),
1784
1785 repositoryEntryModelImpl.getOriginalMappedId()
1786 };
1787
1788 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_M, args);
1789 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_M, args);
1790 }
1791 }
1792
1793
1799 public RepositoryEntry create(long repositoryEntryId) {
1800 RepositoryEntry repositoryEntry = new RepositoryEntryImpl();
1801
1802 repositoryEntry.setNew(true);
1803 repositoryEntry.setPrimaryKey(repositoryEntryId);
1804
1805 String uuid = PortalUUIDUtil.generate();
1806
1807 repositoryEntry.setUuid(uuid);
1808
1809 return repositoryEntry;
1810 }
1811
1812
1820 public RepositoryEntry remove(long repositoryEntryId)
1821 throws NoSuchRepositoryEntryException, SystemException {
1822 return remove(Long.valueOf(repositoryEntryId));
1823 }
1824
1825
1833 @Override
1834 public RepositoryEntry remove(Serializable primaryKey)
1835 throws NoSuchRepositoryEntryException, SystemException {
1836 Session session = null;
1837
1838 try {
1839 session = openSession();
1840
1841 RepositoryEntry repositoryEntry = (RepositoryEntry)session.get(RepositoryEntryImpl.class,
1842 primaryKey);
1843
1844 if (repositoryEntry == null) {
1845 if (_log.isWarnEnabled()) {
1846 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1847 }
1848
1849 throw new NoSuchRepositoryEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1850 primaryKey);
1851 }
1852
1853 return remove(repositoryEntry);
1854 }
1855 catch (NoSuchRepositoryEntryException nsee) {
1856 throw nsee;
1857 }
1858 catch (Exception e) {
1859 throw processException(e);
1860 }
1861 finally {
1862 closeSession(session);
1863 }
1864 }
1865
1866 @Override
1867 protected RepositoryEntry removeImpl(RepositoryEntry repositoryEntry)
1868 throws SystemException {
1869 repositoryEntry = toUnwrappedModel(repositoryEntry);
1870
1871 Session session = null;
1872
1873 try {
1874 session = openSession();
1875
1876 if (!session.contains(repositoryEntry)) {
1877 repositoryEntry = (RepositoryEntry)session.get(RepositoryEntryImpl.class,
1878 repositoryEntry.getPrimaryKeyObj());
1879 }
1880
1881 if (repositoryEntry != null) {
1882 session.delete(repositoryEntry);
1883 }
1884 }
1885 catch (Exception e) {
1886 throw processException(e);
1887 }
1888 finally {
1889 closeSession(session);
1890 }
1891
1892 if (repositoryEntry != null) {
1893 clearCache(repositoryEntry);
1894 }
1895
1896 return repositoryEntry;
1897 }
1898
1899 @Override
1900 public RepositoryEntry updateImpl(
1901 com.liferay.portal.model.RepositoryEntry repositoryEntry)
1902 throws SystemException {
1903 repositoryEntry = toUnwrappedModel(repositoryEntry);
1904
1905 boolean isNew = repositoryEntry.isNew();
1906
1907 RepositoryEntryModelImpl repositoryEntryModelImpl = (RepositoryEntryModelImpl)repositoryEntry;
1908
1909 if (Validator.isNull(repositoryEntry.getUuid())) {
1910 String uuid = PortalUUIDUtil.generate();
1911
1912 repositoryEntry.setUuid(uuid);
1913 }
1914
1915 Session session = null;
1916
1917 try {
1918 session = openSession();
1919
1920 if (repositoryEntry.isNew()) {
1921 session.save(repositoryEntry);
1922
1923 repositoryEntry.setNew(false);
1924 }
1925 else {
1926 session.merge(repositoryEntry);
1927 }
1928 }
1929 catch (Exception e) {
1930 throw processException(e);
1931 }
1932 finally {
1933 closeSession(session);
1934 }
1935
1936 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1937
1938 if (isNew || !RepositoryEntryModelImpl.COLUMN_BITMASK_ENABLED) {
1939 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1940 }
1941
1942 else {
1943 if ((repositoryEntryModelImpl.getColumnBitmask() &
1944 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
1945 Object[] args = new Object[] {
1946 repositoryEntryModelImpl.getOriginalUuid()
1947 };
1948
1949 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
1950 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
1951 args);
1952
1953 args = new Object[] { repositoryEntryModelImpl.getUuid() };
1954
1955 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
1956 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
1957 args);
1958 }
1959
1960 if ((repositoryEntryModelImpl.getColumnBitmask() &
1961 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID.getColumnBitmask()) != 0) {
1962 Object[] args = new Object[] {
1963 Long.valueOf(repositoryEntryModelImpl.getOriginalRepositoryId())
1964 };
1965
1966 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID,
1967 args);
1968 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID,
1969 args);
1970
1971 args = new Object[] {
1972 Long.valueOf(repositoryEntryModelImpl.getRepositoryId())
1973 };
1974
1975 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_REPOSITORYID,
1976 args);
1977 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_REPOSITORYID,
1978 args);
1979 }
1980 }
1981
1982 EntityCacheUtil.putResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
1983 RepositoryEntryImpl.class, repositoryEntry.getPrimaryKey(),
1984 repositoryEntry);
1985
1986 clearUniqueFindersCache(repositoryEntry);
1987 cacheUniqueFindersCache(repositoryEntry);
1988
1989 return repositoryEntry;
1990 }
1991
1992 protected RepositoryEntry toUnwrappedModel(RepositoryEntry repositoryEntry) {
1993 if (repositoryEntry instanceof RepositoryEntryImpl) {
1994 return repositoryEntry;
1995 }
1996
1997 RepositoryEntryImpl repositoryEntryImpl = new RepositoryEntryImpl();
1998
1999 repositoryEntryImpl.setNew(repositoryEntry.isNew());
2000 repositoryEntryImpl.setPrimaryKey(repositoryEntry.getPrimaryKey());
2001
2002 repositoryEntryImpl.setUuid(repositoryEntry.getUuid());
2003 repositoryEntryImpl.setRepositoryEntryId(repositoryEntry.getRepositoryEntryId());
2004 repositoryEntryImpl.setGroupId(repositoryEntry.getGroupId());
2005 repositoryEntryImpl.setRepositoryId(repositoryEntry.getRepositoryId());
2006 repositoryEntryImpl.setMappedId(repositoryEntry.getMappedId());
2007 repositoryEntryImpl.setManualCheckInRequired(repositoryEntry.isManualCheckInRequired());
2008
2009 return repositoryEntryImpl;
2010 }
2011
2012
2020 @Override
2021 public RepositoryEntry findByPrimaryKey(Serializable primaryKey)
2022 throws NoSuchModelException, SystemException {
2023 return findByPrimaryKey(((Long)primaryKey).longValue());
2024 }
2025
2026
2034 public RepositoryEntry findByPrimaryKey(long repositoryEntryId)
2035 throws NoSuchRepositoryEntryException, SystemException {
2036 RepositoryEntry repositoryEntry = fetchByPrimaryKey(repositoryEntryId);
2037
2038 if (repositoryEntry == null) {
2039 if (_log.isWarnEnabled()) {
2040 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + repositoryEntryId);
2041 }
2042
2043 throw new NoSuchRepositoryEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2044 repositoryEntryId);
2045 }
2046
2047 return repositoryEntry;
2048 }
2049
2050
2057 @Override
2058 public RepositoryEntry fetchByPrimaryKey(Serializable primaryKey)
2059 throws SystemException {
2060 return fetchByPrimaryKey(((Long)primaryKey).longValue());
2061 }
2062
2063
2070 public RepositoryEntry fetchByPrimaryKey(long repositoryEntryId)
2071 throws SystemException {
2072 RepositoryEntry repositoryEntry = (RepositoryEntry)EntityCacheUtil.getResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2073 RepositoryEntryImpl.class, repositoryEntryId);
2074
2075 if (repositoryEntry == _nullRepositoryEntry) {
2076 return null;
2077 }
2078
2079 if (repositoryEntry == null) {
2080 Session session = null;
2081
2082 try {
2083 session = openSession();
2084
2085 repositoryEntry = (RepositoryEntry)session.get(RepositoryEntryImpl.class,
2086 Long.valueOf(repositoryEntryId));
2087
2088 if (repositoryEntry != null) {
2089 cacheResult(repositoryEntry);
2090 }
2091 else {
2092 EntityCacheUtil.putResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2093 RepositoryEntryImpl.class, repositoryEntryId,
2094 _nullRepositoryEntry);
2095 }
2096 }
2097 catch (Exception e) {
2098 EntityCacheUtil.removeResult(RepositoryEntryModelImpl.ENTITY_CACHE_ENABLED,
2099 RepositoryEntryImpl.class, repositoryEntryId);
2100
2101 throw processException(e);
2102 }
2103 finally {
2104 closeSession(session);
2105 }
2106 }
2107
2108 return repositoryEntry;
2109 }
2110
2111
2117 public List<RepositoryEntry> findAll() throws SystemException {
2118 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2119 }
2120
2121
2133 public List<RepositoryEntry> findAll(int start, int end)
2134 throws SystemException {
2135 return findAll(start, end, null);
2136 }
2137
2138
2151 public List<RepositoryEntry> findAll(int start, int end,
2152 OrderByComparator orderByComparator) throws SystemException {
2153 boolean pagination = true;
2154 FinderPath finderPath = null;
2155 Object[] finderArgs = null;
2156
2157 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2158 (orderByComparator == null)) {
2159 pagination = false;
2160 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2161 finderArgs = FINDER_ARGS_EMPTY;
2162 }
2163 else {
2164 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2165 finderArgs = new Object[] { start, end, orderByComparator };
2166 }
2167
2168 List<RepositoryEntry> list = (List<RepositoryEntry>)FinderCacheUtil.getResult(finderPath,
2169 finderArgs, this);
2170
2171 if (list == null) {
2172 StringBundler query = null;
2173 String sql = null;
2174
2175 if (orderByComparator != null) {
2176 query = new StringBundler(2 +
2177 (orderByComparator.getOrderByFields().length * 3));
2178
2179 query.append(_SQL_SELECT_REPOSITORYENTRY);
2180
2181 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2182 orderByComparator);
2183
2184 sql = query.toString();
2185 }
2186 else {
2187 sql = _SQL_SELECT_REPOSITORYENTRY;
2188
2189 if (pagination) {
2190 sql = sql.concat(RepositoryEntryModelImpl.ORDER_BY_JPQL);
2191 }
2192 }
2193
2194 Session session = null;
2195
2196 try {
2197 session = openSession();
2198
2199 Query q = session.createQuery(sql);
2200
2201 if (!pagination) {
2202 list = (List<RepositoryEntry>)QueryUtil.list(q,
2203 getDialect(), start, end, false);
2204
2205 Collections.sort(list);
2206
2207 list = new UnmodifiableList<RepositoryEntry>(list);
2208 }
2209 else {
2210 list = (List<RepositoryEntry>)QueryUtil.list(q,
2211 getDialect(), start, end);
2212 }
2213
2214 cacheResult(list);
2215
2216 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2217 }
2218 catch (Exception e) {
2219 FinderCacheUtil.removeResult(finderPath, finderArgs);
2220
2221 throw processException(e);
2222 }
2223 finally {
2224 closeSession(session);
2225 }
2226 }
2227
2228 return list;
2229 }
2230
2231
2236 public void removeAll() throws SystemException {
2237 for (RepositoryEntry repositoryEntry : findAll()) {
2238 remove(repositoryEntry);
2239 }
2240 }
2241
2242
2248 public int countAll() throws SystemException {
2249 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2250 FINDER_ARGS_EMPTY, this);
2251
2252 if (count == null) {
2253 Session session = null;
2254
2255 try {
2256 session = openSession();
2257
2258 Query q = session.createQuery(_SQL_COUNT_REPOSITORYENTRY);
2259
2260 count = (Long)q.uniqueResult();
2261
2262 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2263 FINDER_ARGS_EMPTY, count);
2264 }
2265 catch (Exception e) {
2266 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2267 FINDER_ARGS_EMPTY);
2268
2269 throw processException(e);
2270 }
2271 finally {
2272 closeSession(session);
2273 }
2274 }
2275
2276 return count.intValue();
2277 }
2278
2279
2282 public void afterPropertiesSet() {
2283 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2284 com.liferay.portal.util.PropsUtil.get(
2285 "value.object.listener.com.liferay.portal.model.RepositoryEntry")));
2286
2287 if (listenerClassNames.length > 0) {
2288 try {
2289 List<ModelListener<RepositoryEntry>> listenersList = new ArrayList<ModelListener<RepositoryEntry>>();
2290
2291 for (String listenerClassName : listenerClassNames) {
2292 listenersList.add((ModelListener<RepositoryEntry>)InstanceFactory.newInstance(
2293 listenerClassName));
2294 }
2295
2296 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2297 }
2298 catch (Exception e) {
2299 _log.error(e);
2300 }
2301 }
2302 }
2303
2304 public void destroy() {
2305 EntityCacheUtil.removeCache(RepositoryEntryImpl.class.getName());
2306 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2307 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2308 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2309 }
2310
2311 private static final String _SQL_SELECT_REPOSITORYENTRY = "SELECT repositoryEntry FROM RepositoryEntry repositoryEntry";
2312 private static final String _SQL_SELECT_REPOSITORYENTRY_WHERE = "SELECT repositoryEntry FROM RepositoryEntry repositoryEntry WHERE ";
2313 private static final String _SQL_COUNT_REPOSITORYENTRY = "SELECT COUNT(repositoryEntry) FROM RepositoryEntry repositoryEntry";
2314 private static final String _SQL_COUNT_REPOSITORYENTRY_WHERE = "SELECT COUNT(repositoryEntry) FROM RepositoryEntry repositoryEntry WHERE ";
2315 private static final String _ORDER_BY_ENTITY_ALIAS = "repositoryEntry.";
2316 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RepositoryEntry exists with the primary key ";
2317 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RepositoryEntry exists with the key {";
2318 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2319 private static Log _log = LogFactoryUtil.getLog(RepositoryEntryPersistenceImpl.class);
2320 private static RepositoryEntry _nullRepositoryEntry = new RepositoryEntryImpl() {
2321 @Override
2322 public Object clone() {
2323 return this;
2324 }
2325
2326 @Override
2327 public CacheModel<RepositoryEntry> toCacheModel() {
2328 return _nullRepositoryEntryCacheModel;
2329 }
2330 };
2331
2332 private static CacheModel<RepositoryEntry> _nullRepositoryEntryCacheModel = new CacheModel<RepositoryEntry>() {
2333 public RepositoryEntry toEntityModel() {
2334 return _nullRepositoryEntry;
2335 }
2336 };
2337 }