001
014
015 package com.liferay.portlet.documentlibrary.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.BatchSessionUtil;
039 import com.liferay.portal.service.persistence.LayoutPersistence;
040 import com.liferay.portal.service.persistence.ResourcePersistence;
041 import com.liferay.portal.service.persistence.UserPersistence;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import com.liferay.portlet.documentlibrary.NoSuchFileRankException;
045 import com.liferay.portlet.documentlibrary.model.DLFileRank;
046 import com.liferay.portlet.documentlibrary.model.impl.DLFileRankImpl;
047 import com.liferay.portlet.documentlibrary.model.impl.DLFileRankModelImpl;
048
049 import java.io.Serializable;
050
051 import java.util.ArrayList;
052 import java.util.Collections;
053 import java.util.List;
054
055
071 public class DLFileRankPersistenceImpl extends BasePersistenceImpl<DLFileRank>
072 implements DLFileRankPersistence {
073 public static final String FINDER_CLASS_NAME_ENTITY = DLFileRankImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
075 ".List";
076 public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
077 DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
078 "findByUserId",
079 new String[] {
080 Long.class.getName(),
081
082 "java.lang.Integer", "java.lang.Integer",
083 "com.liferay.portal.kernel.util.OrderByComparator"
084 });
085 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
086 DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
087 "countByUserId", new String[] { Long.class.getName() });
088 public static final FinderPath FINDER_PATH_FIND_BY_G_U = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
089 DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
090 "findByG_U",
091 new String[] {
092 Long.class.getName(), Long.class.getName(),
093
094 "java.lang.Integer", "java.lang.Integer",
095 "com.liferay.portal.kernel.util.OrderByComparator"
096 });
097 public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
098 DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
099 "countByG_U",
100 new String[] { Long.class.getName(), Long.class.getName() });
101 public static final FinderPath FINDER_PATH_FIND_BY_F_N = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
102 DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
103 "findByF_N",
104 new String[] {
105 Long.class.getName(), String.class.getName(),
106
107 "java.lang.Integer", "java.lang.Integer",
108 "com.liferay.portal.kernel.util.OrderByComparator"
109 });
110 public static final FinderPath FINDER_PATH_COUNT_BY_F_N = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
111 DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
112 "countByF_N",
113 new String[] { Long.class.getName(), String.class.getName() });
114 public static final FinderPath FINDER_PATH_FETCH_BY_C_U_F_N = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
115 DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
116 "fetchByC_U_F_N",
117 new String[] {
118 Long.class.getName(), Long.class.getName(), Long.class.getName(),
119 String.class.getName()
120 });
121 public static final FinderPath FINDER_PATH_COUNT_BY_C_U_F_N = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
122 DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
123 "countByC_U_F_N",
124 new String[] {
125 Long.class.getName(), Long.class.getName(), Long.class.getName(),
126 String.class.getName()
127 });
128 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
129 DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
130 "findAll", new String[0]);
131 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
132 DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
133 "countAll", new String[0]);
134
135
140 public void cacheResult(DLFileRank dlFileRank) {
141 EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
142 DLFileRankImpl.class, dlFileRank.getPrimaryKey(), dlFileRank);
143
144 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F_N,
145 new Object[] {
146 new Long(dlFileRank.getCompanyId()),
147 new Long(dlFileRank.getUserId()),
148 new Long(dlFileRank.getFolderId()),
149
150 dlFileRank.getName()
151 }, dlFileRank);
152 }
153
154
159 public void cacheResult(List<DLFileRank> dlFileRanks) {
160 for (DLFileRank dlFileRank : dlFileRanks) {
161 if (EntityCacheUtil.getResult(
162 DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
163 DLFileRankImpl.class, dlFileRank.getPrimaryKey(), this) == null) {
164 cacheResult(dlFileRank);
165 }
166 }
167 }
168
169
176 public void clearCache() {
177 CacheRegistryUtil.clear(DLFileRankImpl.class.getName());
178 EntityCacheUtil.clearCache(DLFileRankImpl.class.getName());
179 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
180 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
181 }
182
183
190 public void clearCache(DLFileRank dlFileRank) {
191 EntityCacheUtil.removeResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
192 DLFileRankImpl.class, dlFileRank.getPrimaryKey());
193
194 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F_N,
195 new Object[] {
196 new Long(dlFileRank.getCompanyId()),
197 new Long(dlFileRank.getUserId()),
198 new Long(dlFileRank.getFolderId()),
199
200 dlFileRank.getName()
201 });
202 }
203
204
210 public DLFileRank create(long fileRankId) {
211 DLFileRank dlFileRank = new DLFileRankImpl();
212
213 dlFileRank.setNew(true);
214 dlFileRank.setPrimaryKey(fileRankId);
215
216 return dlFileRank;
217 }
218
219
227 public DLFileRank remove(Serializable primaryKey)
228 throws NoSuchModelException, SystemException {
229 return remove(((Long)primaryKey).longValue());
230 }
231
232
240 public DLFileRank remove(long fileRankId)
241 throws NoSuchFileRankException, SystemException {
242 Session session = null;
243
244 try {
245 session = openSession();
246
247 DLFileRank dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
248 new Long(fileRankId));
249
250 if (dlFileRank == null) {
251 if (_log.isWarnEnabled()) {
252 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileRankId);
253 }
254
255 throw new NoSuchFileRankException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
256 fileRankId);
257 }
258
259 return remove(dlFileRank);
260 }
261 catch (NoSuchFileRankException nsee) {
262 throw nsee;
263 }
264 catch (Exception e) {
265 throw processException(e);
266 }
267 finally {
268 closeSession(session);
269 }
270 }
271
272 protected DLFileRank removeImpl(DLFileRank dlFileRank)
273 throws SystemException {
274 dlFileRank = toUnwrappedModel(dlFileRank);
275
276 Session session = null;
277
278 try {
279 session = openSession();
280
281 if (dlFileRank.isCachedModel() || BatchSessionUtil.isEnabled()) {
282 Object staleObject = session.get(DLFileRankImpl.class,
283 dlFileRank.getPrimaryKeyObj());
284
285 if (staleObject != null) {
286 session.evict(staleObject);
287 }
288 }
289
290 session.delete(dlFileRank);
291
292 session.flush();
293 }
294 catch (Exception e) {
295 throw processException(e);
296 }
297 finally {
298 closeSession(session);
299 }
300
301 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
302
303 DLFileRankModelImpl dlFileRankModelImpl = (DLFileRankModelImpl)dlFileRank;
304
305 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F_N,
306 new Object[] {
307 new Long(dlFileRankModelImpl.getOriginalCompanyId()),
308 new Long(dlFileRankModelImpl.getOriginalUserId()),
309 new Long(dlFileRankModelImpl.getOriginalFolderId()),
310
311 dlFileRankModelImpl.getOriginalName()
312 });
313
314 EntityCacheUtil.removeResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
315 DLFileRankImpl.class, dlFileRank.getPrimaryKey());
316
317 return dlFileRank;
318 }
319
320 public DLFileRank updateImpl(
321 com.liferay.portlet.documentlibrary.model.DLFileRank dlFileRank,
322 boolean merge) throws SystemException {
323 dlFileRank = toUnwrappedModel(dlFileRank);
324
325 boolean isNew = dlFileRank.isNew();
326
327 DLFileRankModelImpl dlFileRankModelImpl = (DLFileRankModelImpl)dlFileRank;
328
329 Session session = null;
330
331 try {
332 session = openSession();
333
334 BatchSessionUtil.update(session, dlFileRank, merge);
335
336 dlFileRank.setNew(false);
337 }
338 catch (Exception e) {
339 throw processException(e);
340 }
341 finally {
342 closeSession(session);
343 }
344
345 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
346
347 EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
348 DLFileRankImpl.class, dlFileRank.getPrimaryKey(), dlFileRank);
349
350 if (!isNew &&
351 ((dlFileRank.getCompanyId() != dlFileRankModelImpl.getOriginalCompanyId()) ||
352 (dlFileRank.getUserId() != dlFileRankModelImpl.getOriginalUserId()) ||
353 (dlFileRank.getFolderId() != dlFileRankModelImpl.getOriginalFolderId()) ||
354 !Validator.equals(dlFileRank.getName(),
355 dlFileRankModelImpl.getOriginalName()))) {
356 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F_N,
357 new Object[] {
358 new Long(dlFileRankModelImpl.getOriginalCompanyId()),
359 new Long(dlFileRankModelImpl.getOriginalUserId()),
360 new Long(dlFileRankModelImpl.getOriginalFolderId()),
361
362 dlFileRankModelImpl.getOriginalName()
363 });
364 }
365
366 if (isNew ||
367 ((dlFileRank.getCompanyId() != dlFileRankModelImpl.getOriginalCompanyId()) ||
368 (dlFileRank.getUserId() != dlFileRankModelImpl.getOriginalUserId()) ||
369 (dlFileRank.getFolderId() != dlFileRankModelImpl.getOriginalFolderId()) ||
370 !Validator.equals(dlFileRank.getName(),
371 dlFileRankModelImpl.getOriginalName()))) {
372 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F_N,
373 new Object[] {
374 new Long(dlFileRank.getCompanyId()),
375 new Long(dlFileRank.getUserId()),
376 new Long(dlFileRank.getFolderId()),
377
378 dlFileRank.getName()
379 }, dlFileRank);
380 }
381
382 return dlFileRank;
383 }
384
385 protected DLFileRank toUnwrappedModel(DLFileRank dlFileRank) {
386 if (dlFileRank instanceof DLFileRankImpl) {
387 return dlFileRank;
388 }
389
390 DLFileRankImpl dlFileRankImpl = new DLFileRankImpl();
391
392 dlFileRankImpl.setNew(dlFileRank.isNew());
393 dlFileRankImpl.setPrimaryKey(dlFileRank.getPrimaryKey());
394
395 dlFileRankImpl.setFileRankId(dlFileRank.getFileRankId());
396 dlFileRankImpl.setGroupId(dlFileRank.getGroupId());
397 dlFileRankImpl.setCompanyId(dlFileRank.getCompanyId());
398 dlFileRankImpl.setUserId(dlFileRank.getUserId());
399 dlFileRankImpl.setCreateDate(dlFileRank.getCreateDate());
400 dlFileRankImpl.setFolderId(dlFileRank.getFolderId());
401 dlFileRankImpl.setName(dlFileRank.getName());
402
403 return dlFileRankImpl;
404 }
405
406
414 public DLFileRank findByPrimaryKey(Serializable primaryKey)
415 throws NoSuchModelException, SystemException {
416 return findByPrimaryKey(((Long)primaryKey).longValue());
417 }
418
419
427 public DLFileRank findByPrimaryKey(long fileRankId)
428 throws NoSuchFileRankException, SystemException {
429 DLFileRank dlFileRank = fetchByPrimaryKey(fileRankId);
430
431 if (dlFileRank == null) {
432 if (_log.isWarnEnabled()) {
433 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileRankId);
434 }
435
436 throw new NoSuchFileRankException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
437 fileRankId);
438 }
439
440 return dlFileRank;
441 }
442
443
450 public DLFileRank fetchByPrimaryKey(Serializable primaryKey)
451 throws SystemException {
452 return fetchByPrimaryKey(((Long)primaryKey).longValue());
453 }
454
455
462 public DLFileRank fetchByPrimaryKey(long fileRankId)
463 throws SystemException {
464 DLFileRank dlFileRank = (DLFileRank)EntityCacheUtil.getResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
465 DLFileRankImpl.class, fileRankId, this);
466
467 if (dlFileRank == null) {
468 Session session = null;
469
470 try {
471 session = openSession();
472
473 dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
474 new Long(fileRankId));
475 }
476 catch (Exception e) {
477 throw processException(e);
478 }
479 finally {
480 if (dlFileRank != null) {
481 cacheResult(dlFileRank);
482 }
483
484 closeSession(session);
485 }
486 }
487
488 return dlFileRank;
489 }
490
491
498 public List<DLFileRank> findByUserId(long userId) throws SystemException {
499 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
500 }
501
502
515 public List<DLFileRank> findByUserId(long userId, int start, int end)
516 throws SystemException {
517 return findByUserId(userId, start, end, null);
518 }
519
520
534 public List<DLFileRank> findByUserId(long userId, int start, int end,
535 OrderByComparator orderByComparator) throws SystemException {
536 Object[] finderArgs = new Object[] {
537 userId,
538
539 String.valueOf(start), String.valueOf(end),
540 String.valueOf(orderByComparator)
541 };
542
543 List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
544 finderArgs, this);
545
546 if (list == null) {
547 Session session = null;
548
549 try {
550 session = openSession();
551
552 StringBundler query = null;
553
554 if (orderByComparator != null) {
555 query = new StringBundler(3 +
556 (orderByComparator.getOrderByFields().length * 3));
557 }
558 else {
559 query = new StringBundler(3);
560 }
561
562 query.append(_SQL_SELECT_DLFILERANK_WHERE);
563
564 query.append(_FINDER_COLUMN_USERID_USERID_2);
565
566 if (orderByComparator != null) {
567 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
568 orderByComparator);
569 }
570
571 else {
572 query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
573 }
574
575 String sql = query.toString();
576
577 Query q = session.createQuery(sql);
578
579 QueryPos qPos = QueryPos.getInstance(q);
580
581 qPos.add(userId);
582
583 list = (List<DLFileRank>)QueryUtil.list(q, getDialect(), start,
584 end);
585 }
586 catch (Exception e) {
587 throw processException(e);
588 }
589 finally {
590 if (list == null) {
591 list = new ArrayList<DLFileRank>();
592 }
593
594 cacheResult(list);
595
596 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
597 finderArgs, list);
598
599 closeSession(session);
600 }
601 }
602
603 return list;
604 }
605
606
619 public DLFileRank findByUserId_First(long userId,
620 OrderByComparator orderByComparator)
621 throws NoSuchFileRankException, SystemException {
622 List<DLFileRank> list = findByUserId(userId, 0, 1, orderByComparator);
623
624 if (list.isEmpty()) {
625 StringBundler msg = new StringBundler(4);
626
627 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
628
629 msg.append("userId=");
630 msg.append(userId);
631
632 msg.append(StringPool.CLOSE_CURLY_BRACE);
633
634 throw new NoSuchFileRankException(msg.toString());
635 }
636 else {
637 return list.get(0);
638 }
639 }
640
641
654 public DLFileRank findByUserId_Last(long userId,
655 OrderByComparator orderByComparator)
656 throws NoSuchFileRankException, SystemException {
657 int count = countByUserId(userId);
658
659 List<DLFileRank> list = findByUserId(userId, count - 1, count,
660 orderByComparator);
661
662 if (list.isEmpty()) {
663 StringBundler msg = new StringBundler(4);
664
665 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
666
667 msg.append("userId=");
668 msg.append(userId);
669
670 msg.append(StringPool.CLOSE_CURLY_BRACE);
671
672 throw new NoSuchFileRankException(msg.toString());
673 }
674 else {
675 return list.get(0);
676 }
677 }
678
679
693 public DLFileRank[] findByUserId_PrevAndNext(long fileRankId, long userId,
694 OrderByComparator orderByComparator)
695 throws NoSuchFileRankException, SystemException {
696 DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
697
698 Session session = null;
699
700 try {
701 session = openSession();
702
703 DLFileRank[] array = new DLFileRankImpl[3];
704
705 array[0] = getByUserId_PrevAndNext(session, dlFileRank, userId,
706 orderByComparator, true);
707
708 array[1] = dlFileRank;
709
710 array[2] = getByUserId_PrevAndNext(session, dlFileRank, userId,
711 orderByComparator, false);
712
713 return array;
714 }
715 catch (Exception e) {
716 throw processException(e);
717 }
718 finally {
719 closeSession(session);
720 }
721 }
722
723 protected DLFileRank getByUserId_PrevAndNext(Session session,
724 DLFileRank dlFileRank, long userId,
725 OrderByComparator orderByComparator, boolean previous) {
726 StringBundler query = null;
727
728 if (orderByComparator != null) {
729 query = new StringBundler(6 +
730 (orderByComparator.getOrderByFields().length * 6));
731 }
732 else {
733 query = new StringBundler(3);
734 }
735
736 query.append(_SQL_SELECT_DLFILERANK_WHERE);
737
738 query.append(_FINDER_COLUMN_USERID_USERID_2);
739
740 if (orderByComparator != null) {
741 String[] orderByFields = orderByComparator.getOrderByFields();
742
743 if (orderByFields.length > 0) {
744 query.append(WHERE_AND);
745 }
746
747 for (int i = 0; i < orderByFields.length; i++) {
748 query.append(_ORDER_BY_ENTITY_ALIAS);
749 query.append(orderByFields[i]);
750
751 if ((i + 1) < orderByFields.length) {
752 if (orderByComparator.isAscending() ^ previous) {
753 query.append(WHERE_GREATER_THAN_HAS_NEXT);
754 }
755 else {
756 query.append(WHERE_LESSER_THAN_HAS_NEXT);
757 }
758 }
759 else {
760 if (orderByComparator.isAscending() ^ previous) {
761 query.append(WHERE_GREATER_THAN);
762 }
763 else {
764 query.append(WHERE_LESSER_THAN);
765 }
766 }
767 }
768
769 query.append(ORDER_BY_CLAUSE);
770
771 for (int i = 0; i < orderByFields.length; i++) {
772 query.append(_ORDER_BY_ENTITY_ALIAS);
773 query.append(orderByFields[i]);
774
775 if ((i + 1) < orderByFields.length) {
776 if (orderByComparator.isAscending() ^ previous) {
777 query.append(ORDER_BY_ASC_HAS_NEXT);
778 }
779 else {
780 query.append(ORDER_BY_DESC_HAS_NEXT);
781 }
782 }
783 else {
784 if (orderByComparator.isAscending() ^ previous) {
785 query.append(ORDER_BY_ASC);
786 }
787 else {
788 query.append(ORDER_BY_DESC);
789 }
790 }
791 }
792 }
793
794 else {
795 query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
796 }
797
798 String sql = query.toString();
799
800 Query q = session.createQuery(sql);
801
802 q.setFirstResult(0);
803 q.setMaxResults(2);
804
805 QueryPos qPos = QueryPos.getInstance(q);
806
807 qPos.add(userId);
808
809 if (orderByComparator != null) {
810 Object[] values = orderByComparator.getOrderByValues(dlFileRank);
811
812 for (Object value : values) {
813 qPos.add(value);
814 }
815 }
816
817 List<DLFileRank> list = q.list();
818
819 if (list.size() == 2) {
820 return list.get(1);
821 }
822 else {
823 return null;
824 }
825 }
826
827
835 public List<DLFileRank> findByG_U(long groupId, long userId)
836 throws SystemException {
837 return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
838 null);
839 }
840
841
855 public List<DLFileRank> findByG_U(long groupId, long userId, int start,
856 int end) throws SystemException {
857 return findByG_U(groupId, userId, start, end, null);
858 }
859
860
875 public List<DLFileRank> findByG_U(long groupId, long userId, int start,
876 int end, OrderByComparator orderByComparator) throws SystemException {
877 Object[] finderArgs = new Object[] {
878 groupId, userId,
879
880 String.valueOf(start), String.valueOf(end),
881 String.valueOf(orderByComparator)
882 };
883
884 List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
885 finderArgs, this);
886
887 if (list == null) {
888 Session session = null;
889
890 try {
891 session = openSession();
892
893 StringBundler query = null;
894
895 if (orderByComparator != null) {
896 query = new StringBundler(4 +
897 (orderByComparator.getOrderByFields().length * 3));
898 }
899 else {
900 query = new StringBundler(4);
901 }
902
903 query.append(_SQL_SELECT_DLFILERANK_WHERE);
904
905 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
906
907 query.append(_FINDER_COLUMN_G_U_USERID_2);
908
909 if (orderByComparator != null) {
910 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
911 orderByComparator);
912 }
913
914 else {
915 query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
916 }
917
918 String sql = query.toString();
919
920 Query q = session.createQuery(sql);
921
922 QueryPos qPos = QueryPos.getInstance(q);
923
924 qPos.add(groupId);
925
926 qPos.add(userId);
927
928 list = (List<DLFileRank>)QueryUtil.list(q, getDialect(), start,
929 end);
930 }
931 catch (Exception e) {
932 throw processException(e);
933 }
934 finally {
935 if (list == null) {
936 list = new ArrayList<DLFileRank>();
937 }
938
939 cacheResult(list);
940
941 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U, finderArgs,
942 list);
943
944 closeSession(session);
945 }
946 }
947
948 return list;
949 }
950
951
965 public DLFileRank findByG_U_First(long groupId, long userId,
966 OrderByComparator orderByComparator)
967 throws NoSuchFileRankException, SystemException {
968 List<DLFileRank> list = findByG_U(groupId, userId, 0, 1,
969 orderByComparator);
970
971 if (list.isEmpty()) {
972 StringBundler msg = new StringBundler(6);
973
974 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
975
976 msg.append("groupId=");
977 msg.append(groupId);
978
979 msg.append(", userId=");
980 msg.append(userId);
981
982 msg.append(StringPool.CLOSE_CURLY_BRACE);
983
984 throw new NoSuchFileRankException(msg.toString());
985 }
986 else {
987 return list.get(0);
988 }
989 }
990
991
1005 public DLFileRank findByG_U_Last(long groupId, long userId,
1006 OrderByComparator orderByComparator)
1007 throws NoSuchFileRankException, SystemException {
1008 int count = countByG_U(groupId, userId);
1009
1010 List<DLFileRank> list = findByG_U(groupId, userId, count - 1, count,
1011 orderByComparator);
1012
1013 if (list.isEmpty()) {
1014 StringBundler msg = new StringBundler(6);
1015
1016 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1017
1018 msg.append("groupId=");
1019 msg.append(groupId);
1020
1021 msg.append(", userId=");
1022 msg.append(userId);
1023
1024 msg.append(StringPool.CLOSE_CURLY_BRACE);
1025
1026 throw new NoSuchFileRankException(msg.toString());
1027 }
1028 else {
1029 return list.get(0);
1030 }
1031 }
1032
1033
1048 public DLFileRank[] findByG_U_PrevAndNext(long fileRankId, long groupId,
1049 long userId, OrderByComparator orderByComparator)
1050 throws NoSuchFileRankException, SystemException {
1051 DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
1052
1053 Session session = null;
1054
1055 try {
1056 session = openSession();
1057
1058 DLFileRank[] array = new DLFileRankImpl[3];
1059
1060 array[0] = getByG_U_PrevAndNext(session, dlFileRank, groupId,
1061 userId, orderByComparator, true);
1062
1063 array[1] = dlFileRank;
1064
1065 array[2] = getByG_U_PrevAndNext(session, dlFileRank, groupId,
1066 userId, orderByComparator, false);
1067
1068 return array;
1069 }
1070 catch (Exception e) {
1071 throw processException(e);
1072 }
1073 finally {
1074 closeSession(session);
1075 }
1076 }
1077
1078 protected DLFileRank getByG_U_PrevAndNext(Session session,
1079 DLFileRank dlFileRank, long groupId, long userId,
1080 OrderByComparator orderByComparator, boolean previous) {
1081 StringBundler query = null;
1082
1083 if (orderByComparator != null) {
1084 query = new StringBundler(6 +
1085 (orderByComparator.getOrderByFields().length * 6));
1086 }
1087 else {
1088 query = new StringBundler(3);
1089 }
1090
1091 query.append(_SQL_SELECT_DLFILERANK_WHERE);
1092
1093 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1094
1095 query.append(_FINDER_COLUMN_G_U_USERID_2);
1096
1097 if (orderByComparator != null) {
1098 String[] orderByFields = orderByComparator.getOrderByFields();
1099
1100 if (orderByFields.length > 0) {
1101 query.append(WHERE_AND);
1102 }
1103
1104 for (int i = 0; i < orderByFields.length; i++) {
1105 query.append(_ORDER_BY_ENTITY_ALIAS);
1106 query.append(orderByFields[i]);
1107
1108 if ((i + 1) < orderByFields.length) {
1109 if (orderByComparator.isAscending() ^ previous) {
1110 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1111 }
1112 else {
1113 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1114 }
1115 }
1116 else {
1117 if (orderByComparator.isAscending() ^ previous) {
1118 query.append(WHERE_GREATER_THAN);
1119 }
1120 else {
1121 query.append(WHERE_LESSER_THAN);
1122 }
1123 }
1124 }
1125
1126 query.append(ORDER_BY_CLAUSE);
1127
1128 for (int i = 0; i < orderByFields.length; i++) {
1129 query.append(_ORDER_BY_ENTITY_ALIAS);
1130 query.append(orderByFields[i]);
1131
1132 if ((i + 1) < orderByFields.length) {
1133 if (orderByComparator.isAscending() ^ previous) {
1134 query.append(ORDER_BY_ASC_HAS_NEXT);
1135 }
1136 else {
1137 query.append(ORDER_BY_DESC_HAS_NEXT);
1138 }
1139 }
1140 else {
1141 if (orderByComparator.isAscending() ^ previous) {
1142 query.append(ORDER_BY_ASC);
1143 }
1144 else {
1145 query.append(ORDER_BY_DESC);
1146 }
1147 }
1148 }
1149 }
1150
1151 else {
1152 query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1153 }
1154
1155 String sql = query.toString();
1156
1157 Query q = session.createQuery(sql);
1158
1159 q.setFirstResult(0);
1160 q.setMaxResults(2);
1161
1162 QueryPos qPos = QueryPos.getInstance(q);
1163
1164 qPos.add(groupId);
1165
1166 qPos.add(userId);
1167
1168 if (orderByComparator != null) {
1169 Object[] values = orderByComparator.getOrderByValues(dlFileRank);
1170
1171 for (Object value : values) {
1172 qPos.add(value);
1173 }
1174 }
1175
1176 List<DLFileRank> list = q.list();
1177
1178 if (list.size() == 2) {
1179 return list.get(1);
1180 }
1181 else {
1182 return null;
1183 }
1184 }
1185
1186
1194 public List<DLFileRank> findByF_N(long folderId, String name)
1195 throws SystemException {
1196 return findByF_N(folderId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1197 null);
1198 }
1199
1200
1214 public List<DLFileRank> findByF_N(long folderId, String name, int start,
1215 int end) throws SystemException {
1216 return findByF_N(folderId, name, start, end, null);
1217 }
1218
1219
1234 public List<DLFileRank> findByF_N(long folderId, String name, int start,
1235 int end, OrderByComparator orderByComparator) throws SystemException {
1236 Object[] finderArgs = new Object[] {
1237 folderId, name,
1238
1239 String.valueOf(start), String.valueOf(end),
1240 String.valueOf(orderByComparator)
1241 };
1242
1243 List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_F_N,
1244 finderArgs, this);
1245
1246 if (list == null) {
1247 Session session = null;
1248
1249 try {
1250 session = openSession();
1251
1252 StringBundler query = null;
1253
1254 if (orderByComparator != null) {
1255 query = new StringBundler(4 +
1256 (orderByComparator.getOrderByFields().length * 3));
1257 }
1258 else {
1259 query = new StringBundler(4);
1260 }
1261
1262 query.append(_SQL_SELECT_DLFILERANK_WHERE);
1263
1264 query.append(_FINDER_COLUMN_F_N_FOLDERID_2);
1265
1266 if (name == null) {
1267 query.append(_FINDER_COLUMN_F_N_NAME_1);
1268 }
1269 else {
1270 if (name.equals(StringPool.BLANK)) {
1271 query.append(_FINDER_COLUMN_F_N_NAME_3);
1272 }
1273 else {
1274 query.append(_FINDER_COLUMN_F_N_NAME_2);
1275 }
1276 }
1277
1278 if (orderByComparator != null) {
1279 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1280 orderByComparator);
1281 }
1282
1283 else {
1284 query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1285 }
1286
1287 String sql = query.toString();
1288
1289 Query q = session.createQuery(sql);
1290
1291 QueryPos qPos = QueryPos.getInstance(q);
1292
1293 qPos.add(folderId);
1294
1295 if (name != null) {
1296 qPos.add(name);
1297 }
1298
1299 list = (List<DLFileRank>)QueryUtil.list(q, getDialect(), start,
1300 end);
1301 }
1302 catch (Exception e) {
1303 throw processException(e);
1304 }
1305 finally {
1306 if (list == null) {
1307 list = new ArrayList<DLFileRank>();
1308 }
1309
1310 cacheResult(list);
1311
1312 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_F_N, finderArgs,
1313 list);
1314
1315 closeSession(session);
1316 }
1317 }
1318
1319 return list;
1320 }
1321
1322
1336 public DLFileRank findByF_N_First(long folderId, String name,
1337 OrderByComparator orderByComparator)
1338 throws NoSuchFileRankException, SystemException {
1339 List<DLFileRank> list = findByF_N(folderId, name, 0, 1,
1340 orderByComparator);
1341
1342 if (list.isEmpty()) {
1343 StringBundler msg = new StringBundler(6);
1344
1345 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1346
1347 msg.append("folderId=");
1348 msg.append(folderId);
1349
1350 msg.append(", name=");
1351 msg.append(name);
1352
1353 msg.append(StringPool.CLOSE_CURLY_BRACE);
1354
1355 throw new NoSuchFileRankException(msg.toString());
1356 }
1357 else {
1358 return list.get(0);
1359 }
1360 }
1361
1362
1376 public DLFileRank findByF_N_Last(long folderId, String name,
1377 OrderByComparator orderByComparator)
1378 throws NoSuchFileRankException, SystemException {
1379 int count = countByF_N(folderId, name);
1380
1381 List<DLFileRank> list = findByF_N(folderId, name, count - 1, count,
1382 orderByComparator);
1383
1384 if (list.isEmpty()) {
1385 StringBundler msg = new StringBundler(6);
1386
1387 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1388
1389 msg.append("folderId=");
1390 msg.append(folderId);
1391
1392 msg.append(", name=");
1393 msg.append(name);
1394
1395 msg.append(StringPool.CLOSE_CURLY_BRACE);
1396
1397 throw new NoSuchFileRankException(msg.toString());
1398 }
1399 else {
1400 return list.get(0);
1401 }
1402 }
1403
1404
1419 public DLFileRank[] findByF_N_PrevAndNext(long fileRankId, long folderId,
1420 String name, OrderByComparator orderByComparator)
1421 throws NoSuchFileRankException, SystemException {
1422 DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
1423
1424 Session session = null;
1425
1426 try {
1427 session = openSession();
1428
1429 DLFileRank[] array = new DLFileRankImpl[3];
1430
1431 array[0] = getByF_N_PrevAndNext(session, dlFileRank, folderId,
1432 name, orderByComparator, true);
1433
1434 array[1] = dlFileRank;
1435
1436 array[2] = getByF_N_PrevAndNext(session, dlFileRank, folderId,
1437 name, orderByComparator, false);
1438
1439 return array;
1440 }
1441 catch (Exception e) {
1442 throw processException(e);
1443 }
1444 finally {
1445 closeSession(session);
1446 }
1447 }
1448
1449 protected DLFileRank getByF_N_PrevAndNext(Session session,
1450 DLFileRank dlFileRank, long folderId, String name,
1451 OrderByComparator orderByComparator, boolean previous) {
1452 StringBundler query = null;
1453
1454 if (orderByComparator != null) {
1455 query = new StringBundler(6 +
1456 (orderByComparator.getOrderByFields().length * 6));
1457 }
1458 else {
1459 query = new StringBundler(3);
1460 }
1461
1462 query.append(_SQL_SELECT_DLFILERANK_WHERE);
1463
1464 query.append(_FINDER_COLUMN_F_N_FOLDERID_2);
1465
1466 if (name == null) {
1467 query.append(_FINDER_COLUMN_F_N_NAME_1);
1468 }
1469 else {
1470 if (name.equals(StringPool.BLANK)) {
1471 query.append(_FINDER_COLUMN_F_N_NAME_3);
1472 }
1473 else {
1474 query.append(_FINDER_COLUMN_F_N_NAME_2);
1475 }
1476 }
1477
1478 if (orderByComparator != null) {
1479 String[] orderByFields = orderByComparator.getOrderByFields();
1480
1481 if (orderByFields.length > 0) {
1482 query.append(WHERE_AND);
1483 }
1484
1485 for (int i = 0; i < orderByFields.length; i++) {
1486 query.append(_ORDER_BY_ENTITY_ALIAS);
1487 query.append(orderByFields[i]);
1488
1489 if ((i + 1) < orderByFields.length) {
1490 if (orderByComparator.isAscending() ^ previous) {
1491 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1492 }
1493 else {
1494 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1495 }
1496 }
1497 else {
1498 if (orderByComparator.isAscending() ^ previous) {
1499 query.append(WHERE_GREATER_THAN);
1500 }
1501 else {
1502 query.append(WHERE_LESSER_THAN);
1503 }
1504 }
1505 }
1506
1507 query.append(ORDER_BY_CLAUSE);
1508
1509 for (int i = 0; i < orderByFields.length; i++) {
1510 query.append(_ORDER_BY_ENTITY_ALIAS);
1511 query.append(orderByFields[i]);
1512
1513 if ((i + 1) < orderByFields.length) {
1514 if (orderByComparator.isAscending() ^ previous) {
1515 query.append(ORDER_BY_ASC_HAS_NEXT);
1516 }
1517 else {
1518 query.append(ORDER_BY_DESC_HAS_NEXT);
1519 }
1520 }
1521 else {
1522 if (orderByComparator.isAscending() ^ previous) {
1523 query.append(ORDER_BY_ASC);
1524 }
1525 else {
1526 query.append(ORDER_BY_DESC);
1527 }
1528 }
1529 }
1530 }
1531
1532 else {
1533 query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1534 }
1535
1536 String sql = query.toString();
1537
1538 Query q = session.createQuery(sql);
1539
1540 q.setFirstResult(0);
1541 q.setMaxResults(2);
1542
1543 QueryPos qPos = QueryPos.getInstance(q);
1544
1545 qPos.add(folderId);
1546
1547 if (name != null) {
1548 qPos.add(name);
1549 }
1550
1551 if (orderByComparator != null) {
1552 Object[] values = orderByComparator.getOrderByValues(dlFileRank);
1553
1554 for (Object value : values) {
1555 qPos.add(value);
1556 }
1557 }
1558
1559 List<DLFileRank> list = q.list();
1560
1561 if (list.size() == 2) {
1562 return list.get(1);
1563 }
1564 else {
1565 return null;
1566 }
1567 }
1568
1569
1580 public DLFileRank findByC_U_F_N(long companyId, long userId, long folderId,
1581 String name) throws NoSuchFileRankException, SystemException {
1582 DLFileRank dlFileRank = fetchByC_U_F_N(companyId, userId, folderId, name);
1583
1584 if (dlFileRank == null) {
1585 StringBundler msg = new StringBundler(10);
1586
1587 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1588
1589 msg.append("companyId=");
1590 msg.append(companyId);
1591
1592 msg.append(", userId=");
1593 msg.append(userId);
1594
1595 msg.append(", folderId=");
1596 msg.append(folderId);
1597
1598 msg.append(", name=");
1599 msg.append(name);
1600
1601 msg.append(StringPool.CLOSE_CURLY_BRACE);
1602
1603 if (_log.isWarnEnabled()) {
1604 _log.warn(msg.toString());
1605 }
1606
1607 throw new NoSuchFileRankException(msg.toString());
1608 }
1609
1610 return dlFileRank;
1611 }
1612
1613
1623 public DLFileRank fetchByC_U_F_N(long companyId, long userId,
1624 long folderId, String name) throws SystemException {
1625 return fetchByC_U_F_N(companyId, userId, folderId, name, true);
1626 }
1627
1628
1638 public DLFileRank fetchByC_U_F_N(long companyId, long userId,
1639 long folderId, String name, boolean retrieveFromCache)
1640 throws SystemException {
1641 Object[] finderArgs = new Object[] { companyId, userId, folderId, name };
1642
1643 Object result = null;
1644
1645 if (retrieveFromCache) {
1646 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_U_F_N,
1647 finderArgs, this);
1648 }
1649
1650 if (result == null) {
1651 Session session = null;
1652
1653 try {
1654 session = openSession();
1655
1656 StringBundler query = new StringBundler(6);
1657
1658 query.append(_SQL_SELECT_DLFILERANK_WHERE);
1659
1660 query.append(_FINDER_COLUMN_C_U_F_N_COMPANYID_2);
1661
1662 query.append(_FINDER_COLUMN_C_U_F_N_USERID_2);
1663
1664 query.append(_FINDER_COLUMN_C_U_F_N_FOLDERID_2);
1665
1666 if (name == null) {
1667 query.append(_FINDER_COLUMN_C_U_F_N_NAME_1);
1668 }
1669 else {
1670 if (name.equals(StringPool.BLANK)) {
1671 query.append(_FINDER_COLUMN_C_U_F_N_NAME_3);
1672 }
1673 else {
1674 query.append(_FINDER_COLUMN_C_U_F_N_NAME_2);
1675 }
1676 }
1677
1678 query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1679
1680 String sql = query.toString();
1681
1682 Query q = session.createQuery(sql);
1683
1684 QueryPos qPos = QueryPos.getInstance(q);
1685
1686 qPos.add(companyId);
1687
1688 qPos.add(userId);
1689
1690 qPos.add(folderId);
1691
1692 if (name != null) {
1693 qPos.add(name);
1694 }
1695
1696 List<DLFileRank> list = q.list();
1697
1698 result = list;
1699
1700 DLFileRank dlFileRank = null;
1701
1702 if (list.isEmpty()) {
1703 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F_N,
1704 finderArgs, list);
1705 }
1706 else {
1707 dlFileRank = list.get(0);
1708
1709 cacheResult(dlFileRank);
1710
1711 if ((dlFileRank.getCompanyId() != companyId) ||
1712 (dlFileRank.getUserId() != userId) ||
1713 (dlFileRank.getFolderId() != folderId) ||
1714 (dlFileRank.getName() == null) ||
1715 !dlFileRank.getName().equals(name)) {
1716 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F_N,
1717 finderArgs, dlFileRank);
1718 }
1719 }
1720
1721 return dlFileRank;
1722 }
1723 catch (Exception e) {
1724 throw processException(e);
1725 }
1726 finally {
1727 if (result == null) {
1728 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F_N,
1729 finderArgs, new ArrayList<DLFileRank>());
1730 }
1731
1732 closeSession(session);
1733 }
1734 }
1735 else {
1736 if (result instanceof List<?>) {
1737 return null;
1738 }
1739 else {
1740 return (DLFileRank)result;
1741 }
1742 }
1743 }
1744
1745
1751 public List<DLFileRank> findAll() throws SystemException {
1752 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1753 }
1754
1755
1767 public List<DLFileRank> findAll(int start, int end)
1768 throws SystemException {
1769 return findAll(start, end, null);
1770 }
1771
1772
1785 public List<DLFileRank> findAll(int start, int end,
1786 OrderByComparator orderByComparator) throws SystemException {
1787 Object[] finderArgs = new Object[] {
1788 String.valueOf(start), String.valueOf(end),
1789 String.valueOf(orderByComparator)
1790 };
1791
1792 List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1793 finderArgs, this);
1794
1795 if (list == null) {
1796 Session session = null;
1797
1798 try {
1799 session = openSession();
1800
1801 StringBundler query = null;
1802 String sql = null;
1803
1804 if (orderByComparator != null) {
1805 query = new StringBundler(2 +
1806 (orderByComparator.getOrderByFields().length * 3));
1807
1808 query.append(_SQL_SELECT_DLFILERANK);
1809
1810 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1811 orderByComparator);
1812
1813 sql = query.toString();
1814 }
1815 else {
1816 sql = _SQL_SELECT_DLFILERANK.concat(DLFileRankModelImpl.ORDER_BY_JPQL);
1817 }
1818
1819 Query q = session.createQuery(sql);
1820
1821 if (orderByComparator == null) {
1822 list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1823 start, end, false);
1824
1825 Collections.sort(list);
1826 }
1827 else {
1828 list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1829 start, end);
1830 }
1831 }
1832 catch (Exception e) {
1833 throw processException(e);
1834 }
1835 finally {
1836 if (list == null) {
1837 list = new ArrayList<DLFileRank>();
1838 }
1839
1840 cacheResult(list);
1841
1842 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1843
1844 closeSession(session);
1845 }
1846 }
1847
1848 return list;
1849 }
1850
1851
1857 public void removeByUserId(long userId) throws SystemException {
1858 for (DLFileRank dlFileRank : findByUserId(userId)) {
1859 remove(dlFileRank);
1860 }
1861 }
1862
1863
1870 public void removeByG_U(long groupId, long userId)
1871 throws SystemException {
1872 for (DLFileRank dlFileRank : findByG_U(groupId, userId)) {
1873 remove(dlFileRank);
1874 }
1875 }
1876
1877
1884 public void removeByF_N(long folderId, String name)
1885 throws SystemException {
1886 for (DLFileRank dlFileRank : findByF_N(folderId, name)) {
1887 remove(dlFileRank);
1888 }
1889 }
1890
1891
1900 public void removeByC_U_F_N(long companyId, long userId, long folderId,
1901 String name) throws NoSuchFileRankException, SystemException {
1902 DLFileRank dlFileRank = findByC_U_F_N(companyId, userId, folderId, name);
1903
1904 remove(dlFileRank);
1905 }
1906
1907
1912 public void removeAll() throws SystemException {
1913 for (DLFileRank dlFileRank : findAll()) {
1914 remove(dlFileRank);
1915 }
1916 }
1917
1918
1925 public int countByUserId(long userId) throws SystemException {
1926 Object[] finderArgs = new Object[] { userId };
1927
1928 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1929 finderArgs, this);
1930
1931 if (count == null) {
1932 Session session = null;
1933
1934 try {
1935 session = openSession();
1936
1937 StringBundler query = new StringBundler(2);
1938
1939 query.append(_SQL_COUNT_DLFILERANK_WHERE);
1940
1941 query.append(_FINDER_COLUMN_USERID_USERID_2);
1942
1943 String sql = query.toString();
1944
1945 Query q = session.createQuery(sql);
1946
1947 QueryPos qPos = QueryPos.getInstance(q);
1948
1949 qPos.add(userId);
1950
1951 count = (Long)q.uniqueResult();
1952 }
1953 catch (Exception e) {
1954 throw processException(e);
1955 }
1956 finally {
1957 if (count == null) {
1958 count = Long.valueOf(0);
1959 }
1960
1961 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1962 finderArgs, count);
1963
1964 closeSession(session);
1965 }
1966 }
1967
1968 return count.intValue();
1969 }
1970
1971
1979 public int countByG_U(long groupId, long userId) throws SystemException {
1980 Object[] finderArgs = new Object[] { groupId, userId };
1981
1982 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1983 finderArgs, this);
1984
1985 if (count == null) {
1986 Session session = null;
1987
1988 try {
1989 session = openSession();
1990
1991 StringBundler query = new StringBundler(3);
1992
1993 query.append(_SQL_COUNT_DLFILERANK_WHERE);
1994
1995 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1996
1997 query.append(_FINDER_COLUMN_G_U_USERID_2);
1998
1999 String sql = query.toString();
2000
2001 Query q = session.createQuery(sql);
2002
2003 QueryPos qPos = QueryPos.getInstance(q);
2004
2005 qPos.add(groupId);
2006
2007 qPos.add(userId);
2008
2009 count = (Long)q.uniqueResult();
2010 }
2011 catch (Exception e) {
2012 throw processException(e);
2013 }
2014 finally {
2015 if (count == null) {
2016 count = Long.valueOf(0);
2017 }
2018
2019 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
2020 count);
2021
2022 closeSession(session);
2023 }
2024 }
2025
2026 return count.intValue();
2027 }
2028
2029
2037 public int countByF_N(long folderId, String name) throws SystemException {
2038 Object[] finderArgs = new Object[] { folderId, name };
2039
2040 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_F_N,
2041 finderArgs, this);
2042
2043 if (count == null) {
2044 Session session = null;
2045
2046 try {
2047 session = openSession();
2048
2049 StringBundler query = new StringBundler(3);
2050
2051 query.append(_SQL_COUNT_DLFILERANK_WHERE);
2052
2053 query.append(_FINDER_COLUMN_F_N_FOLDERID_2);
2054
2055 if (name == null) {
2056 query.append(_FINDER_COLUMN_F_N_NAME_1);
2057 }
2058 else {
2059 if (name.equals(StringPool.BLANK)) {
2060 query.append(_FINDER_COLUMN_F_N_NAME_3);
2061 }
2062 else {
2063 query.append(_FINDER_COLUMN_F_N_NAME_2);
2064 }
2065 }
2066
2067 String sql = query.toString();
2068
2069 Query q = session.createQuery(sql);
2070
2071 QueryPos qPos = QueryPos.getInstance(q);
2072
2073 qPos.add(folderId);
2074
2075 if (name != null) {
2076 qPos.add(name);
2077 }
2078
2079 count = (Long)q.uniqueResult();
2080 }
2081 catch (Exception e) {
2082 throw processException(e);
2083 }
2084 finally {
2085 if (count == null) {
2086 count = Long.valueOf(0);
2087 }
2088
2089 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_N, finderArgs,
2090 count);
2091
2092 closeSession(session);
2093 }
2094 }
2095
2096 return count.intValue();
2097 }
2098
2099
2109 public int countByC_U_F_N(long companyId, long userId, long folderId,
2110 String name) throws SystemException {
2111 Object[] finderArgs = new Object[] { companyId, userId, folderId, name };
2112
2113 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_U_F_N,
2114 finderArgs, this);
2115
2116 if (count == null) {
2117 Session session = null;
2118
2119 try {
2120 session = openSession();
2121
2122 StringBundler query = new StringBundler(5);
2123
2124 query.append(_SQL_COUNT_DLFILERANK_WHERE);
2125
2126 query.append(_FINDER_COLUMN_C_U_F_N_COMPANYID_2);
2127
2128 query.append(_FINDER_COLUMN_C_U_F_N_USERID_2);
2129
2130 query.append(_FINDER_COLUMN_C_U_F_N_FOLDERID_2);
2131
2132 if (name == null) {
2133 query.append(_FINDER_COLUMN_C_U_F_N_NAME_1);
2134 }
2135 else {
2136 if (name.equals(StringPool.BLANK)) {
2137 query.append(_FINDER_COLUMN_C_U_F_N_NAME_3);
2138 }
2139 else {
2140 query.append(_FINDER_COLUMN_C_U_F_N_NAME_2);
2141 }
2142 }
2143
2144 String sql = query.toString();
2145
2146 Query q = session.createQuery(sql);
2147
2148 QueryPos qPos = QueryPos.getInstance(q);
2149
2150 qPos.add(companyId);
2151
2152 qPos.add(userId);
2153
2154 qPos.add(folderId);
2155
2156 if (name != null) {
2157 qPos.add(name);
2158 }
2159
2160 count = (Long)q.uniqueResult();
2161 }
2162 catch (Exception e) {
2163 throw processException(e);
2164 }
2165 finally {
2166 if (count == null) {
2167 count = Long.valueOf(0);
2168 }
2169
2170 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_F_N,
2171 finderArgs, count);
2172
2173 closeSession(session);
2174 }
2175 }
2176
2177 return count.intValue();
2178 }
2179
2180
2186 public int countAll() throws SystemException {
2187 Object[] finderArgs = new Object[0];
2188
2189 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2190 finderArgs, this);
2191
2192 if (count == null) {
2193 Session session = null;
2194
2195 try {
2196 session = openSession();
2197
2198 Query q = session.createQuery(_SQL_COUNT_DLFILERANK);
2199
2200 count = (Long)q.uniqueResult();
2201 }
2202 catch (Exception e) {
2203 throw processException(e);
2204 }
2205 finally {
2206 if (count == null) {
2207 count = Long.valueOf(0);
2208 }
2209
2210 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2211 count);
2212
2213 closeSession(session);
2214 }
2215 }
2216
2217 return count.intValue();
2218 }
2219
2220
2223 public void afterPropertiesSet() {
2224 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2225 com.liferay.portal.util.PropsUtil.get(
2226 "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileRank")));
2227
2228 if (listenerClassNames.length > 0) {
2229 try {
2230 List<ModelListener<DLFileRank>> listenersList = new ArrayList<ModelListener<DLFileRank>>();
2231
2232 for (String listenerClassName : listenerClassNames) {
2233 listenersList.add((ModelListener<DLFileRank>)InstanceFactory.newInstance(
2234 listenerClassName));
2235 }
2236
2237 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2238 }
2239 catch (Exception e) {
2240 _log.error(e);
2241 }
2242 }
2243 }
2244
2245 @BeanReference(type = DLFileEntryPersistence.class)
2246 protected DLFileEntryPersistence dlFileEntryPersistence;
2247 @BeanReference(type = DLFileRankPersistence.class)
2248 protected DLFileRankPersistence dlFileRankPersistence;
2249 @BeanReference(type = DLFileShortcutPersistence.class)
2250 protected DLFileShortcutPersistence dlFileShortcutPersistence;
2251 @BeanReference(type = DLFileVersionPersistence.class)
2252 protected DLFileVersionPersistence dlFileVersionPersistence;
2253 @BeanReference(type = DLFolderPersistence.class)
2254 protected DLFolderPersistence dlFolderPersistence;
2255 @BeanReference(type = LayoutPersistence.class)
2256 protected LayoutPersistence layoutPersistence;
2257 @BeanReference(type = ResourcePersistence.class)
2258 protected ResourcePersistence resourcePersistence;
2259 @BeanReference(type = UserPersistence.class)
2260 protected UserPersistence userPersistence;
2261 private static final String _SQL_SELECT_DLFILERANK = "SELECT dlFileRank FROM DLFileRank dlFileRank";
2262 private static final String _SQL_SELECT_DLFILERANK_WHERE = "SELECT dlFileRank FROM DLFileRank dlFileRank WHERE ";
2263 private static final String _SQL_COUNT_DLFILERANK = "SELECT COUNT(dlFileRank) FROM DLFileRank dlFileRank";
2264 private static final String _SQL_COUNT_DLFILERANK_WHERE = "SELECT COUNT(dlFileRank) FROM DLFileRank dlFileRank WHERE ";
2265 private static final String _FINDER_COLUMN_USERID_USERID_2 = "dlFileRank.userId = ?";
2266 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "dlFileRank.groupId = ? AND ";
2267 private static final String _FINDER_COLUMN_G_U_USERID_2 = "dlFileRank.userId = ?";
2268 private static final String _FINDER_COLUMN_F_N_FOLDERID_2 = "dlFileRank.folderId = ? AND ";
2269 private static final String _FINDER_COLUMN_F_N_NAME_1 = "dlFileRank.name IS NULL";
2270 private static final String _FINDER_COLUMN_F_N_NAME_2 = "dlFileRank.name = ?";
2271 private static final String _FINDER_COLUMN_F_N_NAME_3 = "(dlFileRank.name IS NULL OR dlFileRank.name = ?)";
2272 private static final String _FINDER_COLUMN_C_U_F_N_COMPANYID_2 = "dlFileRank.companyId = ? AND ";
2273 private static final String _FINDER_COLUMN_C_U_F_N_USERID_2 = "dlFileRank.userId = ? AND ";
2274 private static final String _FINDER_COLUMN_C_U_F_N_FOLDERID_2 = "dlFileRank.folderId = ? AND ";
2275 private static final String _FINDER_COLUMN_C_U_F_N_NAME_1 = "dlFileRank.name IS NULL";
2276 private static final String _FINDER_COLUMN_C_U_F_N_NAME_2 = "dlFileRank.name = ?";
2277 private static final String _FINDER_COLUMN_C_U_F_N_NAME_3 = "(dlFileRank.name IS NULL OR dlFileRank.name = ?)";
2278 private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileRank.";
2279 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileRank exists with the primary key ";
2280 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileRank exists with the key {";
2281 private static Log _log = LogFactoryUtil.getLog(DLFileRankPersistenceImpl.class);
2282 }