001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchRepositoryException;
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.model.Repository;
040 import com.liferay.portal.model.impl.RepositoryImpl;
041 import com.liferay.portal.model.impl.RepositoryModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
045 import com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistence;
046 import com.liferay.portlet.documentlibrary.service.persistence.DLFileVersionPersistence;
047 import com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence;
048 import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
049
050 import java.io.Serializable;
051
052 import java.util.ArrayList;
053 import java.util.Collections;
054 import java.util.List;
055
056
068 public class RepositoryPersistenceImpl extends BasePersistenceImpl<Repository>
069 implements RepositoryPersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = RepositoryImpl.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_BY_GROUPID = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
081 RepositoryModelImpl.FINDER_CACHE_ENABLED, RepositoryImpl.class,
082 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
083 new String[] {
084 Long.class.getName(),
085
086 "java.lang.Integer", "java.lang.Integer",
087 "com.liferay.portal.kernel.util.OrderByComparator"
088 });
089 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
090 new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
091 RepositoryModelImpl.FINDER_CACHE_ENABLED, RepositoryImpl.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
093 new String[] { Long.class.getName() },
094 RepositoryModelImpl.GROUPID_COLUMN_BITMASK);
095 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
096 RepositoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
098 new String[] { Long.class.getName() });
099 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
100 RepositoryModelImpl.FINDER_CACHE_ENABLED, RepositoryImpl.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
102 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
103 RepositoryModelImpl.FINDER_CACHE_ENABLED, RepositoryImpl.class,
104 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
105 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
106 RepositoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
108
109
114 public void cacheResult(Repository repository) {
115 EntityCacheUtil.putResult(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
116 RepositoryImpl.class, repository.getPrimaryKey(), repository);
117
118 repository.resetOriginalValues();
119 }
120
121
126 public void cacheResult(List<Repository> repositories) {
127 for (Repository repository : repositories) {
128 if (EntityCacheUtil.getResult(
129 RepositoryModelImpl.ENTITY_CACHE_ENABLED,
130 RepositoryImpl.class, repository.getPrimaryKey()) == null) {
131 cacheResult(repository);
132 }
133 else {
134 repository.resetOriginalValues();
135 }
136 }
137 }
138
139
146 @Override
147 public void clearCache() {
148 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
149 CacheRegistryUtil.clear(RepositoryImpl.class.getName());
150 }
151
152 EntityCacheUtil.clearCache(RepositoryImpl.class.getName());
153
154 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
155 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
156 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
157 }
158
159
166 @Override
167 public void clearCache(Repository repository) {
168 EntityCacheUtil.removeResult(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
169 RepositoryImpl.class, repository.getPrimaryKey());
170
171 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
172 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
173 }
174
175
181 public Repository create(long repositoryId) {
182 Repository repository = new RepositoryImpl();
183
184 repository.setNew(true);
185 repository.setPrimaryKey(repositoryId);
186
187 return repository;
188 }
189
190
198 @Override
199 public Repository remove(Serializable primaryKey)
200 throws NoSuchModelException, SystemException {
201 return remove(((Long)primaryKey).longValue());
202 }
203
204
212 public Repository remove(long repositoryId)
213 throws NoSuchRepositoryException, SystemException {
214 Session session = null;
215
216 try {
217 session = openSession();
218
219 Repository repository = (Repository)session.get(RepositoryImpl.class,
220 Long.valueOf(repositoryId));
221
222 if (repository == null) {
223 if (_log.isWarnEnabled()) {
224 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + repositoryId);
225 }
226
227 throw new NoSuchRepositoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
228 repositoryId);
229 }
230
231 return repositoryPersistence.remove(repository);
232 }
233 catch (NoSuchRepositoryException nsee) {
234 throw nsee;
235 }
236 catch (Exception e) {
237 throw processException(e);
238 }
239 finally {
240 closeSession(session);
241 }
242 }
243
244
251 @Override
252 public Repository remove(Repository repository) throws SystemException {
253 return super.remove(repository);
254 }
255
256 @Override
257 protected Repository removeImpl(Repository repository)
258 throws SystemException {
259 repository = toUnwrappedModel(repository);
260
261 Session session = null;
262
263 try {
264 session = openSession();
265
266 BatchSessionUtil.delete(session, repository);
267 }
268 catch (Exception e) {
269 throw processException(e);
270 }
271 finally {
272 closeSession(session);
273 }
274
275 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
276 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
277
278 EntityCacheUtil.removeResult(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
279 RepositoryImpl.class, repository.getPrimaryKey());
280
281 return repository;
282 }
283
284 @Override
285 public Repository updateImpl(
286 com.liferay.portal.model.Repository repository, boolean merge)
287 throws SystemException {
288 repository = toUnwrappedModel(repository);
289
290 boolean isNew = repository.isNew();
291
292 RepositoryModelImpl repositoryModelImpl = (RepositoryModelImpl)repository;
293
294 Session session = null;
295
296 try {
297 session = openSession();
298
299 BatchSessionUtil.update(session, repository, merge);
300
301 repository.setNew(false);
302 }
303 catch (Exception e) {
304 throw processException(e);
305 }
306 finally {
307 closeSession(session);
308 }
309
310 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
311
312 if (isNew || !RepositoryModelImpl.COLUMN_BITMASK_ENABLED) {
313 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
314 }
315
316 else {
317 if ((repositoryModelImpl.getColumnBitmask() &
318 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
319 Object[] args = new Object[] {
320 Long.valueOf(repositoryModelImpl.getOriginalGroupId())
321 };
322
323 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
324 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
325 args);
326
327 args = new Object[] {
328 Long.valueOf(repositoryModelImpl.getGroupId())
329 };
330
331 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
332 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
333 args);
334 }
335 }
336
337 EntityCacheUtil.putResult(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
338 RepositoryImpl.class, repository.getPrimaryKey(), repository);
339
340 return repository;
341 }
342
343 protected Repository toUnwrappedModel(Repository repository) {
344 if (repository instanceof RepositoryImpl) {
345 return repository;
346 }
347
348 RepositoryImpl repositoryImpl = new RepositoryImpl();
349
350 repositoryImpl.setNew(repository.isNew());
351 repositoryImpl.setPrimaryKey(repository.getPrimaryKey());
352
353 repositoryImpl.setRepositoryId(repository.getRepositoryId());
354 repositoryImpl.setGroupId(repository.getGroupId());
355 repositoryImpl.setCompanyId(repository.getCompanyId());
356 repositoryImpl.setCreateDate(repository.getCreateDate());
357 repositoryImpl.setModifiedDate(repository.getModifiedDate());
358 repositoryImpl.setClassNameId(repository.getClassNameId());
359 repositoryImpl.setName(repository.getName());
360 repositoryImpl.setDescription(repository.getDescription());
361 repositoryImpl.setPortletId(repository.getPortletId());
362 repositoryImpl.setTypeSettings(repository.getTypeSettings());
363 repositoryImpl.setDlFolderId(repository.getDlFolderId());
364
365 return repositoryImpl;
366 }
367
368
376 @Override
377 public Repository findByPrimaryKey(Serializable primaryKey)
378 throws NoSuchModelException, SystemException {
379 return findByPrimaryKey(((Long)primaryKey).longValue());
380 }
381
382
390 public Repository findByPrimaryKey(long repositoryId)
391 throws NoSuchRepositoryException, SystemException {
392 Repository repository = fetchByPrimaryKey(repositoryId);
393
394 if (repository == null) {
395 if (_log.isWarnEnabled()) {
396 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + repositoryId);
397 }
398
399 throw new NoSuchRepositoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
400 repositoryId);
401 }
402
403 return repository;
404 }
405
406
413 @Override
414 public Repository fetchByPrimaryKey(Serializable primaryKey)
415 throws SystemException {
416 return fetchByPrimaryKey(((Long)primaryKey).longValue());
417 }
418
419
426 public Repository fetchByPrimaryKey(long repositoryId)
427 throws SystemException {
428 Repository repository = (Repository)EntityCacheUtil.getResult(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
429 RepositoryImpl.class, repositoryId);
430
431 if (repository == _nullRepository) {
432 return null;
433 }
434
435 if (repository == null) {
436 Session session = null;
437
438 boolean hasException = false;
439
440 try {
441 session = openSession();
442
443 repository = (Repository)session.get(RepositoryImpl.class,
444 Long.valueOf(repositoryId));
445 }
446 catch (Exception e) {
447 hasException = true;
448
449 throw processException(e);
450 }
451 finally {
452 if (repository != null) {
453 cacheResult(repository);
454 }
455 else if (!hasException) {
456 EntityCacheUtil.putResult(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
457 RepositoryImpl.class, repositoryId, _nullRepository);
458 }
459
460 closeSession(session);
461 }
462 }
463
464 return repository;
465 }
466
467
474 public List<Repository> findByGroupId(long groupId)
475 throws SystemException {
476 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
477 }
478
479
492 public List<Repository> findByGroupId(long groupId, int start, int end)
493 throws SystemException {
494 return findByGroupId(groupId, start, end, null);
495 }
496
497
511 public List<Repository> findByGroupId(long groupId, int start, int end,
512 OrderByComparator orderByComparator) throws SystemException {
513 FinderPath finderPath = null;
514 Object[] finderArgs = null;
515
516 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
517 (orderByComparator == null)) {
518 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
519 finderArgs = new Object[] { groupId };
520 }
521 else {
522 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
523 finderArgs = new Object[] { groupId, start, end, orderByComparator };
524 }
525
526 List<Repository> list = (List<Repository>)FinderCacheUtil.getResult(finderPath,
527 finderArgs, this);
528
529 if (list == null) {
530 StringBundler query = null;
531
532 if (orderByComparator != null) {
533 query = new StringBundler(3 +
534 (orderByComparator.getOrderByFields().length * 3));
535 }
536 else {
537 query = new StringBundler(2);
538 }
539
540 query.append(_SQL_SELECT_REPOSITORY_WHERE);
541
542 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
543
544 if (orderByComparator != null) {
545 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
546 orderByComparator);
547 }
548
549 String sql = query.toString();
550
551 Session session = null;
552
553 try {
554 session = openSession();
555
556 Query q = session.createQuery(sql);
557
558 QueryPos qPos = QueryPos.getInstance(q);
559
560 qPos.add(groupId);
561
562 list = (List<Repository>)QueryUtil.list(q, getDialect(), start,
563 end);
564 }
565 catch (Exception e) {
566 throw processException(e);
567 }
568 finally {
569 if (list == null) {
570 FinderCacheUtil.removeResult(finderPath, finderArgs);
571 }
572 else {
573 cacheResult(list);
574
575 FinderCacheUtil.putResult(finderPath, finderArgs, list);
576 }
577
578 closeSession(session);
579 }
580 }
581
582 return list;
583 }
584
585
598 public Repository findByGroupId_First(long groupId,
599 OrderByComparator orderByComparator)
600 throws NoSuchRepositoryException, SystemException {
601 List<Repository> list = findByGroupId(groupId, 0, 1, orderByComparator);
602
603 if (list.isEmpty()) {
604 StringBundler msg = new StringBundler(4);
605
606 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
607
608 msg.append("groupId=");
609 msg.append(groupId);
610
611 msg.append(StringPool.CLOSE_CURLY_BRACE);
612
613 throw new NoSuchRepositoryException(msg.toString());
614 }
615 else {
616 return list.get(0);
617 }
618 }
619
620
633 public Repository findByGroupId_Last(long groupId,
634 OrderByComparator orderByComparator)
635 throws NoSuchRepositoryException, SystemException {
636 int count = countByGroupId(groupId);
637
638 List<Repository> list = findByGroupId(groupId, count - 1, count,
639 orderByComparator);
640
641 if (list.isEmpty()) {
642 StringBundler msg = new StringBundler(4);
643
644 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
645
646 msg.append("groupId=");
647 msg.append(groupId);
648
649 msg.append(StringPool.CLOSE_CURLY_BRACE);
650
651 throw new NoSuchRepositoryException(msg.toString());
652 }
653 else {
654 return list.get(0);
655 }
656 }
657
658
672 public Repository[] findByGroupId_PrevAndNext(long repositoryId,
673 long groupId, OrderByComparator orderByComparator)
674 throws NoSuchRepositoryException, SystemException {
675 Repository repository = findByPrimaryKey(repositoryId);
676
677 Session session = null;
678
679 try {
680 session = openSession();
681
682 Repository[] array = new RepositoryImpl[3];
683
684 array[0] = getByGroupId_PrevAndNext(session, repository, groupId,
685 orderByComparator, true);
686
687 array[1] = repository;
688
689 array[2] = getByGroupId_PrevAndNext(session, repository, groupId,
690 orderByComparator, false);
691
692 return array;
693 }
694 catch (Exception e) {
695 throw processException(e);
696 }
697 finally {
698 closeSession(session);
699 }
700 }
701
702 protected Repository getByGroupId_PrevAndNext(Session session,
703 Repository repository, long groupId,
704 OrderByComparator orderByComparator, boolean previous) {
705 StringBundler query = null;
706
707 if (orderByComparator != null) {
708 query = new StringBundler(6 +
709 (orderByComparator.getOrderByFields().length * 6));
710 }
711 else {
712 query = new StringBundler(3);
713 }
714
715 query.append(_SQL_SELECT_REPOSITORY_WHERE);
716
717 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
718
719 if (orderByComparator != null) {
720 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
721
722 if (orderByConditionFields.length > 0) {
723 query.append(WHERE_AND);
724 }
725
726 for (int i = 0; i < orderByConditionFields.length; i++) {
727 query.append(_ORDER_BY_ENTITY_ALIAS);
728 query.append(orderByConditionFields[i]);
729
730 if ((i + 1) < orderByConditionFields.length) {
731 if (orderByComparator.isAscending() ^ previous) {
732 query.append(WHERE_GREATER_THAN_HAS_NEXT);
733 }
734 else {
735 query.append(WHERE_LESSER_THAN_HAS_NEXT);
736 }
737 }
738 else {
739 if (orderByComparator.isAscending() ^ previous) {
740 query.append(WHERE_GREATER_THAN);
741 }
742 else {
743 query.append(WHERE_LESSER_THAN);
744 }
745 }
746 }
747
748 query.append(ORDER_BY_CLAUSE);
749
750 String[] orderByFields = orderByComparator.getOrderByFields();
751
752 for (int i = 0; i < orderByFields.length; i++) {
753 query.append(_ORDER_BY_ENTITY_ALIAS);
754 query.append(orderByFields[i]);
755
756 if ((i + 1) < orderByFields.length) {
757 if (orderByComparator.isAscending() ^ previous) {
758 query.append(ORDER_BY_ASC_HAS_NEXT);
759 }
760 else {
761 query.append(ORDER_BY_DESC_HAS_NEXT);
762 }
763 }
764 else {
765 if (orderByComparator.isAscending() ^ previous) {
766 query.append(ORDER_BY_ASC);
767 }
768 else {
769 query.append(ORDER_BY_DESC);
770 }
771 }
772 }
773 }
774
775 String sql = query.toString();
776
777 Query q = session.createQuery(sql);
778
779 q.setFirstResult(0);
780 q.setMaxResults(2);
781
782 QueryPos qPos = QueryPos.getInstance(q);
783
784 qPos.add(groupId);
785
786 if (orderByComparator != null) {
787 Object[] values = orderByComparator.getOrderByConditionValues(repository);
788
789 for (Object value : values) {
790 qPos.add(value);
791 }
792 }
793
794 List<Repository> list = q.list();
795
796 if (list.size() == 2) {
797 return list.get(1);
798 }
799 else {
800 return null;
801 }
802 }
803
804
810 public List<Repository> findAll() throws SystemException {
811 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
812 }
813
814
826 public List<Repository> findAll(int start, int end)
827 throws SystemException {
828 return findAll(start, end, null);
829 }
830
831
844 public List<Repository> findAll(int start, int end,
845 OrderByComparator orderByComparator) throws SystemException {
846 FinderPath finderPath = null;
847 Object[] finderArgs = new Object[] { start, end, orderByComparator };
848
849 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
850 (orderByComparator == null)) {
851 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
852 finderArgs = FINDER_ARGS_EMPTY;
853 }
854 else {
855 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
856 finderArgs = new Object[] { start, end, orderByComparator };
857 }
858
859 List<Repository> list = (List<Repository>)FinderCacheUtil.getResult(finderPath,
860 finderArgs, this);
861
862 if (list == null) {
863 StringBundler query = null;
864 String sql = null;
865
866 if (orderByComparator != null) {
867 query = new StringBundler(2 +
868 (orderByComparator.getOrderByFields().length * 3));
869
870 query.append(_SQL_SELECT_REPOSITORY);
871
872 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
873 orderByComparator);
874
875 sql = query.toString();
876 }
877 else {
878 sql = _SQL_SELECT_REPOSITORY;
879 }
880
881 Session session = null;
882
883 try {
884 session = openSession();
885
886 Query q = session.createQuery(sql);
887
888 if (orderByComparator == null) {
889 list = (List<Repository>)QueryUtil.list(q, getDialect(),
890 start, end, false);
891
892 Collections.sort(list);
893 }
894 else {
895 list = (List<Repository>)QueryUtil.list(q, getDialect(),
896 start, end);
897 }
898 }
899 catch (Exception e) {
900 throw processException(e);
901 }
902 finally {
903 if (list == null) {
904 FinderCacheUtil.removeResult(finderPath, finderArgs);
905 }
906 else {
907 cacheResult(list);
908
909 FinderCacheUtil.putResult(finderPath, finderArgs, list);
910 }
911
912 closeSession(session);
913 }
914 }
915
916 return list;
917 }
918
919
925 public void removeByGroupId(long groupId) throws SystemException {
926 for (Repository repository : findByGroupId(groupId)) {
927 repositoryPersistence.remove(repository);
928 }
929 }
930
931
936 public void removeAll() throws SystemException {
937 for (Repository repository : findAll()) {
938 repositoryPersistence.remove(repository);
939 }
940 }
941
942
949 public int countByGroupId(long groupId) throws SystemException {
950 Object[] finderArgs = new Object[] { groupId };
951
952 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
953 finderArgs, this);
954
955 if (count == null) {
956 StringBundler query = new StringBundler(2);
957
958 query.append(_SQL_COUNT_REPOSITORY_WHERE);
959
960 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
961
962 String sql = query.toString();
963
964 Session session = null;
965
966 try {
967 session = openSession();
968
969 Query q = session.createQuery(sql);
970
971 QueryPos qPos = QueryPos.getInstance(q);
972
973 qPos.add(groupId);
974
975 count = (Long)q.uniqueResult();
976 }
977 catch (Exception e) {
978 throw processException(e);
979 }
980 finally {
981 if (count == null) {
982 count = Long.valueOf(0);
983 }
984
985 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
986 finderArgs, count);
987
988 closeSession(session);
989 }
990 }
991
992 return count.intValue();
993 }
994
995
1001 public int countAll() throws SystemException {
1002 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1003 FINDER_ARGS_EMPTY, this);
1004
1005 if (count == null) {
1006 Session session = null;
1007
1008 try {
1009 session = openSession();
1010
1011 Query q = session.createQuery(_SQL_COUNT_REPOSITORY);
1012
1013 count = (Long)q.uniqueResult();
1014 }
1015 catch (Exception e) {
1016 throw processException(e);
1017 }
1018 finally {
1019 if (count == null) {
1020 count = Long.valueOf(0);
1021 }
1022
1023 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1024 FINDER_ARGS_EMPTY, count);
1025
1026 closeSession(session);
1027 }
1028 }
1029
1030 return count.intValue();
1031 }
1032
1033
1036 public void afterPropertiesSet() {
1037 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1038 com.liferay.portal.util.PropsUtil.get(
1039 "value.object.listener.com.liferay.portal.model.Repository")));
1040
1041 if (listenerClassNames.length > 0) {
1042 try {
1043 List<ModelListener<Repository>> listenersList = new ArrayList<ModelListener<Repository>>();
1044
1045 for (String listenerClassName : listenerClassNames) {
1046 listenersList.add((ModelListener<Repository>)InstanceFactory.newInstance(
1047 listenerClassName));
1048 }
1049
1050 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1051 }
1052 catch (Exception e) {
1053 _log.error(e);
1054 }
1055 }
1056 }
1057
1058 public void destroy() {
1059 EntityCacheUtil.removeCache(RepositoryImpl.class.getName());
1060 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1061 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1062 }
1063
1064 @BeanReference(type = AccountPersistence.class)
1065 protected AccountPersistence accountPersistence;
1066 @BeanReference(type = AddressPersistence.class)
1067 protected AddressPersistence addressPersistence;
1068 @BeanReference(type = BrowserTrackerPersistence.class)
1069 protected BrowserTrackerPersistence browserTrackerPersistence;
1070 @BeanReference(type = ClassNamePersistence.class)
1071 protected ClassNamePersistence classNamePersistence;
1072 @BeanReference(type = ClusterGroupPersistence.class)
1073 protected ClusterGroupPersistence clusterGroupPersistence;
1074 @BeanReference(type = CompanyPersistence.class)
1075 protected CompanyPersistence companyPersistence;
1076 @BeanReference(type = ContactPersistence.class)
1077 protected ContactPersistence contactPersistence;
1078 @BeanReference(type = CountryPersistence.class)
1079 protected CountryPersistence countryPersistence;
1080 @BeanReference(type = EmailAddressPersistence.class)
1081 protected EmailAddressPersistence emailAddressPersistence;
1082 @BeanReference(type = GroupPersistence.class)
1083 protected GroupPersistence groupPersistence;
1084 @BeanReference(type = ImagePersistence.class)
1085 protected ImagePersistence imagePersistence;
1086 @BeanReference(type = LayoutPersistence.class)
1087 protected LayoutPersistence layoutPersistence;
1088 @BeanReference(type = LayoutBranchPersistence.class)
1089 protected LayoutBranchPersistence layoutBranchPersistence;
1090 @BeanReference(type = LayoutPrototypePersistence.class)
1091 protected LayoutPrototypePersistence layoutPrototypePersistence;
1092 @BeanReference(type = LayoutRevisionPersistence.class)
1093 protected LayoutRevisionPersistence layoutRevisionPersistence;
1094 @BeanReference(type = LayoutSetPersistence.class)
1095 protected LayoutSetPersistence layoutSetPersistence;
1096 @BeanReference(type = LayoutSetBranchPersistence.class)
1097 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1098 @BeanReference(type = LayoutSetPrototypePersistence.class)
1099 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1100 @BeanReference(type = ListTypePersistence.class)
1101 protected ListTypePersistence listTypePersistence;
1102 @BeanReference(type = LockPersistence.class)
1103 protected LockPersistence lockPersistence;
1104 @BeanReference(type = MembershipRequestPersistence.class)
1105 protected MembershipRequestPersistence membershipRequestPersistence;
1106 @BeanReference(type = OrganizationPersistence.class)
1107 protected OrganizationPersistence organizationPersistence;
1108 @BeanReference(type = OrgGroupPermissionPersistence.class)
1109 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1110 @BeanReference(type = OrgGroupRolePersistence.class)
1111 protected OrgGroupRolePersistence orgGroupRolePersistence;
1112 @BeanReference(type = OrgLaborPersistence.class)
1113 protected OrgLaborPersistence orgLaborPersistence;
1114 @BeanReference(type = PasswordPolicyPersistence.class)
1115 protected PasswordPolicyPersistence passwordPolicyPersistence;
1116 @BeanReference(type = PasswordPolicyRelPersistence.class)
1117 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1118 @BeanReference(type = PasswordTrackerPersistence.class)
1119 protected PasswordTrackerPersistence passwordTrackerPersistence;
1120 @BeanReference(type = PermissionPersistence.class)
1121 protected PermissionPersistence permissionPersistence;
1122 @BeanReference(type = PhonePersistence.class)
1123 protected PhonePersistence phonePersistence;
1124 @BeanReference(type = PluginSettingPersistence.class)
1125 protected PluginSettingPersistence pluginSettingPersistence;
1126 @BeanReference(type = PortalPreferencesPersistence.class)
1127 protected PortalPreferencesPersistence portalPreferencesPersistence;
1128 @BeanReference(type = PortletPersistence.class)
1129 protected PortletPersistence portletPersistence;
1130 @BeanReference(type = PortletItemPersistence.class)
1131 protected PortletItemPersistence portletItemPersistence;
1132 @BeanReference(type = PortletPreferencesPersistence.class)
1133 protected PortletPreferencesPersistence portletPreferencesPersistence;
1134 @BeanReference(type = RegionPersistence.class)
1135 protected RegionPersistence regionPersistence;
1136 @BeanReference(type = ReleasePersistence.class)
1137 protected ReleasePersistence releasePersistence;
1138 @BeanReference(type = RepositoryPersistence.class)
1139 protected RepositoryPersistence repositoryPersistence;
1140 @BeanReference(type = RepositoryEntryPersistence.class)
1141 protected RepositoryEntryPersistence repositoryEntryPersistence;
1142 @BeanReference(type = ResourcePersistence.class)
1143 protected ResourcePersistence resourcePersistence;
1144 @BeanReference(type = ResourceActionPersistence.class)
1145 protected ResourceActionPersistence resourceActionPersistence;
1146 @BeanReference(type = ResourceBlockPersistence.class)
1147 protected ResourceBlockPersistence resourceBlockPersistence;
1148 @BeanReference(type = ResourceBlockPermissionPersistence.class)
1149 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1150 @BeanReference(type = ResourceCodePersistence.class)
1151 protected ResourceCodePersistence resourceCodePersistence;
1152 @BeanReference(type = ResourcePermissionPersistence.class)
1153 protected ResourcePermissionPersistence resourcePermissionPersistence;
1154 @BeanReference(type = ResourceTypePermissionPersistence.class)
1155 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1156 @BeanReference(type = RolePersistence.class)
1157 protected RolePersistence rolePersistence;
1158 @BeanReference(type = ServiceComponentPersistence.class)
1159 protected ServiceComponentPersistence serviceComponentPersistence;
1160 @BeanReference(type = ShardPersistence.class)
1161 protected ShardPersistence shardPersistence;
1162 @BeanReference(type = SubscriptionPersistence.class)
1163 protected SubscriptionPersistence subscriptionPersistence;
1164 @BeanReference(type = TeamPersistence.class)
1165 protected TeamPersistence teamPersistence;
1166 @BeanReference(type = TicketPersistence.class)
1167 protected TicketPersistence ticketPersistence;
1168 @BeanReference(type = UserPersistence.class)
1169 protected UserPersistence userPersistence;
1170 @BeanReference(type = UserGroupPersistence.class)
1171 protected UserGroupPersistence userGroupPersistence;
1172 @BeanReference(type = UserGroupGroupRolePersistence.class)
1173 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1174 @BeanReference(type = UserGroupRolePersistence.class)
1175 protected UserGroupRolePersistence userGroupRolePersistence;
1176 @BeanReference(type = UserIdMapperPersistence.class)
1177 protected UserIdMapperPersistence userIdMapperPersistence;
1178 @BeanReference(type = UserNotificationEventPersistence.class)
1179 protected UserNotificationEventPersistence userNotificationEventPersistence;
1180 @BeanReference(type = UserTrackerPersistence.class)
1181 protected UserTrackerPersistence userTrackerPersistence;
1182 @BeanReference(type = UserTrackerPathPersistence.class)
1183 protected UserTrackerPathPersistence userTrackerPathPersistence;
1184 @BeanReference(type = VirtualHostPersistence.class)
1185 protected VirtualHostPersistence virtualHostPersistence;
1186 @BeanReference(type = WebDAVPropsPersistence.class)
1187 protected WebDAVPropsPersistence webDAVPropsPersistence;
1188 @BeanReference(type = WebsitePersistence.class)
1189 protected WebsitePersistence websitePersistence;
1190 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1191 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1192 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1193 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1194 @BeanReference(type = AssetEntryPersistence.class)
1195 protected AssetEntryPersistence assetEntryPersistence;
1196 @BeanReference(type = DLFileEntryPersistence.class)
1197 protected DLFileEntryPersistence dlFileEntryPersistence;
1198 @BeanReference(type = DLFileVersionPersistence.class)
1199 protected DLFileVersionPersistence dlFileVersionPersistence;
1200 @BeanReference(type = DLFolderPersistence.class)
1201 protected DLFolderPersistence dlFolderPersistence;
1202 @BeanReference(type = ExpandoValuePersistence.class)
1203 protected ExpandoValuePersistence expandoValuePersistence;
1204 private static final String _SQL_SELECT_REPOSITORY = "SELECT repository FROM Repository repository";
1205 private static final String _SQL_SELECT_REPOSITORY_WHERE = "SELECT repository FROM Repository repository WHERE ";
1206 private static final String _SQL_COUNT_REPOSITORY = "SELECT COUNT(repository) FROM Repository repository";
1207 private static final String _SQL_COUNT_REPOSITORY_WHERE = "SELECT COUNT(repository) FROM Repository repository WHERE ";
1208 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "repository.groupId = ?";
1209 private static final String _ORDER_BY_ENTITY_ALIAS = "repository.";
1210 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Repository exists with the primary key ";
1211 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Repository exists with the key {";
1212 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1213 private static Log _log = LogFactoryUtil.getLog(RepositoryPersistenceImpl.class);
1214 private static Repository _nullRepository = new RepositoryImpl() {
1215 @Override
1216 public Object clone() {
1217 return this;
1218 }
1219
1220 @Override
1221 public CacheModel<Repository> toCacheModel() {
1222 return _nullRepositoryCacheModel;
1223 }
1224 };
1225
1226 private static CacheModel<Repository> _nullRepositoryCacheModel = new CacheModel<Repository>() {
1227 public Repository toEntityModel() {
1228 return _nullRepository;
1229 }
1230 };
1231 }