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.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.Repository;
042 import com.liferay.portal.model.impl.RepositoryImpl;
043 import com.liferay.portal.model.impl.RepositoryModelImpl;
044 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045
046 import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
047 import com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistence;
048 import com.liferay.portlet.documentlibrary.service.persistence.DLFileVersionPersistence;
049 import com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence;
050 import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
051
052 import java.io.Serializable;
053
054 import java.util.ArrayList;
055 import java.util.Collections;
056 import java.util.List;
057
058
070 public class RepositoryPersistenceImpl extends BasePersistenceImpl<Repository>
071 implements RepositoryPersistence {
072
077 public static final String FINDER_CLASS_NAME_ENTITY = RepositoryImpl.class.getName();
078 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List1";
080 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081 ".List2";
082 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
083 RepositoryModelImpl.FINDER_CACHE_ENABLED, RepositoryImpl.class,
084 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
085 new String[] {
086 String.class.getName(),
087
088 "java.lang.Integer", "java.lang.Integer",
089 "com.liferay.portal.kernel.util.OrderByComparator"
090 });
091 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
092 RepositoryModelImpl.FINDER_CACHE_ENABLED, RepositoryImpl.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
094 new String[] { String.class.getName() },
095 RepositoryModelImpl.UUID_COLUMN_BITMASK);
096 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
097 RepositoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
099 new String[] { String.class.getName() });
100 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
101 RepositoryModelImpl.FINDER_CACHE_ENABLED, RepositoryImpl.class,
102 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
103 new String[] { String.class.getName(), Long.class.getName() },
104 RepositoryModelImpl.UUID_COLUMN_BITMASK |
105 RepositoryModelImpl.GROUPID_COLUMN_BITMASK);
106 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
107 RepositoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
108 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
109 new String[] { String.class.getName(), Long.class.getName() });
110 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
111 RepositoryModelImpl.FINDER_CACHE_ENABLED, RepositoryImpl.class,
112 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
113 new String[] {
114 String.class.getName(), Long.class.getName(),
115
116 "java.lang.Integer", "java.lang.Integer",
117 "com.liferay.portal.kernel.util.OrderByComparator"
118 });
119 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
120 new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
121 RepositoryModelImpl.FINDER_CACHE_ENABLED, RepositoryImpl.class,
122 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
123 new String[] { String.class.getName(), Long.class.getName() },
124 RepositoryModelImpl.UUID_COLUMN_BITMASK |
125 RepositoryModelImpl.COMPANYID_COLUMN_BITMASK);
126 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
127 RepositoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
128 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
129 new String[] { String.class.getName(), Long.class.getName() });
130 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
131 RepositoryModelImpl.FINDER_CACHE_ENABLED, RepositoryImpl.class,
132 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
133 new String[] {
134 Long.class.getName(),
135
136 "java.lang.Integer", "java.lang.Integer",
137 "com.liferay.portal.kernel.util.OrderByComparator"
138 });
139 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
140 new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
141 RepositoryModelImpl.FINDER_CACHE_ENABLED, RepositoryImpl.class,
142 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
143 new String[] { Long.class.getName() },
144 RepositoryModelImpl.GROUPID_COLUMN_BITMASK);
145 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
146 RepositoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
147 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
148 new String[] { Long.class.getName() });
149 public static final FinderPath FINDER_PATH_FETCH_BY_G_N_P = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
150 RepositoryModelImpl.FINDER_CACHE_ENABLED, RepositoryImpl.class,
151 FINDER_CLASS_NAME_ENTITY, "fetchByG_N_P",
152 new String[] {
153 Long.class.getName(), String.class.getName(),
154 String.class.getName()
155 },
156 RepositoryModelImpl.GROUPID_COLUMN_BITMASK |
157 RepositoryModelImpl.NAME_COLUMN_BITMASK |
158 RepositoryModelImpl.PORTLETID_COLUMN_BITMASK);
159 public static final FinderPath FINDER_PATH_COUNT_BY_G_N_P = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
160 RepositoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
161 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_P",
162 new String[] {
163 Long.class.getName(), String.class.getName(),
164 String.class.getName()
165 });
166 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
167 RepositoryModelImpl.FINDER_CACHE_ENABLED, RepositoryImpl.class,
168 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
169 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
170 RepositoryModelImpl.FINDER_CACHE_ENABLED, RepositoryImpl.class,
171 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
172 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
173 RepositoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
174 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
175
176
181 public void cacheResult(Repository repository) {
182 EntityCacheUtil.putResult(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
183 RepositoryImpl.class, repository.getPrimaryKey(), repository);
184
185 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
186 new Object[] {
187 repository.getUuid(), Long.valueOf(repository.getGroupId())
188 }, repository);
189
190 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P,
191 new Object[] {
192 Long.valueOf(repository.getGroupId()),
193
194 repository.getName(),
195
196 repository.getPortletId()
197 }, repository);
198
199 repository.resetOriginalValues();
200 }
201
202
207 public void cacheResult(List<Repository> repositories) {
208 for (Repository repository : repositories) {
209 if (EntityCacheUtil.getResult(
210 RepositoryModelImpl.ENTITY_CACHE_ENABLED,
211 RepositoryImpl.class, repository.getPrimaryKey()) == null) {
212 cacheResult(repository);
213 }
214 else {
215 repository.resetOriginalValues();
216 }
217 }
218 }
219
220
227 @Override
228 public void clearCache() {
229 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
230 CacheRegistryUtil.clear(RepositoryImpl.class.getName());
231 }
232
233 EntityCacheUtil.clearCache(RepositoryImpl.class.getName());
234
235 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
236 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
237 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
238 }
239
240
247 @Override
248 public void clearCache(Repository repository) {
249 EntityCacheUtil.removeResult(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
250 RepositoryImpl.class, repository.getPrimaryKey());
251
252 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
253 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
254
255 clearUniqueFindersCache(repository);
256 }
257
258 @Override
259 public void clearCache(List<Repository> repositories) {
260 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
261 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
262
263 for (Repository repository : repositories) {
264 EntityCacheUtil.removeResult(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
265 RepositoryImpl.class, repository.getPrimaryKey());
266
267 clearUniqueFindersCache(repository);
268 }
269 }
270
271 protected void clearUniqueFindersCache(Repository repository) {
272 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
273 new Object[] {
274 repository.getUuid(), Long.valueOf(repository.getGroupId())
275 });
276
277 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P,
278 new Object[] {
279 Long.valueOf(repository.getGroupId()),
280
281 repository.getName(),
282
283 repository.getPortletId()
284 });
285 }
286
287
293 public Repository create(long repositoryId) {
294 Repository repository = new RepositoryImpl();
295
296 repository.setNew(true);
297 repository.setPrimaryKey(repositoryId);
298
299 String uuid = PortalUUIDUtil.generate();
300
301 repository.setUuid(uuid);
302
303 return repository;
304 }
305
306
314 public Repository remove(long repositoryId)
315 throws NoSuchRepositoryException, SystemException {
316 return remove(Long.valueOf(repositoryId));
317 }
318
319
327 @Override
328 public Repository remove(Serializable primaryKey)
329 throws NoSuchRepositoryException, SystemException {
330 Session session = null;
331
332 try {
333 session = openSession();
334
335 Repository repository = (Repository)session.get(RepositoryImpl.class,
336 primaryKey);
337
338 if (repository == null) {
339 if (_log.isWarnEnabled()) {
340 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
341 }
342
343 throw new NoSuchRepositoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
344 primaryKey);
345 }
346
347 return remove(repository);
348 }
349 catch (NoSuchRepositoryException nsee) {
350 throw nsee;
351 }
352 catch (Exception e) {
353 throw processException(e);
354 }
355 finally {
356 closeSession(session);
357 }
358 }
359
360 @Override
361 protected Repository removeImpl(Repository repository)
362 throws SystemException {
363 repository = toUnwrappedModel(repository);
364
365 Session session = null;
366
367 try {
368 session = openSession();
369
370 if (repository.isCachedModel()) {
371 repository = (Repository)session.get(RepositoryImpl.class,
372 repository.getPrimaryKeyObj());
373 }
374
375 session.delete(repository);
376 }
377 catch (Exception e) {
378 throw processException(e);
379 }
380 finally {
381 closeSession(session);
382 }
383
384 clearCache(repository);
385
386 return repository;
387 }
388
389 @Override
390 public Repository updateImpl(com.liferay.portal.model.Repository repository)
391 throws SystemException {
392 repository = toUnwrappedModel(repository);
393
394 boolean isNew = repository.isNew();
395
396 RepositoryModelImpl repositoryModelImpl = (RepositoryModelImpl)repository;
397
398 if (Validator.isNull(repository.getUuid())) {
399 String uuid = PortalUUIDUtil.generate();
400
401 repository.setUuid(uuid);
402 }
403
404 Session session = null;
405
406 try {
407 session = openSession();
408
409 if (repository.isNew()) {
410 session.save(repository);
411
412 repository.setNew(false);
413 }
414 else {
415 session.merge(repository);
416 }
417 }
418 catch (Exception e) {
419 throw processException(e);
420 }
421 finally {
422 closeSession(session);
423 }
424
425 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
426
427 if (isNew || !RepositoryModelImpl.COLUMN_BITMASK_ENABLED) {
428 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
429 }
430
431 else {
432 if ((repositoryModelImpl.getColumnBitmask() &
433 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
434 Object[] args = new Object[] {
435 repositoryModelImpl.getOriginalUuid()
436 };
437
438 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
439 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
440 args);
441
442 args = new Object[] { repositoryModelImpl.getUuid() };
443
444 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
445 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
446 args);
447 }
448
449 if ((repositoryModelImpl.getColumnBitmask() &
450 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
451 Object[] args = new Object[] {
452 repositoryModelImpl.getOriginalUuid(),
453 Long.valueOf(repositoryModelImpl.getOriginalCompanyId())
454 };
455
456 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
457 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
458 args);
459
460 args = new Object[] {
461 repositoryModelImpl.getUuid(),
462 Long.valueOf(repositoryModelImpl.getCompanyId())
463 };
464
465 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
466 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
467 args);
468 }
469
470 if ((repositoryModelImpl.getColumnBitmask() &
471 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
472 Object[] args = new Object[] {
473 Long.valueOf(repositoryModelImpl.getOriginalGroupId())
474 };
475
476 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
477 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
478 args);
479
480 args = new Object[] {
481 Long.valueOf(repositoryModelImpl.getGroupId())
482 };
483
484 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
485 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
486 args);
487 }
488 }
489
490 EntityCacheUtil.putResult(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
491 RepositoryImpl.class, repository.getPrimaryKey(), repository);
492
493 if (isNew) {
494 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
495 new Object[] {
496 repository.getUuid(), Long.valueOf(repository.getGroupId())
497 }, repository);
498
499 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P,
500 new Object[] {
501 Long.valueOf(repository.getGroupId()),
502
503 repository.getName(),
504
505 repository.getPortletId()
506 }, repository);
507 }
508 else {
509 if ((repositoryModelImpl.getColumnBitmask() &
510 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
511 Object[] args = new Object[] {
512 repositoryModelImpl.getOriginalUuid(),
513 Long.valueOf(repositoryModelImpl.getOriginalGroupId())
514 };
515
516 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
517
518 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
519
520 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
521 new Object[] {
522 repository.getUuid(),
523 Long.valueOf(repository.getGroupId())
524 }, repository);
525 }
526
527 if ((repositoryModelImpl.getColumnBitmask() &
528 FINDER_PATH_FETCH_BY_G_N_P.getColumnBitmask()) != 0) {
529 Object[] args = new Object[] {
530 Long.valueOf(repositoryModelImpl.getOriginalGroupId()),
531
532 repositoryModelImpl.getOriginalName(),
533
534 repositoryModelImpl.getOriginalPortletId()
535 };
536
537 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_P, args);
538
539 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P, args);
540
541 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P,
542 new Object[] {
543 Long.valueOf(repository.getGroupId()),
544
545 repository.getName(),
546
547 repository.getPortletId()
548 }, repository);
549 }
550 }
551
552 return repository;
553 }
554
555 protected Repository toUnwrappedModel(Repository repository) {
556 if (repository instanceof RepositoryImpl) {
557 return repository;
558 }
559
560 RepositoryImpl repositoryImpl = new RepositoryImpl();
561
562 repositoryImpl.setNew(repository.isNew());
563 repositoryImpl.setPrimaryKey(repository.getPrimaryKey());
564
565 repositoryImpl.setUuid(repository.getUuid());
566 repositoryImpl.setRepositoryId(repository.getRepositoryId());
567 repositoryImpl.setGroupId(repository.getGroupId());
568 repositoryImpl.setCompanyId(repository.getCompanyId());
569 repositoryImpl.setUserId(repository.getUserId());
570 repositoryImpl.setUserName(repository.getUserName());
571 repositoryImpl.setCreateDate(repository.getCreateDate());
572 repositoryImpl.setModifiedDate(repository.getModifiedDate());
573 repositoryImpl.setClassNameId(repository.getClassNameId());
574 repositoryImpl.setName(repository.getName());
575 repositoryImpl.setDescription(repository.getDescription());
576 repositoryImpl.setPortletId(repository.getPortletId());
577 repositoryImpl.setTypeSettings(repository.getTypeSettings());
578 repositoryImpl.setDlFolderId(repository.getDlFolderId());
579
580 return repositoryImpl;
581 }
582
583
591 @Override
592 public Repository findByPrimaryKey(Serializable primaryKey)
593 throws NoSuchModelException, SystemException {
594 return findByPrimaryKey(((Long)primaryKey).longValue());
595 }
596
597
605 public Repository findByPrimaryKey(long repositoryId)
606 throws NoSuchRepositoryException, SystemException {
607 Repository repository = fetchByPrimaryKey(repositoryId);
608
609 if (repository == null) {
610 if (_log.isWarnEnabled()) {
611 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + repositoryId);
612 }
613
614 throw new NoSuchRepositoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
615 repositoryId);
616 }
617
618 return repository;
619 }
620
621
628 @Override
629 public Repository fetchByPrimaryKey(Serializable primaryKey)
630 throws SystemException {
631 return fetchByPrimaryKey(((Long)primaryKey).longValue());
632 }
633
634
641 public Repository fetchByPrimaryKey(long repositoryId)
642 throws SystemException {
643 Repository repository = (Repository)EntityCacheUtil.getResult(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
644 RepositoryImpl.class, repositoryId);
645
646 if (repository == _nullRepository) {
647 return null;
648 }
649
650 if (repository == null) {
651 Session session = null;
652
653 boolean hasException = false;
654
655 try {
656 session = openSession();
657
658 repository = (Repository)session.get(RepositoryImpl.class,
659 Long.valueOf(repositoryId));
660 }
661 catch (Exception e) {
662 hasException = true;
663
664 throw processException(e);
665 }
666 finally {
667 if (repository != null) {
668 cacheResult(repository);
669 }
670 else if (!hasException) {
671 EntityCacheUtil.putResult(RepositoryModelImpl.ENTITY_CACHE_ENABLED,
672 RepositoryImpl.class, repositoryId, _nullRepository);
673 }
674
675 closeSession(session);
676 }
677 }
678
679 return repository;
680 }
681
682
689 public List<Repository> findByUuid(String uuid) throws SystemException {
690 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
691 }
692
693
706 public List<Repository> findByUuid(String uuid, int start, int end)
707 throws SystemException {
708 return findByUuid(uuid, start, end, null);
709 }
710
711
725 public List<Repository> findByUuid(String uuid, int start, int end,
726 OrderByComparator orderByComparator) throws SystemException {
727 FinderPath finderPath = null;
728 Object[] finderArgs = null;
729
730 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
731 (orderByComparator == null)) {
732 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
733 finderArgs = new Object[] { uuid };
734 }
735 else {
736 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
737 finderArgs = new Object[] { uuid, start, end, orderByComparator };
738 }
739
740 List<Repository> list = (List<Repository>)FinderCacheUtil.getResult(finderPath,
741 finderArgs, this);
742
743 if ((list != null) && !list.isEmpty()) {
744 for (Repository repository : list) {
745 if (!Validator.equals(uuid, repository.getUuid())) {
746 list = null;
747
748 break;
749 }
750 }
751 }
752
753 if (list == null) {
754 StringBundler query = null;
755
756 if (orderByComparator != null) {
757 query = new StringBundler(3 +
758 (orderByComparator.getOrderByFields().length * 3));
759 }
760 else {
761 query = new StringBundler(2);
762 }
763
764 query.append(_SQL_SELECT_REPOSITORY_WHERE);
765
766 if (uuid == null) {
767 query.append(_FINDER_COLUMN_UUID_UUID_1);
768 }
769 else {
770 if (uuid.equals(StringPool.BLANK)) {
771 query.append(_FINDER_COLUMN_UUID_UUID_3);
772 }
773 else {
774 query.append(_FINDER_COLUMN_UUID_UUID_2);
775 }
776 }
777
778 if (orderByComparator != null) {
779 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
780 orderByComparator);
781 }
782
783 String sql = query.toString();
784
785 Session session = null;
786
787 try {
788 session = openSession();
789
790 Query q = session.createQuery(sql);
791
792 QueryPos qPos = QueryPos.getInstance(q);
793
794 if (uuid != null) {
795 qPos.add(uuid);
796 }
797
798 list = (List<Repository>)QueryUtil.list(q, getDialect(), start,
799 end);
800 }
801 catch (Exception e) {
802 throw processException(e);
803 }
804 finally {
805 if (list == null) {
806 FinderCacheUtil.removeResult(finderPath, finderArgs);
807 }
808 else {
809 cacheResult(list);
810
811 FinderCacheUtil.putResult(finderPath, finderArgs, list);
812 }
813
814 closeSession(session);
815 }
816 }
817
818 return list;
819 }
820
821
830 public Repository findByUuid_First(String uuid,
831 OrderByComparator orderByComparator)
832 throws NoSuchRepositoryException, SystemException {
833 Repository repository = fetchByUuid_First(uuid, orderByComparator);
834
835 if (repository != null) {
836 return repository;
837 }
838
839 StringBundler msg = new StringBundler(4);
840
841 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
842
843 msg.append("uuid=");
844 msg.append(uuid);
845
846 msg.append(StringPool.CLOSE_CURLY_BRACE);
847
848 throw new NoSuchRepositoryException(msg.toString());
849 }
850
851
859 public Repository fetchByUuid_First(String uuid,
860 OrderByComparator orderByComparator) throws SystemException {
861 List<Repository> list = findByUuid(uuid, 0, 1, orderByComparator);
862
863 if (!list.isEmpty()) {
864 return list.get(0);
865 }
866
867 return null;
868 }
869
870
879 public Repository findByUuid_Last(String uuid,
880 OrderByComparator orderByComparator)
881 throws NoSuchRepositoryException, SystemException {
882 Repository repository = fetchByUuid_Last(uuid, orderByComparator);
883
884 if (repository != null) {
885 return repository;
886 }
887
888 StringBundler msg = new StringBundler(4);
889
890 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
891
892 msg.append("uuid=");
893 msg.append(uuid);
894
895 msg.append(StringPool.CLOSE_CURLY_BRACE);
896
897 throw new NoSuchRepositoryException(msg.toString());
898 }
899
900
908 public Repository fetchByUuid_Last(String uuid,
909 OrderByComparator orderByComparator) throws SystemException {
910 int count = countByUuid(uuid);
911
912 List<Repository> list = findByUuid(uuid, count - 1, count,
913 orderByComparator);
914
915 if (!list.isEmpty()) {
916 return list.get(0);
917 }
918
919 return null;
920 }
921
922
932 public Repository[] findByUuid_PrevAndNext(long repositoryId, String uuid,
933 OrderByComparator orderByComparator)
934 throws NoSuchRepositoryException, SystemException {
935 Repository repository = findByPrimaryKey(repositoryId);
936
937 Session session = null;
938
939 try {
940 session = openSession();
941
942 Repository[] array = new RepositoryImpl[3];
943
944 array[0] = getByUuid_PrevAndNext(session, repository, uuid,
945 orderByComparator, true);
946
947 array[1] = repository;
948
949 array[2] = getByUuid_PrevAndNext(session, repository, uuid,
950 orderByComparator, false);
951
952 return array;
953 }
954 catch (Exception e) {
955 throw processException(e);
956 }
957 finally {
958 closeSession(session);
959 }
960 }
961
962 protected Repository getByUuid_PrevAndNext(Session session,
963 Repository repository, String uuid,
964 OrderByComparator orderByComparator, boolean previous) {
965 StringBundler query = null;
966
967 if (orderByComparator != null) {
968 query = new StringBundler(6 +
969 (orderByComparator.getOrderByFields().length * 6));
970 }
971 else {
972 query = new StringBundler(3);
973 }
974
975 query.append(_SQL_SELECT_REPOSITORY_WHERE);
976
977 if (uuid == null) {
978 query.append(_FINDER_COLUMN_UUID_UUID_1);
979 }
980 else {
981 if (uuid.equals(StringPool.BLANK)) {
982 query.append(_FINDER_COLUMN_UUID_UUID_3);
983 }
984 else {
985 query.append(_FINDER_COLUMN_UUID_UUID_2);
986 }
987 }
988
989 if (orderByComparator != null) {
990 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
991
992 if (orderByConditionFields.length > 0) {
993 query.append(WHERE_AND);
994 }
995
996 for (int i = 0; i < orderByConditionFields.length; i++) {
997 query.append(_ORDER_BY_ENTITY_ALIAS);
998 query.append(orderByConditionFields[i]);
999
1000 if ((i + 1) < orderByConditionFields.length) {
1001 if (orderByComparator.isAscending() ^ previous) {
1002 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1003 }
1004 else {
1005 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1006 }
1007 }
1008 else {
1009 if (orderByComparator.isAscending() ^ previous) {
1010 query.append(WHERE_GREATER_THAN);
1011 }
1012 else {
1013 query.append(WHERE_LESSER_THAN);
1014 }
1015 }
1016 }
1017
1018 query.append(ORDER_BY_CLAUSE);
1019
1020 String[] orderByFields = orderByComparator.getOrderByFields();
1021
1022 for (int i = 0; i < orderByFields.length; i++) {
1023 query.append(_ORDER_BY_ENTITY_ALIAS);
1024 query.append(orderByFields[i]);
1025
1026 if ((i + 1) < orderByFields.length) {
1027 if (orderByComparator.isAscending() ^ previous) {
1028 query.append(ORDER_BY_ASC_HAS_NEXT);
1029 }
1030 else {
1031 query.append(ORDER_BY_DESC_HAS_NEXT);
1032 }
1033 }
1034 else {
1035 if (orderByComparator.isAscending() ^ previous) {
1036 query.append(ORDER_BY_ASC);
1037 }
1038 else {
1039 query.append(ORDER_BY_DESC);
1040 }
1041 }
1042 }
1043 }
1044
1045 String sql = query.toString();
1046
1047 Query q = session.createQuery(sql);
1048
1049 q.setFirstResult(0);
1050 q.setMaxResults(2);
1051
1052 QueryPos qPos = QueryPos.getInstance(q);
1053
1054 if (uuid != null) {
1055 qPos.add(uuid);
1056 }
1057
1058 if (orderByComparator != null) {
1059 Object[] values = orderByComparator.getOrderByConditionValues(repository);
1060
1061 for (Object value : values) {
1062 qPos.add(value);
1063 }
1064 }
1065
1066 List<Repository> list = q.list();
1067
1068 if (list.size() == 2) {
1069 return list.get(1);
1070 }
1071 else {
1072 return null;
1073 }
1074 }
1075
1076
1085 public Repository findByUUID_G(String uuid, long groupId)
1086 throws NoSuchRepositoryException, SystemException {
1087 Repository repository = fetchByUUID_G(uuid, groupId);
1088
1089 if (repository == null) {
1090 StringBundler msg = new StringBundler(6);
1091
1092 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1093
1094 msg.append("uuid=");
1095 msg.append(uuid);
1096
1097 msg.append(", groupId=");
1098 msg.append(groupId);
1099
1100 msg.append(StringPool.CLOSE_CURLY_BRACE);
1101
1102 if (_log.isWarnEnabled()) {
1103 _log.warn(msg.toString());
1104 }
1105
1106 throw new NoSuchRepositoryException(msg.toString());
1107 }
1108
1109 return repository;
1110 }
1111
1112
1120 public Repository fetchByUUID_G(String uuid, long groupId)
1121 throws SystemException {
1122 return fetchByUUID_G(uuid, groupId, true);
1123 }
1124
1125
1134 public Repository fetchByUUID_G(String uuid, long groupId,
1135 boolean retrieveFromCache) throws SystemException {
1136 Object[] finderArgs = new Object[] { uuid, groupId };
1137
1138 Object result = null;
1139
1140 if (retrieveFromCache) {
1141 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1142 finderArgs, this);
1143 }
1144
1145 if (result instanceof Repository) {
1146 Repository repository = (Repository)result;
1147
1148 if (!Validator.equals(uuid, repository.getUuid()) ||
1149 (groupId != repository.getGroupId())) {
1150 result = null;
1151 }
1152 }
1153
1154 if (result == null) {
1155 StringBundler query = new StringBundler(3);
1156
1157 query.append(_SQL_SELECT_REPOSITORY_WHERE);
1158
1159 if (uuid == null) {
1160 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1161 }
1162 else {
1163 if (uuid.equals(StringPool.BLANK)) {
1164 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1165 }
1166 else {
1167 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1168 }
1169 }
1170
1171 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1172
1173 String sql = query.toString();
1174
1175 Session session = null;
1176
1177 try {
1178 session = openSession();
1179
1180 Query q = session.createQuery(sql);
1181
1182 QueryPos qPos = QueryPos.getInstance(q);
1183
1184 if (uuid != null) {
1185 qPos.add(uuid);
1186 }
1187
1188 qPos.add(groupId);
1189
1190 List<Repository> list = q.list();
1191
1192 result = list;
1193
1194 Repository repository = null;
1195
1196 if (list.isEmpty()) {
1197 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1198 finderArgs, list);
1199 }
1200 else {
1201 repository = list.get(0);
1202
1203 cacheResult(repository);
1204
1205 if ((repository.getUuid() == null) ||
1206 !repository.getUuid().equals(uuid) ||
1207 (repository.getGroupId() != groupId)) {
1208 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1209 finderArgs, repository);
1210 }
1211 }
1212
1213 return repository;
1214 }
1215 catch (Exception e) {
1216 throw processException(e);
1217 }
1218 finally {
1219 if (result == null) {
1220 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1221 finderArgs);
1222 }
1223
1224 closeSession(session);
1225 }
1226 }
1227 else {
1228 if (result instanceof List<?>) {
1229 return null;
1230 }
1231 else {
1232 return (Repository)result;
1233 }
1234 }
1235 }
1236
1237
1245 public List<Repository> findByUuid_C(String uuid, long companyId)
1246 throws SystemException {
1247 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1248 QueryUtil.ALL_POS, null);
1249 }
1250
1251
1265 public List<Repository> findByUuid_C(String uuid, long companyId,
1266 int start, int end) throws SystemException {
1267 return findByUuid_C(uuid, companyId, start, end, null);
1268 }
1269
1270
1285 public List<Repository> findByUuid_C(String uuid, long companyId,
1286 int start, int end, OrderByComparator orderByComparator)
1287 throws SystemException {
1288 FinderPath finderPath = null;
1289 Object[] finderArgs = null;
1290
1291 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1292 (orderByComparator == null)) {
1293 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1294 finderArgs = new Object[] { uuid, companyId };
1295 }
1296 else {
1297 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1298 finderArgs = new Object[] {
1299 uuid, companyId,
1300
1301 start, end, orderByComparator
1302 };
1303 }
1304
1305 List<Repository> list = (List<Repository>)FinderCacheUtil.getResult(finderPath,
1306 finderArgs, this);
1307
1308 if ((list != null) && !list.isEmpty()) {
1309 for (Repository repository : list) {
1310 if (!Validator.equals(uuid, repository.getUuid()) ||
1311 (companyId != repository.getCompanyId())) {
1312 list = null;
1313
1314 break;
1315 }
1316 }
1317 }
1318
1319 if (list == null) {
1320 StringBundler query = null;
1321
1322 if (orderByComparator != null) {
1323 query = new StringBundler(4 +
1324 (orderByComparator.getOrderByFields().length * 3));
1325 }
1326 else {
1327 query = new StringBundler(3);
1328 }
1329
1330 query.append(_SQL_SELECT_REPOSITORY_WHERE);
1331
1332 if (uuid == null) {
1333 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1334 }
1335 else {
1336 if (uuid.equals(StringPool.BLANK)) {
1337 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1338 }
1339 else {
1340 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1341 }
1342 }
1343
1344 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1345
1346 if (orderByComparator != null) {
1347 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1348 orderByComparator);
1349 }
1350
1351 String sql = query.toString();
1352
1353 Session session = null;
1354
1355 try {
1356 session = openSession();
1357
1358 Query q = session.createQuery(sql);
1359
1360 QueryPos qPos = QueryPos.getInstance(q);
1361
1362 if (uuid != null) {
1363 qPos.add(uuid);
1364 }
1365
1366 qPos.add(companyId);
1367
1368 list = (List<Repository>)QueryUtil.list(q, getDialect(), start,
1369 end);
1370 }
1371 catch (Exception e) {
1372 throw processException(e);
1373 }
1374 finally {
1375 if (list == null) {
1376 FinderCacheUtil.removeResult(finderPath, finderArgs);
1377 }
1378 else {
1379 cacheResult(list);
1380
1381 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1382 }
1383
1384 closeSession(session);
1385 }
1386 }
1387
1388 return list;
1389 }
1390
1391
1401 public Repository findByUuid_C_First(String uuid, long companyId,
1402 OrderByComparator orderByComparator)
1403 throws NoSuchRepositoryException, SystemException {
1404 Repository repository = fetchByUuid_C_First(uuid, companyId,
1405 orderByComparator);
1406
1407 if (repository != null) {
1408 return repository;
1409 }
1410
1411 StringBundler msg = new StringBundler(6);
1412
1413 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1414
1415 msg.append("uuid=");
1416 msg.append(uuid);
1417
1418 msg.append(", companyId=");
1419 msg.append(companyId);
1420
1421 msg.append(StringPool.CLOSE_CURLY_BRACE);
1422
1423 throw new NoSuchRepositoryException(msg.toString());
1424 }
1425
1426
1435 public Repository fetchByUuid_C_First(String uuid, long companyId,
1436 OrderByComparator orderByComparator) throws SystemException {
1437 List<Repository> list = findByUuid_C(uuid, companyId, 0, 1,
1438 orderByComparator);
1439
1440 if (!list.isEmpty()) {
1441 return list.get(0);
1442 }
1443
1444 return null;
1445 }
1446
1447
1457 public Repository findByUuid_C_Last(String uuid, long companyId,
1458 OrderByComparator orderByComparator)
1459 throws NoSuchRepositoryException, SystemException {
1460 Repository repository = fetchByUuid_C_Last(uuid, companyId,
1461 orderByComparator);
1462
1463 if (repository != null) {
1464 return repository;
1465 }
1466
1467 StringBundler msg = new StringBundler(6);
1468
1469 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1470
1471 msg.append("uuid=");
1472 msg.append(uuid);
1473
1474 msg.append(", companyId=");
1475 msg.append(companyId);
1476
1477 msg.append(StringPool.CLOSE_CURLY_BRACE);
1478
1479 throw new NoSuchRepositoryException(msg.toString());
1480 }
1481
1482
1491 public Repository fetchByUuid_C_Last(String uuid, long companyId,
1492 OrderByComparator orderByComparator) throws SystemException {
1493 int count = countByUuid_C(uuid, companyId);
1494
1495 List<Repository> list = findByUuid_C(uuid, companyId, count - 1, count,
1496 orderByComparator);
1497
1498 if (!list.isEmpty()) {
1499 return list.get(0);
1500 }
1501
1502 return null;
1503 }
1504
1505
1516 public Repository[] findByUuid_C_PrevAndNext(long repositoryId,
1517 String uuid, long companyId, OrderByComparator orderByComparator)
1518 throws NoSuchRepositoryException, SystemException {
1519 Repository repository = findByPrimaryKey(repositoryId);
1520
1521 Session session = null;
1522
1523 try {
1524 session = openSession();
1525
1526 Repository[] array = new RepositoryImpl[3];
1527
1528 array[0] = getByUuid_C_PrevAndNext(session, repository, uuid,
1529 companyId, orderByComparator, true);
1530
1531 array[1] = repository;
1532
1533 array[2] = getByUuid_C_PrevAndNext(session, repository, uuid,
1534 companyId, orderByComparator, false);
1535
1536 return array;
1537 }
1538 catch (Exception e) {
1539 throw processException(e);
1540 }
1541 finally {
1542 closeSession(session);
1543 }
1544 }
1545
1546 protected Repository getByUuid_C_PrevAndNext(Session session,
1547 Repository repository, String uuid, long companyId,
1548 OrderByComparator orderByComparator, boolean previous) {
1549 StringBundler query = null;
1550
1551 if (orderByComparator != null) {
1552 query = new StringBundler(6 +
1553 (orderByComparator.getOrderByFields().length * 6));
1554 }
1555 else {
1556 query = new StringBundler(3);
1557 }
1558
1559 query.append(_SQL_SELECT_REPOSITORY_WHERE);
1560
1561 if (uuid == null) {
1562 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1563 }
1564 else {
1565 if (uuid.equals(StringPool.BLANK)) {
1566 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1567 }
1568 else {
1569 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1570 }
1571 }
1572
1573 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1574
1575 if (orderByComparator != null) {
1576 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1577
1578 if (orderByConditionFields.length > 0) {
1579 query.append(WHERE_AND);
1580 }
1581
1582 for (int i = 0; i < orderByConditionFields.length; i++) {
1583 query.append(_ORDER_BY_ENTITY_ALIAS);
1584 query.append(orderByConditionFields[i]);
1585
1586 if ((i + 1) < orderByConditionFields.length) {
1587 if (orderByComparator.isAscending() ^ previous) {
1588 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1589 }
1590 else {
1591 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1592 }
1593 }
1594 else {
1595 if (orderByComparator.isAscending() ^ previous) {
1596 query.append(WHERE_GREATER_THAN);
1597 }
1598 else {
1599 query.append(WHERE_LESSER_THAN);
1600 }
1601 }
1602 }
1603
1604 query.append(ORDER_BY_CLAUSE);
1605
1606 String[] orderByFields = orderByComparator.getOrderByFields();
1607
1608 for (int i = 0; i < orderByFields.length; i++) {
1609 query.append(_ORDER_BY_ENTITY_ALIAS);
1610 query.append(orderByFields[i]);
1611
1612 if ((i + 1) < orderByFields.length) {
1613 if (orderByComparator.isAscending() ^ previous) {
1614 query.append(ORDER_BY_ASC_HAS_NEXT);
1615 }
1616 else {
1617 query.append(ORDER_BY_DESC_HAS_NEXT);
1618 }
1619 }
1620 else {
1621 if (orderByComparator.isAscending() ^ previous) {
1622 query.append(ORDER_BY_ASC);
1623 }
1624 else {
1625 query.append(ORDER_BY_DESC);
1626 }
1627 }
1628 }
1629 }
1630
1631 String sql = query.toString();
1632
1633 Query q = session.createQuery(sql);
1634
1635 q.setFirstResult(0);
1636 q.setMaxResults(2);
1637
1638 QueryPos qPos = QueryPos.getInstance(q);
1639
1640 if (uuid != null) {
1641 qPos.add(uuid);
1642 }
1643
1644 qPos.add(companyId);
1645
1646 if (orderByComparator != null) {
1647 Object[] values = orderByComparator.getOrderByConditionValues(repository);
1648
1649 for (Object value : values) {
1650 qPos.add(value);
1651 }
1652 }
1653
1654 List<Repository> list = q.list();
1655
1656 if (list.size() == 2) {
1657 return list.get(1);
1658 }
1659 else {
1660 return null;
1661 }
1662 }
1663
1664
1671 public List<Repository> findByGroupId(long groupId)
1672 throws SystemException {
1673 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1674 }
1675
1676
1689 public List<Repository> findByGroupId(long groupId, int start, int end)
1690 throws SystemException {
1691 return findByGroupId(groupId, start, end, null);
1692 }
1693
1694
1708 public List<Repository> findByGroupId(long groupId, int start, int end,
1709 OrderByComparator orderByComparator) throws SystemException {
1710 FinderPath finderPath = null;
1711 Object[] finderArgs = null;
1712
1713 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1714 (orderByComparator == null)) {
1715 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1716 finderArgs = new Object[] { groupId };
1717 }
1718 else {
1719 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1720 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1721 }
1722
1723 List<Repository> list = (List<Repository>)FinderCacheUtil.getResult(finderPath,
1724 finderArgs, this);
1725
1726 if ((list != null) && !list.isEmpty()) {
1727 for (Repository repository : list) {
1728 if ((groupId != repository.getGroupId())) {
1729 list = null;
1730
1731 break;
1732 }
1733 }
1734 }
1735
1736 if (list == null) {
1737 StringBundler query = null;
1738
1739 if (orderByComparator != null) {
1740 query = new StringBundler(3 +
1741 (orderByComparator.getOrderByFields().length * 3));
1742 }
1743 else {
1744 query = new StringBundler(2);
1745 }
1746
1747 query.append(_SQL_SELECT_REPOSITORY_WHERE);
1748
1749 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1750
1751 if (orderByComparator != null) {
1752 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1753 orderByComparator);
1754 }
1755
1756 String sql = query.toString();
1757
1758 Session session = null;
1759
1760 try {
1761 session = openSession();
1762
1763 Query q = session.createQuery(sql);
1764
1765 QueryPos qPos = QueryPos.getInstance(q);
1766
1767 qPos.add(groupId);
1768
1769 list = (List<Repository>)QueryUtil.list(q, getDialect(), start,
1770 end);
1771 }
1772 catch (Exception e) {
1773 throw processException(e);
1774 }
1775 finally {
1776 if (list == null) {
1777 FinderCacheUtil.removeResult(finderPath, finderArgs);
1778 }
1779 else {
1780 cacheResult(list);
1781
1782 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1783 }
1784
1785 closeSession(session);
1786 }
1787 }
1788
1789 return list;
1790 }
1791
1792
1801 public Repository findByGroupId_First(long groupId,
1802 OrderByComparator orderByComparator)
1803 throws NoSuchRepositoryException, SystemException {
1804 Repository repository = fetchByGroupId_First(groupId, orderByComparator);
1805
1806 if (repository != null) {
1807 return repository;
1808 }
1809
1810 StringBundler msg = new StringBundler(4);
1811
1812 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1813
1814 msg.append("groupId=");
1815 msg.append(groupId);
1816
1817 msg.append(StringPool.CLOSE_CURLY_BRACE);
1818
1819 throw new NoSuchRepositoryException(msg.toString());
1820 }
1821
1822
1830 public Repository fetchByGroupId_First(long groupId,
1831 OrderByComparator orderByComparator) throws SystemException {
1832 List<Repository> list = findByGroupId(groupId, 0, 1, orderByComparator);
1833
1834 if (!list.isEmpty()) {
1835 return list.get(0);
1836 }
1837
1838 return null;
1839 }
1840
1841
1850 public Repository findByGroupId_Last(long groupId,
1851 OrderByComparator orderByComparator)
1852 throws NoSuchRepositoryException, SystemException {
1853 Repository repository = fetchByGroupId_Last(groupId, orderByComparator);
1854
1855 if (repository != null) {
1856 return repository;
1857 }
1858
1859 StringBundler msg = new StringBundler(4);
1860
1861 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1862
1863 msg.append("groupId=");
1864 msg.append(groupId);
1865
1866 msg.append(StringPool.CLOSE_CURLY_BRACE);
1867
1868 throw new NoSuchRepositoryException(msg.toString());
1869 }
1870
1871
1879 public Repository fetchByGroupId_Last(long groupId,
1880 OrderByComparator orderByComparator) throws SystemException {
1881 int count = countByGroupId(groupId);
1882
1883 List<Repository> list = findByGroupId(groupId, count - 1, count,
1884 orderByComparator);
1885
1886 if (!list.isEmpty()) {
1887 return list.get(0);
1888 }
1889
1890 return null;
1891 }
1892
1893
1903 public Repository[] findByGroupId_PrevAndNext(long repositoryId,
1904 long groupId, OrderByComparator orderByComparator)
1905 throws NoSuchRepositoryException, SystemException {
1906 Repository repository = findByPrimaryKey(repositoryId);
1907
1908 Session session = null;
1909
1910 try {
1911 session = openSession();
1912
1913 Repository[] array = new RepositoryImpl[3];
1914
1915 array[0] = getByGroupId_PrevAndNext(session, repository, groupId,
1916 orderByComparator, true);
1917
1918 array[1] = repository;
1919
1920 array[2] = getByGroupId_PrevAndNext(session, repository, groupId,
1921 orderByComparator, false);
1922
1923 return array;
1924 }
1925 catch (Exception e) {
1926 throw processException(e);
1927 }
1928 finally {
1929 closeSession(session);
1930 }
1931 }
1932
1933 protected Repository getByGroupId_PrevAndNext(Session session,
1934 Repository repository, long groupId,
1935 OrderByComparator orderByComparator, boolean previous) {
1936 StringBundler query = null;
1937
1938 if (orderByComparator != null) {
1939 query = new StringBundler(6 +
1940 (orderByComparator.getOrderByFields().length * 6));
1941 }
1942 else {
1943 query = new StringBundler(3);
1944 }
1945
1946 query.append(_SQL_SELECT_REPOSITORY_WHERE);
1947
1948 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1949
1950 if (orderByComparator != null) {
1951 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1952
1953 if (orderByConditionFields.length > 0) {
1954 query.append(WHERE_AND);
1955 }
1956
1957 for (int i = 0; i < orderByConditionFields.length; i++) {
1958 query.append(_ORDER_BY_ENTITY_ALIAS);
1959 query.append(orderByConditionFields[i]);
1960
1961 if ((i + 1) < orderByConditionFields.length) {
1962 if (orderByComparator.isAscending() ^ previous) {
1963 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1964 }
1965 else {
1966 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1967 }
1968 }
1969 else {
1970 if (orderByComparator.isAscending() ^ previous) {
1971 query.append(WHERE_GREATER_THAN);
1972 }
1973 else {
1974 query.append(WHERE_LESSER_THAN);
1975 }
1976 }
1977 }
1978
1979 query.append(ORDER_BY_CLAUSE);
1980
1981 String[] orderByFields = orderByComparator.getOrderByFields();
1982
1983 for (int i = 0; i < orderByFields.length; i++) {
1984 query.append(_ORDER_BY_ENTITY_ALIAS);
1985 query.append(orderByFields[i]);
1986
1987 if ((i + 1) < orderByFields.length) {
1988 if (orderByComparator.isAscending() ^ previous) {
1989 query.append(ORDER_BY_ASC_HAS_NEXT);
1990 }
1991 else {
1992 query.append(ORDER_BY_DESC_HAS_NEXT);
1993 }
1994 }
1995 else {
1996 if (orderByComparator.isAscending() ^ previous) {
1997 query.append(ORDER_BY_ASC);
1998 }
1999 else {
2000 query.append(ORDER_BY_DESC);
2001 }
2002 }
2003 }
2004 }
2005
2006 String sql = query.toString();
2007
2008 Query q = session.createQuery(sql);
2009
2010 q.setFirstResult(0);
2011 q.setMaxResults(2);
2012
2013 QueryPos qPos = QueryPos.getInstance(q);
2014
2015 qPos.add(groupId);
2016
2017 if (orderByComparator != null) {
2018 Object[] values = orderByComparator.getOrderByConditionValues(repository);
2019
2020 for (Object value : values) {
2021 qPos.add(value);
2022 }
2023 }
2024
2025 List<Repository> list = q.list();
2026
2027 if (list.size() == 2) {
2028 return list.get(1);
2029 }
2030 else {
2031 return null;
2032 }
2033 }
2034
2035
2045 public Repository findByG_N_P(long groupId, String name, String portletId)
2046 throws NoSuchRepositoryException, SystemException {
2047 Repository repository = fetchByG_N_P(groupId, name, portletId);
2048
2049 if (repository == null) {
2050 StringBundler msg = new StringBundler(8);
2051
2052 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2053
2054 msg.append("groupId=");
2055 msg.append(groupId);
2056
2057 msg.append(", name=");
2058 msg.append(name);
2059
2060 msg.append(", portletId=");
2061 msg.append(portletId);
2062
2063 msg.append(StringPool.CLOSE_CURLY_BRACE);
2064
2065 if (_log.isWarnEnabled()) {
2066 _log.warn(msg.toString());
2067 }
2068
2069 throw new NoSuchRepositoryException(msg.toString());
2070 }
2071
2072 return repository;
2073 }
2074
2075
2084 public Repository fetchByG_N_P(long groupId, String name, String portletId)
2085 throws SystemException {
2086 return fetchByG_N_P(groupId, name, portletId, true);
2087 }
2088
2089
2099 public Repository fetchByG_N_P(long groupId, String name, String portletId,
2100 boolean retrieveFromCache) throws SystemException {
2101 Object[] finderArgs = new Object[] { groupId, name, portletId };
2102
2103 Object result = null;
2104
2105 if (retrieveFromCache) {
2106 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N_P,
2107 finderArgs, this);
2108 }
2109
2110 if (result instanceof Repository) {
2111 Repository repository = (Repository)result;
2112
2113 if ((groupId != repository.getGroupId()) ||
2114 !Validator.equals(name, repository.getName()) ||
2115 !Validator.equals(portletId, repository.getPortletId())) {
2116 result = null;
2117 }
2118 }
2119
2120 if (result == null) {
2121 StringBundler query = new StringBundler(4);
2122
2123 query.append(_SQL_SELECT_REPOSITORY_WHERE);
2124
2125 query.append(_FINDER_COLUMN_G_N_P_GROUPID_2);
2126
2127 if (name == null) {
2128 query.append(_FINDER_COLUMN_G_N_P_NAME_1);
2129 }
2130 else {
2131 if (name.equals(StringPool.BLANK)) {
2132 query.append(_FINDER_COLUMN_G_N_P_NAME_3);
2133 }
2134 else {
2135 query.append(_FINDER_COLUMN_G_N_P_NAME_2);
2136 }
2137 }
2138
2139 if (portletId == null) {
2140 query.append(_FINDER_COLUMN_G_N_P_PORTLETID_1);
2141 }
2142 else {
2143 if (portletId.equals(StringPool.BLANK)) {
2144 query.append(_FINDER_COLUMN_G_N_P_PORTLETID_3);
2145 }
2146 else {
2147 query.append(_FINDER_COLUMN_G_N_P_PORTLETID_2);
2148 }
2149 }
2150
2151 String sql = query.toString();
2152
2153 Session session = null;
2154
2155 try {
2156 session = openSession();
2157
2158 Query q = session.createQuery(sql);
2159
2160 QueryPos qPos = QueryPos.getInstance(q);
2161
2162 qPos.add(groupId);
2163
2164 if (name != null) {
2165 qPos.add(name);
2166 }
2167
2168 if (portletId != null) {
2169 qPos.add(portletId);
2170 }
2171
2172 List<Repository> list = q.list();
2173
2174 result = list;
2175
2176 Repository repository = null;
2177
2178 if (list.isEmpty()) {
2179 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P,
2180 finderArgs, list);
2181 }
2182 else {
2183 repository = list.get(0);
2184
2185 cacheResult(repository);
2186
2187 if ((repository.getGroupId() != groupId) ||
2188 (repository.getName() == null) ||
2189 !repository.getName().equals(name) ||
2190 (repository.getPortletId() == null) ||
2191 !repository.getPortletId().equals(portletId)) {
2192 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P,
2193 finderArgs, repository);
2194 }
2195 }
2196
2197 return repository;
2198 }
2199 catch (Exception e) {
2200 throw processException(e);
2201 }
2202 finally {
2203 if (result == null) {
2204 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P,
2205 finderArgs);
2206 }
2207
2208 closeSession(session);
2209 }
2210 }
2211 else {
2212 if (result instanceof List<?>) {
2213 return null;
2214 }
2215 else {
2216 return (Repository)result;
2217 }
2218 }
2219 }
2220
2221
2227 public List<Repository> findAll() throws SystemException {
2228 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2229 }
2230
2231
2243 public List<Repository> findAll(int start, int end)
2244 throws SystemException {
2245 return findAll(start, end, null);
2246 }
2247
2248
2261 public List<Repository> findAll(int start, int end,
2262 OrderByComparator orderByComparator) throws SystemException {
2263 FinderPath finderPath = null;
2264 Object[] finderArgs = new Object[] { start, end, orderByComparator };
2265
2266 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2267 (orderByComparator == null)) {
2268 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2269 finderArgs = FINDER_ARGS_EMPTY;
2270 }
2271 else {
2272 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2273 finderArgs = new Object[] { start, end, orderByComparator };
2274 }
2275
2276 List<Repository> list = (List<Repository>)FinderCacheUtil.getResult(finderPath,
2277 finderArgs, this);
2278
2279 if (list == null) {
2280 StringBundler query = null;
2281 String sql = null;
2282
2283 if (orderByComparator != null) {
2284 query = new StringBundler(2 +
2285 (orderByComparator.getOrderByFields().length * 3));
2286
2287 query.append(_SQL_SELECT_REPOSITORY);
2288
2289 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2290 orderByComparator);
2291
2292 sql = query.toString();
2293 }
2294 else {
2295 sql = _SQL_SELECT_REPOSITORY;
2296 }
2297
2298 Session session = null;
2299
2300 try {
2301 session = openSession();
2302
2303 Query q = session.createQuery(sql);
2304
2305 if (orderByComparator == null) {
2306 list = (List<Repository>)QueryUtil.list(q, getDialect(),
2307 start, end, false);
2308
2309 Collections.sort(list);
2310 }
2311 else {
2312 list = (List<Repository>)QueryUtil.list(q, getDialect(),
2313 start, end);
2314 }
2315 }
2316 catch (Exception e) {
2317 throw processException(e);
2318 }
2319 finally {
2320 if (list == null) {
2321 FinderCacheUtil.removeResult(finderPath, finderArgs);
2322 }
2323 else {
2324 cacheResult(list);
2325
2326 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2327 }
2328
2329 closeSession(session);
2330 }
2331 }
2332
2333 return list;
2334 }
2335
2336
2342 public void removeByUuid(String uuid) throws SystemException {
2343 for (Repository repository : findByUuid(uuid)) {
2344 remove(repository);
2345 }
2346 }
2347
2348
2356 public Repository removeByUUID_G(String uuid, long groupId)
2357 throws NoSuchRepositoryException, SystemException {
2358 Repository repository = findByUUID_G(uuid, groupId);
2359
2360 return remove(repository);
2361 }
2362
2363
2370 public void removeByUuid_C(String uuid, long companyId)
2371 throws SystemException {
2372 for (Repository repository : findByUuid_C(uuid, companyId)) {
2373 remove(repository);
2374 }
2375 }
2376
2377
2383 public void removeByGroupId(long groupId) throws SystemException {
2384 for (Repository repository : findByGroupId(groupId)) {
2385 remove(repository);
2386 }
2387 }
2388
2389
2398 public Repository removeByG_N_P(long groupId, String name, String portletId)
2399 throws NoSuchRepositoryException, SystemException {
2400 Repository repository = findByG_N_P(groupId, name, portletId);
2401
2402 return remove(repository);
2403 }
2404
2405
2410 public void removeAll() throws SystemException {
2411 for (Repository repository : findAll()) {
2412 remove(repository);
2413 }
2414 }
2415
2416
2423 public int countByUuid(String uuid) throws SystemException {
2424 Object[] finderArgs = new Object[] { uuid };
2425
2426 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2427 finderArgs, this);
2428
2429 if (count == null) {
2430 StringBundler query = new StringBundler(2);
2431
2432 query.append(_SQL_COUNT_REPOSITORY_WHERE);
2433
2434 if (uuid == null) {
2435 query.append(_FINDER_COLUMN_UUID_UUID_1);
2436 }
2437 else {
2438 if (uuid.equals(StringPool.BLANK)) {
2439 query.append(_FINDER_COLUMN_UUID_UUID_3);
2440 }
2441 else {
2442 query.append(_FINDER_COLUMN_UUID_UUID_2);
2443 }
2444 }
2445
2446 String sql = query.toString();
2447
2448 Session session = null;
2449
2450 try {
2451 session = openSession();
2452
2453 Query q = session.createQuery(sql);
2454
2455 QueryPos qPos = QueryPos.getInstance(q);
2456
2457 if (uuid != null) {
2458 qPos.add(uuid);
2459 }
2460
2461 count = (Long)q.uniqueResult();
2462 }
2463 catch (Exception e) {
2464 throw processException(e);
2465 }
2466 finally {
2467 if (count == null) {
2468 count = Long.valueOf(0);
2469 }
2470
2471 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2472 finderArgs, count);
2473
2474 closeSession(session);
2475 }
2476 }
2477
2478 return count.intValue();
2479 }
2480
2481
2489 public int countByUUID_G(String uuid, long groupId)
2490 throws SystemException {
2491 Object[] finderArgs = new Object[] { uuid, groupId };
2492
2493 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2494 finderArgs, this);
2495
2496 if (count == null) {
2497 StringBundler query = new StringBundler(3);
2498
2499 query.append(_SQL_COUNT_REPOSITORY_WHERE);
2500
2501 if (uuid == null) {
2502 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2503 }
2504 else {
2505 if (uuid.equals(StringPool.BLANK)) {
2506 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2507 }
2508 else {
2509 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2510 }
2511 }
2512
2513 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2514
2515 String sql = query.toString();
2516
2517 Session session = null;
2518
2519 try {
2520 session = openSession();
2521
2522 Query q = session.createQuery(sql);
2523
2524 QueryPos qPos = QueryPos.getInstance(q);
2525
2526 if (uuid != null) {
2527 qPos.add(uuid);
2528 }
2529
2530 qPos.add(groupId);
2531
2532 count = (Long)q.uniqueResult();
2533 }
2534 catch (Exception e) {
2535 throw processException(e);
2536 }
2537 finally {
2538 if (count == null) {
2539 count = Long.valueOf(0);
2540 }
2541
2542 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2543 finderArgs, count);
2544
2545 closeSession(session);
2546 }
2547 }
2548
2549 return count.intValue();
2550 }
2551
2552
2560 public int countByUuid_C(String uuid, long companyId)
2561 throws SystemException {
2562 Object[] finderArgs = new Object[] { uuid, companyId };
2563
2564 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_C,
2565 finderArgs, this);
2566
2567 if (count == null) {
2568 StringBundler query = new StringBundler(3);
2569
2570 query.append(_SQL_COUNT_REPOSITORY_WHERE);
2571
2572 if (uuid == null) {
2573 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
2574 }
2575 else {
2576 if (uuid.equals(StringPool.BLANK)) {
2577 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
2578 }
2579 else {
2580 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
2581 }
2582 }
2583
2584 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
2585
2586 String sql = query.toString();
2587
2588 Session session = null;
2589
2590 try {
2591 session = openSession();
2592
2593 Query q = session.createQuery(sql);
2594
2595 QueryPos qPos = QueryPos.getInstance(q);
2596
2597 if (uuid != null) {
2598 qPos.add(uuid);
2599 }
2600
2601 qPos.add(companyId);
2602
2603 count = (Long)q.uniqueResult();
2604 }
2605 catch (Exception e) {
2606 throw processException(e);
2607 }
2608 finally {
2609 if (count == null) {
2610 count = Long.valueOf(0);
2611 }
2612
2613 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_C,
2614 finderArgs, count);
2615
2616 closeSession(session);
2617 }
2618 }
2619
2620 return count.intValue();
2621 }
2622
2623
2630 public int countByGroupId(long groupId) throws SystemException {
2631 Object[] finderArgs = new Object[] { groupId };
2632
2633 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2634 finderArgs, this);
2635
2636 if (count == null) {
2637 StringBundler query = new StringBundler(2);
2638
2639 query.append(_SQL_COUNT_REPOSITORY_WHERE);
2640
2641 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2642
2643 String sql = query.toString();
2644
2645 Session session = null;
2646
2647 try {
2648 session = openSession();
2649
2650 Query q = session.createQuery(sql);
2651
2652 QueryPos qPos = QueryPos.getInstance(q);
2653
2654 qPos.add(groupId);
2655
2656 count = (Long)q.uniqueResult();
2657 }
2658 catch (Exception e) {
2659 throw processException(e);
2660 }
2661 finally {
2662 if (count == null) {
2663 count = Long.valueOf(0);
2664 }
2665
2666 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2667 finderArgs, count);
2668
2669 closeSession(session);
2670 }
2671 }
2672
2673 return count.intValue();
2674 }
2675
2676
2685 public int countByG_N_P(long groupId, String name, String portletId)
2686 throws SystemException {
2687 Object[] finderArgs = new Object[] { groupId, name, portletId };
2688
2689 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N_P,
2690 finderArgs, this);
2691
2692 if (count == null) {
2693 StringBundler query = new StringBundler(4);
2694
2695 query.append(_SQL_COUNT_REPOSITORY_WHERE);
2696
2697 query.append(_FINDER_COLUMN_G_N_P_GROUPID_2);
2698
2699 if (name == null) {
2700 query.append(_FINDER_COLUMN_G_N_P_NAME_1);
2701 }
2702 else {
2703 if (name.equals(StringPool.BLANK)) {
2704 query.append(_FINDER_COLUMN_G_N_P_NAME_3);
2705 }
2706 else {
2707 query.append(_FINDER_COLUMN_G_N_P_NAME_2);
2708 }
2709 }
2710
2711 if (portletId == null) {
2712 query.append(_FINDER_COLUMN_G_N_P_PORTLETID_1);
2713 }
2714 else {
2715 if (portletId.equals(StringPool.BLANK)) {
2716 query.append(_FINDER_COLUMN_G_N_P_PORTLETID_3);
2717 }
2718 else {
2719 query.append(_FINDER_COLUMN_G_N_P_PORTLETID_2);
2720 }
2721 }
2722
2723 String sql = query.toString();
2724
2725 Session session = null;
2726
2727 try {
2728 session = openSession();
2729
2730 Query q = session.createQuery(sql);
2731
2732 QueryPos qPos = QueryPos.getInstance(q);
2733
2734 qPos.add(groupId);
2735
2736 if (name != null) {
2737 qPos.add(name);
2738 }
2739
2740 if (portletId != null) {
2741 qPos.add(portletId);
2742 }
2743
2744 count = (Long)q.uniqueResult();
2745 }
2746 catch (Exception e) {
2747 throw processException(e);
2748 }
2749 finally {
2750 if (count == null) {
2751 count = Long.valueOf(0);
2752 }
2753
2754 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N_P,
2755 finderArgs, count);
2756
2757 closeSession(session);
2758 }
2759 }
2760
2761 return count.intValue();
2762 }
2763
2764
2770 public int countAll() throws SystemException {
2771 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2772 FINDER_ARGS_EMPTY, this);
2773
2774 if (count == null) {
2775 Session session = null;
2776
2777 try {
2778 session = openSession();
2779
2780 Query q = session.createQuery(_SQL_COUNT_REPOSITORY);
2781
2782 count = (Long)q.uniqueResult();
2783 }
2784 catch (Exception e) {
2785 throw processException(e);
2786 }
2787 finally {
2788 if (count == null) {
2789 count = Long.valueOf(0);
2790 }
2791
2792 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2793 FINDER_ARGS_EMPTY, count);
2794
2795 closeSession(session);
2796 }
2797 }
2798
2799 return count.intValue();
2800 }
2801
2802
2805 public void afterPropertiesSet() {
2806 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2807 com.liferay.portal.util.PropsUtil.get(
2808 "value.object.listener.com.liferay.portal.model.Repository")));
2809
2810 if (listenerClassNames.length > 0) {
2811 try {
2812 List<ModelListener<Repository>> listenersList = new ArrayList<ModelListener<Repository>>();
2813
2814 for (String listenerClassName : listenerClassNames) {
2815 listenersList.add((ModelListener<Repository>)InstanceFactory.newInstance(
2816 listenerClassName));
2817 }
2818
2819 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2820 }
2821 catch (Exception e) {
2822 _log.error(e);
2823 }
2824 }
2825 }
2826
2827 public void destroy() {
2828 EntityCacheUtil.removeCache(RepositoryImpl.class.getName());
2829 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2830 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2831 }
2832
2833 @BeanReference(type = AccountPersistence.class)
2834 protected AccountPersistence accountPersistence;
2835 @BeanReference(type = AddressPersistence.class)
2836 protected AddressPersistence addressPersistence;
2837 @BeanReference(type = BrowserTrackerPersistence.class)
2838 protected BrowserTrackerPersistence browserTrackerPersistence;
2839 @BeanReference(type = ClassNamePersistence.class)
2840 protected ClassNamePersistence classNamePersistence;
2841 @BeanReference(type = ClusterGroupPersistence.class)
2842 protected ClusterGroupPersistence clusterGroupPersistence;
2843 @BeanReference(type = CompanyPersistence.class)
2844 protected CompanyPersistence companyPersistence;
2845 @BeanReference(type = ContactPersistence.class)
2846 protected ContactPersistence contactPersistence;
2847 @BeanReference(type = CountryPersistence.class)
2848 protected CountryPersistence countryPersistence;
2849 @BeanReference(type = EmailAddressPersistence.class)
2850 protected EmailAddressPersistence emailAddressPersistence;
2851 @BeanReference(type = GroupPersistence.class)
2852 protected GroupPersistence groupPersistence;
2853 @BeanReference(type = ImagePersistence.class)
2854 protected ImagePersistence imagePersistence;
2855 @BeanReference(type = LayoutPersistence.class)
2856 protected LayoutPersistence layoutPersistence;
2857 @BeanReference(type = LayoutBranchPersistence.class)
2858 protected LayoutBranchPersistence layoutBranchPersistence;
2859 @BeanReference(type = LayoutPrototypePersistence.class)
2860 protected LayoutPrototypePersistence layoutPrototypePersistence;
2861 @BeanReference(type = LayoutRevisionPersistence.class)
2862 protected LayoutRevisionPersistence layoutRevisionPersistence;
2863 @BeanReference(type = LayoutSetPersistence.class)
2864 protected LayoutSetPersistence layoutSetPersistence;
2865 @BeanReference(type = LayoutSetBranchPersistence.class)
2866 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2867 @BeanReference(type = LayoutSetPrototypePersistence.class)
2868 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2869 @BeanReference(type = ListTypePersistence.class)
2870 protected ListTypePersistence listTypePersistence;
2871 @BeanReference(type = LockPersistence.class)
2872 protected LockPersistence lockPersistence;
2873 @BeanReference(type = MembershipRequestPersistence.class)
2874 protected MembershipRequestPersistence membershipRequestPersistence;
2875 @BeanReference(type = OrganizationPersistence.class)
2876 protected OrganizationPersistence organizationPersistence;
2877 @BeanReference(type = OrgGroupRolePersistence.class)
2878 protected OrgGroupRolePersistence orgGroupRolePersistence;
2879 @BeanReference(type = OrgLaborPersistence.class)
2880 protected OrgLaborPersistence orgLaborPersistence;
2881 @BeanReference(type = PasswordPolicyPersistence.class)
2882 protected PasswordPolicyPersistence passwordPolicyPersistence;
2883 @BeanReference(type = PasswordPolicyRelPersistence.class)
2884 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2885 @BeanReference(type = PasswordTrackerPersistence.class)
2886 protected PasswordTrackerPersistence passwordTrackerPersistence;
2887 @BeanReference(type = PhonePersistence.class)
2888 protected PhonePersistence phonePersistence;
2889 @BeanReference(type = PluginSettingPersistence.class)
2890 protected PluginSettingPersistence pluginSettingPersistence;
2891 @BeanReference(type = PortalPreferencesPersistence.class)
2892 protected PortalPreferencesPersistence portalPreferencesPersistence;
2893 @BeanReference(type = PortletPersistence.class)
2894 protected PortletPersistence portletPersistence;
2895 @BeanReference(type = PortletItemPersistence.class)
2896 protected PortletItemPersistence portletItemPersistence;
2897 @BeanReference(type = PortletPreferencesPersistence.class)
2898 protected PortletPreferencesPersistence portletPreferencesPersistence;
2899 @BeanReference(type = RegionPersistence.class)
2900 protected RegionPersistence regionPersistence;
2901 @BeanReference(type = ReleasePersistence.class)
2902 protected ReleasePersistence releasePersistence;
2903 @BeanReference(type = RepositoryPersistence.class)
2904 protected RepositoryPersistence repositoryPersistence;
2905 @BeanReference(type = RepositoryEntryPersistence.class)
2906 protected RepositoryEntryPersistence repositoryEntryPersistence;
2907 @BeanReference(type = ResourceActionPersistence.class)
2908 protected ResourceActionPersistence resourceActionPersistence;
2909 @BeanReference(type = ResourceBlockPersistence.class)
2910 protected ResourceBlockPersistence resourceBlockPersistence;
2911 @BeanReference(type = ResourceBlockPermissionPersistence.class)
2912 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2913 @BeanReference(type = ResourcePermissionPersistence.class)
2914 protected ResourcePermissionPersistence resourcePermissionPersistence;
2915 @BeanReference(type = ResourceTypePermissionPersistence.class)
2916 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2917 @BeanReference(type = RolePersistence.class)
2918 protected RolePersistence rolePersistence;
2919 @BeanReference(type = ServiceComponentPersistence.class)
2920 protected ServiceComponentPersistence serviceComponentPersistence;
2921 @BeanReference(type = ShardPersistence.class)
2922 protected ShardPersistence shardPersistence;
2923 @BeanReference(type = SubscriptionPersistence.class)
2924 protected SubscriptionPersistence subscriptionPersistence;
2925 @BeanReference(type = TeamPersistence.class)
2926 protected TeamPersistence teamPersistence;
2927 @BeanReference(type = TicketPersistence.class)
2928 protected TicketPersistence ticketPersistence;
2929 @BeanReference(type = UserPersistence.class)
2930 protected UserPersistence userPersistence;
2931 @BeanReference(type = UserGroupPersistence.class)
2932 protected UserGroupPersistence userGroupPersistence;
2933 @BeanReference(type = UserGroupGroupRolePersistence.class)
2934 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2935 @BeanReference(type = UserGroupRolePersistence.class)
2936 protected UserGroupRolePersistence userGroupRolePersistence;
2937 @BeanReference(type = UserIdMapperPersistence.class)
2938 protected UserIdMapperPersistence userIdMapperPersistence;
2939 @BeanReference(type = UserNotificationEventPersistence.class)
2940 protected UserNotificationEventPersistence userNotificationEventPersistence;
2941 @BeanReference(type = UserTrackerPersistence.class)
2942 protected UserTrackerPersistence userTrackerPersistence;
2943 @BeanReference(type = UserTrackerPathPersistence.class)
2944 protected UserTrackerPathPersistence userTrackerPathPersistence;
2945 @BeanReference(type = VirtualHostPersistence.class)
2946 protected VirtualHostPersistence virtualHostPersistence;
2947 @BeanReference(type = WebDAVPropsPersistence.class)
2948 protected WebDAVPropsPersistence webDAVPropsPersistence;
2949 @BeanReference(type = WebsitePersistence.class)
2950 protected WebsitePersistence websitePersistence;
2951 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2952 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2953 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2954 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2955 @BeanReference(type = AssetEntryPersistence.class)
2956 protected AssetEntryPersistence assetEntryPersistence;
2957 @BeanReference(type = DLFileEntryPersistence.class)
2958 protected DLFileEntryPersistence dlFileEntryPersistence;
2959 @BeanReference(type = DLFileVersionPersistence.class)
2960 protected DLFileVersionPersistence dlFileVersionPersistence;
2961 @BeanReference(type = DLFolderPersistence.class)
2962 protected DLFolderPersistence dlFolderPersistence;
2963 @BeanReference(type = ExpandoValuePersistence.class)
2964 protected ExpandoValuePersistence expandoValuePersistence;
2965 private static final String _SQL_SELECT_REPOSITORY = "SELECT repository FROM Repository repository";
2966 private static final String _SQL_SELECT_REPOSITORY_WHERE = "SELECT repository FROM Repository repository WHERE ";
2967 private static final String _SQL_COUNT_REPOSITORY = "SELECT COUNT(repository) FROM Repository repository";
2968 private static final String _SQL_COUNT_REPOSITORY_WHERE = "SELECT COUNT(repository) FROM Repository repository WHERE ";
2969 private static final String _FINDER_COLUMN_UUID_UUID_1 = "repository.uuid IS NULL";
2970 private static final String _FINDER_COLUMN_UUID_UUID_2 = "repository.uuid = ?";
2971 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(repository.uuid IS NULL OR repository.uuid = ?)";
2972 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "repository.uuid IS NULL AND ";
2973 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "repository.uuid = ? AND ";
2974 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(repository.uuid IS NULL OR repository.uuid = ?) AND ";
2975 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "repository.groupId = ?";
2976 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "repository.uuid IS NULL AND ";
2977 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "repository.uuid = ? AND ";
2978 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(repository.uuid IS NULL OR repository.uuid = ?) AND ";
2979 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "repository.companyId = ?";
2980 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "repository.groupId = ?";
2981 private static final String _FINDER_COLUMN_G_N_P_GROUPID_2 = "repository.groupId = ? AND ";
2982 private static final String _FINDER_COLUMN_G_N_P_NAME_1 = "repository.name IS NULL AND ";
2983 private static final String _FINDER_COLUMN_G_N_P_NAME_2 = "repository.name = ? AND ";
2984 private static final String _FINDER_COLUMN_G_N_P_NAME_3 = "(repository.name IS NULL OR repository.name = ?) AND ";
2985 private static final String _FINDER_COLUMN_G_N_P_PORTLETID_1 = "repository.portletId IS NULL";
2986 private static final String _FINDER_COLUMN_G_N_P_PORTLETID_2 = "repository.portletId = ?";
2987 private static final String _FINDER_COLUMN_G_N_P_PORTLETID_3 = "(repository.portletId IS NULL OR repository.portletId = ?)";
2988 private static final String _ORDER_BY_ENTITY_ALIAS = "repository.";
2989 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Repository exists with the primary key ";
2990 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Repository exists with the key {";
2991 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2992 private static Log _log = LogFactoryUtil.getLog(RepositoryPersistenceImpl.class);
2993 private static Repository _nullRepository = new RepositoryImpl() {
2994 @Override
2995 public Object clone() {
2996 return this;
2997 }
2998
2999 @Override
3000 public CacheModel<Repository> toCacheModel() {
3001 return _nullRepositoryCacheModel;
3002 }
3003 };
3004
3005 private static CacheModel<Repository> _nullRepositoryCacheModel = new CacheModel<Repository>() {
3006 public Repository toEntityModel() {
3007 return _nullRepository;
3008 }
3009 };
3010 }