1
22
23 package com.liferay.portlet.documentlibrary.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.dao.DynamicQuery;
27 import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
28 import com.liferay.portal.kernel.util.OrderByComparator;
29 import com.liferay.portal.kernel.util.StringMaker;
30 import com.liferay.portal.kernel.util.StringPool;
31 import com.liferay.portal.service.persistence.BasePersistence;
32 import com.liferay.portal.spring.hibernate.FinderCache;
33 import com.liferay.portal.spring.hibernate.HibernateUtil;
34
35 import com.liferay.portlet.documentlibrary.NoSuchFileRankException;
36 import com.liferay.portlet.documentlibrary.model.DLFileRank;
37 import com.liferay.portlet.documentlibrary.model.impl.DLFileRankImpl;
38
39 import com.liferay.util.dao.hibernate.QueryUtil;
40
41 import org.apache.commons.logging.Log;
42 import org.apache.commons.logging.LogFactory;
43
44 import org.hibernate.Query;
45 import org.hibernate.Session;
46
47 import java.util.Collections;
48 import java.util.Iterator;
49 import java.util.List;
50
51
57 public class DLFileRankPersistenceImpl extends BasePersistence
58 implements DLFileRankPersistence {
59 public DLFileRank create(long fileRankId) {
60 DLFileRank dlFileRank = new DLFileRankImpl();
61 dlFileRank.setNew(true);
62 dlFileRank.setPrimaryKey(fileRankId);
63
64 return dlFileRank;
65 }
66
67 public DLFileRank remove(long fileRankId)
68 throws NoSuchFileRankException, SystemException {
69 Session session = null;
70
71 try {
72 session = openSession();
73
74 DLFileRank dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
75 new Long(fileRankId));
76
77 if (dlFileRank == null) {
78 if (_log.isWarnEnabled()) {
79 _log.warn("No DLFileRank exists with the primary key " +
80 fileRankId);
81 }
82
83 throw new NoSuchFileRankException(
84 "No DLFileRank exists with the primary key " + fileRankId);
85 }
86
87 return remove(dlFileRank);
88 }
89 catch (NoSuchFileRankException nsee) {
90 throw nsee;
91 }
92 catch (Exception e) {
93 throw HibernateUtil.processException(e);
94 }
95 finally {
96 closeSession(session);
97 }
98 }
99
100 public DLFileRank remove(DLFileRank dlFileRank) throws SystemException {
101 Session session = null;
102
103 try {
104 session = openSession();
105 session.delete(dlFileRank);
106 session.flush();
107
108 return dlFileRank;
109 }
110 catch (Exception e) {
111 throw HibernateUtil.processException(e);
112 }
113 finally {
114 closeSession(session);
115 FinderCache.clearCache(DLFileRank.class.getName());
116 }
117 }
118
119 public DLFileRank update(
120 com.liferay.portlet.documentlibrary.model.DLFileRank dlFileRank)
121 throws SystemException {
122 return update(dlFileRank, false);
123 }
124
125 public DLFileRank update(
126 com.liferay.portlet.documentlibrary.model.DLFileRank dlFileRank,
127 boolean merge) throws SystemException {
128 Session session = null;
129
130 try {
131 session = openSession();
132
133 if (merge) {
134 session.merge(dlFileRank);
135 }
136 else {
137 if (dlFileRank.isNew()) {
138 session.save(dlFileRank);
139 }
140 }
141
142 session.flush();
143 dlFileRank.setNew(false);
144
145 return dlFileRank;
146 }
147 catch (Exception e) {
148 throw HibernateUtil.processException(e);
149 }
150 finally {
151 closeSession(session);
152 FinderCache.clearCache(DLFileRank.class.getName());
153 }
154 }
155
156 public DLFileRank findByPrimaryKey(long fileRankId)
157 throws NoSuchFileRankException, SystemException {
158 DLFileRank dlFileRank = fetchByPrimaryKey(fileRankId);
159
160 if (dlFileRank == null) {
161 if (_log.isWarnEnabled()) {
162 _log.warn("No DLFileRank exists with the primary key " +
163 fileRankId);
164 }
165
166 throw new NoSuchFileRankException(
167 "No DLFileRank exists with the primary key " + fileRankId);
168 }
169
170 return dlFileRank;
171 }
172
173 public DLFileRank fetchByPrimaryKey(long fileRankId)
174 throws SystemException {
175 Session session = null;
176
177 try {
178 session = openSession();
179
180 return (DLFileRank)session.get(DLFileRankImpl.class,
181 new Long(fileRankId));
182 }
183 catch (Exception e) {
184 throw HibernateUtil.processException(e);
185 }
186 finally {
187 closeSession(session);
188 }
189 }
190
191 public List findByUserId(long userId) throws SystemException {
192 String finderClassName = DLFileRank.class.getName();
193 String finderMethodName = "findByUserId";
194 String[] finderParams = new String[] { Long.class.getName() };
195 Object[] finderArgs = new Object[] { new Long(userId) };
196 Object result = FinderCache.getResult(finderClassName,
197 finderMethodName, finderParams, finderArgs, getSessionFactory());
198
199 if (result == null) {
200 Session session = null;
201
202 try {
203 session = openSession();
204
205 StringMaker query = new StringMaker();
206 query.append(
207 "FROM com.liferay.portlet.documentlibrary.model.DLFileRank WHERE ");
208 query.append("userId = ?");
209 query.append(" ");
210 query.append("ORDER BY ");
211 query.append("createDate DESC");
212
213 Query q = session.createQuery(query.toString());
214 int queryPos = 0;
215 q.setLong(queryPos++, userId);
216
217 List list = q.list();
218 FinderCache.putResult(finderClassName, finderMethodName,
219 finderParams, finderArgs, list);
220
221 return list;
222 }
223 catch (Exception e) {
224 throw HibernateUtil.processException(e);
225 }
226 finally {
227 closeSession(session);
228 }
229 }
230 else {
231 return (List)result;
232 }
233 }
234
235 public List findByUserId(long userId, int begin, int end)
236 throws SystemException {
237 return findByUserId(userId, begin, end, null);
238 }
239
240 public List findByUserId(long userId, int begin, int end,
241 OrderByComparator obc) throws SystemException {
242 String finderClassName = DLFileRank.class.getName();
243 String finderMethodName = "findByUserId";
244 String[] finderParams = new String[] {
245 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
246 "com.liferay.portal.kernel.util.OrderByComparator"
247 };
248 Object[] finderArgs = new Object[] {
249 new Long(userId), String.valueOf(begin), String.valueOf(end),
250 String.valueOf(obc)
251 };
252 Object result = FinderCache.getResult(finderClassName,
253 finderMethodName, finderParams, finderArgs, getSessionFactory());
254
255 if (result == null) {
256 Session session = null;
257
258 try {
259 session = openSession();
260
261 StringMaker query = new StringMaker();
262 query.append(
263 "FROM com.liferay.portlet.documentlibrary.model.DLFileRank WHERE ");
264 query.append("userId = ?");
265 query.append(" ");
266
267 if (obc != null) {
268 query.append("ORDER BY ");
269 query.append(obc.getOrderBy());
270 }
271 else {
272 query.append("ORDER BY ");
273 query.append("createDate DESC");
274 }
275
276 Query q = session.createQuery(query.toString());
277 int queryPos = 0;
278 q.setLong(queryPos++, userId);
279
280 List list = QueryUtil.list(q, getDialect(), begin, end);
281 FinderCache.putResult(finderClassName, finderMethodName,
282 finderParams, finderArgs, list);
283
284 return list;
285 }
286 catch (Exception e) {
287 throw HibernateUtil.processException(e);
288 }
289 finally {
290 closeSession(session);
291 }
292 }
293 else {
294 return (List)result;
295 }
296 }
297
298 public DLFileRank findByUserId_First(long userId, OrderByComparator obc)
299 throws NoSuchFileRankException, SystemException {
300 List list = findByUserId(userId, 0, 1, obc);
301
302 if (list.size() == 0) {
303 StringMaker msg = new StringMaker();
304 msg.append("No DLFileRank exists with the key ");
305 msg.append(StringPool.OPEN_CURLY_BRACE);
306 msg.append("userId=");
307 msg.append(userId);
308 msg.append(StringPool.CLOSE_CURLY_BRACE);
309 throw new NoSuchFileRankException(msg.toString());
310 }
311 else {
312 return (DLFileRank)list.get(0);
313 }
314 }
315
316 public DLFileRank findByUserId_Last(long userId, OrderByComparator obc)
317 throws NoSuchFileRankException, SystemException {
318 int count = countByUserId(userId);
319 List list = findByUserId(userId, count - 1, count, obc);
320
321 if (list.size() == 0) {
322 StringMaker msg = new StringMaker();
323 msg.append("No DLFileRank exists with the key ");
324 msg.append(StringPool.OPEN_CURLY_BRACE);
325 msg.append("userId=");
326 msg.append(userId);
327 msg.append(StringPool.CLOSE_CURLY_BRACE);
328 throw new NoSuchFileRankException(msg.toString());
329 }
330 else {
331 return (DLFileRank)list.get(0);
332 }
333 }
334
335 public DLFileRank[] findByUserId_PrevAndNext(long fileRankId, long userId,
336 OrderByComparator obc) throws NoSuchFileRankException, SystemException {
337 DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
338 int count = countByUserId(userId);
339 Session session = null;
340
341 try {
342 session = openSession();
343
344 StringMaker query = new StringMaker();
345 query.append(
346 "FROM com.liferay.portlet.documentlibrary.model.DLFileRank WHERE ");
347 query.append("userId = ?");
348 query.append(" ");
349
350 if (obc != null) {
351 query.append("ORDER BY ");
352 query.append(obc.getOrderBy());
353 }
354 else {
355 query.append("ORDER BY ");
356 query.append("createDate DESC");
357 }
358
359 Query q = session.createQuery(query.toString());
360 int queryPos = 0;
361 q.setLong(queryPos++, userId);
362
363 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
364 dlFileRank);
365 DLFileRank[] array = new DLFileRankImpl[3];
366 array[0] = (DLFileRank)objArray[0];
367 array[1] = (DLFileRank)objArray[1];
368 array[2] = (DLFileRank)objArray[2];
369
370 return array;
371 }
372 catch (Exception e) {
373 throw HibernateUtil.processException(e);
374 }
375 finally {
376 closeSession(session);
377 }
378 }
379
380 public List findByF_N(long folderId, String name) throws SystemException {
381 String finderClassName = DLFileRank.class.getName();
382 String finderMethodName = "findByF_N";
383 String[] finderParams = new String[] {
384 Long.class.getName(), String.class.getName()
385 };
386 Object[] finderArgs = new Object[] { new Long(folderId), name };
387 Object result = FinderCache.getResult(finderClassName,
388 finderMethodName, finderParams, finderArgs, getSessionFactory());
389
390 if (result == null) {
391 Session session = null;
392
393 try {
394 session = openSession();
395
396 StringMaker query = new StringMaker();
397 query.append(
398 "FROM com.liferay.portlet.documentlibrary.model.DLFileRank WHERE ");
399 query.append("folderId = ?");
400 query.append(" AND ");
401
402 if (name == null) {
403 query.append("name IS NULL");
404 }
405 else {
406 query.append("name = ?");
407 }
408
409 query.append(" ");
410 query.append("ORDER BY ");
411 query.append("createDate DESC");
412
413 Query q = session.createQuery(query.toString());
414 int queryPos = 0;
415 q.setLong(queryPos++, folderId);
416
417 if (name != null) {
418 q.setString(queryPos++, name);
419 }
420
421 List list = q.list();
422 FinderCache.putResult(finderClassName, finderMethodName,
423 finderParams, finderArgs, list);
424
425 return list;
426 }
427 catch (Exception e) {
428 throw HibernateUtil.processException(e);
429 }
430 finally {
431 closeSession(session);
432 }
433 }
434 else {
435 return (List)result;
436 }
437 }
438
439 public List findByF_N(long folderId, String name, int begin, int end)
440 throws SystemException {
441 return findByF_N(folderId, name, begin, end, null);
442 }
443
444 public List findByF_N(long folderId, String name, int begin, int end,
445 OrderByComparator obc) throws SystemException {
446 String finderClassName = DLFileRank.class.getName();
447 String finderMethodName = "findByF_N";
448 String[] finderParams = new String[] {
449 Long.class.getName(), String.class.getName(),
450 "java.lang.Integer", "java.lang.Integer",
451 "com.liferay.portal.kernel.util.OrderByComparator"
452 };
453 Object[] finderArgs = new Object[] {
454 new Long(folderId), name, String.valueOf(begin),
455 String.valueOf(end), String.valueOf(obc)
456 };
457 Object result = FinderCache.getResult(finderClassName,
458 finderMethodName, finderParams, finderArgs, getSessionFactory());
459
460 if (result == null) {
461 Session session = null;
462
463 try {
464 session = openSession();
465
466 StringMaker query = new StringMaker();
467 query.append(
468 "FROM com.liferay.portlet.documentlibrary.model.DLFileRank WHERE ");
469 query.append("folderId = ?");
470 query.append(" AND ");
471
472 if (name == null) {
473 query.append("name IS NULL");
474 }
475 else {
476 query.append("name = ?");
477 }
478
479 query.append(" ");
480
481 if (obc != null) {
482 query.append("ORDER BY ");
483 query.append(obc.getOrderBy());
484 }
485 else {
486 query.append("ORDER BY ");
487 query.append("createDate DESC");
488 }
489
490 Query q = session.createQuery(query.toString());
491 int queryPos = 0;
492 q.setLong(queryPos++, folderId);
493
494 if (name != null) {
495 q.setString(queryPos++, name);
496 }
497
498 List list = QueryUtil.list(q, getDialect(), begin, end);
499 FinderCache.putResult(finderClassName, finderMethodName,
500 finderParams, finderArgs, list);
501
502 return list;
503 }
504 catch (Exception e) {
505 throw HibernateUtil.processException(e);
506 }
507 finally {
508 closeSession(session);
509 }
510 }
511 else {
512 return (List)result;
513 }
514 }
515
516 public DLFileRank findByF_N_First(long folderId, String name,
517 OrderByComparator obc) throws NoSuchFileRankException, SystemException {
518 List list = findByF_N(folderId, name, 0, 1, obc);
519
520 if (list.size() == 0) {
521 StringMaker msg = new StringMaker();
522 msg.append("No DLFileRank exists with the key ");
523 msg.append(StringPool.OPEN_CURLY_BRACE);
524 msg.append("folderId=");
525 msg.append(folderId);
526 msg.append(", ");
527 msg.append("name=");
528 msg.append(name);
529 msg.append(StringPool.CLOSE_CURLY_BRACE);
530 throw new NoSuchFileRankException(msg.toString());
531 }
532 else {
533 return (DLFileRank)list.get(0);
534 }
535 }
536
537 public DLFileRank findByF_N_Last(long folderId, String name,
538 OrderByComparator obc) throws NoSuchFileRankException, SystemException {
539 int count = countByF_N(folderId, name);
540 List list = findByF_N(folderId, name, count - 1, count, obc);
541
542 if (list.size() == 0) {
543 StringMaker msg = new StringMaker();
544 msg.append("No DLFileRank exists with the key ");
545 msg.append(StringPool.OPEN_CURLY_BRACE);
546 msg.append("folderId=");
547 msg.append(folderId);
548 msg.append(", ");
549 msg.append("name=");
550 msg.append(name);
551 msg.append(StringPool.CLOSE_CURLY_BRACE);
552 throw new NoSuchFileRankException(msg.toString());
553 }
554 else {
555 return (DLFileRank)list.get(0);
556 }
557 }
558
559 public DLFileRank[] findByF_N_PrevAndNext(long fileRankId, long folderId,
560 String name, OrderByComparator obc)
561 throws NoSuchFileRankException, SystemException {
562 DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
563 int count = countByF_N(folderId, name);
564 Session session = null;
565
566 try {
567 session = openSession();
568
569 StringMaker query = new StringMaker();
570 query.append(
571 "FROM com.liferay.portlet.documentlibrary.model.DLFileRank WHERE ");
572 query.append("folderId = ?");
573 query.append(" AND ");
574
575 if (name == null) {
576 query.append("name IS NULL");
577 }
578 else {
579 query.append("name = ?");
580 }
581
582 query.append(" ");
583
584 if (obc != null) {
585 query.append("ORDER BY ");
586 query.append(obc.getOrderBy());
587 }
588 else {
589 query.append("ORDER BY ");
590 query.append("createDate DESC");
591 }
592
593 Query q = session.createQuery(query.toString());
594 int queryPos = 0;
595 q.setLong(queryPos++, folderId);
596
597 if (name != null) {
598 q.setString(queryPos++, name);
599 }
600
601 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
602 dlFileRank);
603 DLFileRank[] array = new DLFileRankImpl[3];
604 array[0] = (DLFileRank)objArray[0];
605 array[1] = (DLFileRank)objArray[1];
606 array[2] = (DLFileRank)objArray[2];
607
608 return array;
609 }
610 catch (Exception e) {
611 throw HibernateUtil.processException(e);
612 }
613 finally {
614 closeSession(session);
615 }
616 }
617
618 public DLFileRank findByC_U_F_N(long companyId, long userId, long folderId,
619 String name) throws NoSuchFileRankException, SystemException {
620 DLFileRank dlFileRank = fetchByC_U_F_N(companyId, userId, folderId, name);
621
622 if (dlFileRank == null) {
623 StringMaker msg = new StringMaker();
624 msg.append("No DLFileRank exists with the key ");
625 msg.append(StringPool.OPEN_CURLY_BRACE);
626 msg.append("companyId=");
627 msg.append(companyId);
628 msg.append(", ");
629 msg.append("userId=");
630 msg.append(userId);
631 msg.append(", ");
632 msg.append("folderId=");
633 msg.append(folderId);
634 msg.append(", ");
635 msg.append("name=");
636 msg.append(name);
637 msg.append(StringPool.CLOSE_CURLY_BRACE);
638
639 if (_log.isWarnEnabled()) {
640 _log.warn(msg.toString());
641 }
642
643 throw new NoSuchFileRankException(msg.toString());
644 }
645
646 return dlFileRank;
647 }
648
649 public DLFileRank fetchByC_U_F_N(long companyId, long userId,
650 long folderId, String name) throws SystemException {
651 String finderClassName = DLFileRank.class.getName();
652 String finderMethodName = "fetchByC_U_F_N";
653 String[] finderParams = new String[] {
654 Long.class.getName(), Long.class.getName(), Long.class.getName(),
655 String.class.getName()
656 };
657 Object[] finderArgs = new Object[] {
658 new Long(companyId), new Long(userId), new Long(folderId), name
659 };
660 Object result = FinderCache.getResult(finderClassName,
661 finderMethodName, finderParams, finderArgs, getSessionFactory());
662
663 if (result == null) {
664 Session session = null;
665
666 try {
667 session = openSession();
668
669 StringMaker query = new StringMaker();
670 query.append(
671 "FROM com.liferay.portlet.documentlibrary.model.DLFileRank WHERE ");
672 query.append("companyId = ?");
673 query.append(" AND ");
674 query.append("userId = ?");
675 query.append(" AND ");
676 query.append("folderId = ?");
677 query.append(" AND ");
678
679 if (name == null) {
680 query.append("name IS NULL");
681 }
682 else {
683 query.append("name = ?");
684 }
685
686 query.append(" ");
687 query.append("ORDER BY ");
688 query.append("createDate DESC");
689
690 Query q = session.createQuery(query.toString());
691 int queryPos = 0;
692 q.setLong(queryPos++, companyId);
693 q.setLong(queryPos++, userId);
694 q.setLong(queryPos++, folderId);
695
696 if (name != null) {
697 q.setString(queryPos++, name);
698 }
699
700 List list = q.list();
701 FinderCache.putResult(finderClassName, finderMethodName,
702 finderParams, finderArgs, list);
703
704 if (list.size() == 0) {
705 return null;
706 }
707 else {
708 return (DLFileRank)list.get(0);
709 }
710 }
711 catch (Exception e) {
712 throw HibernateUtil.processException(e);
713 }
714 finally {
715 closeSession(session);
716 }
717 }
718 else {
719 List list = (List)result;
720
721 if (list.size() == 0) {
722 return null;
723 }
724 else {
725 return (DLFileRank)list.get(0);
726 }
727 }
728 }
729
730 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
731 throws SystemException {
732 Session session = null;
733
734 try {
735 session = openSession();
736
737 DynamicQuery query = queryInitializer.initialize(session);
738
739 return query.list();
740 }
741 catch (Exception e) {
742 throw HibernateUtil.processException(e);
743 }
744 finally {
745 closeSession(session);
746 }
747 }
748
749 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
750 int begin, int end) throws SystemException {
751 Session session = null;
752
753 try {
754 session = openSession();
755
756 DynamicQuery query = queryInitializer.initialize(session);
757 query.setLimit(begin, end);
758
759 return query.list();
760 }
761 catch (Exception e) {
762 throw HibernateUtil.processException(e);
763 }
764 finally {
765 closeSession(session);
766 }
767 }
768
769 public List findAll() throws SystemException {
770 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
771 }
772
773 public List findAll(int begin, int end) throws SystemException {
774 return findAll(begin, end, null);
775 }
776
777 public List findAll(int begin, int end, OrderByComparator obc)
778 throws SystemException {
779 String finderClassName = DLFileRank.class.getName();
780 String finderMethodName = "findAll";
781 String[] finderParams = new String[] {
782 "java.lang.Integer", "java.lang.Integer",
783 "com.liferay.portal.kernel.util.OrderByComparator"
784 };
785 Object[] finderArgs = new Object[] {
786 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
787 };
788 Object result = FinderCache.getResult(finderClassName,
789 finderMethodName, finderParams, finderArgs, getSessionFactory());
790
791 if (result == null) {
792 Session session = null;
793
794 try {
795 session = openSession();
796
797 StringMaker query = new StringMaker();
798 query.append(
799 "FROM com.liferay.portlet.documentlibrary.model.DLFileRank ");
800
801 if (obc != null) {
802 query.append("ORDER BY ");
803 query.append(obc.getOrderBy());
804 }
805 else {
806 query.append("ORDER BY ");
807 query.append("createDate DESC");
808 }
809
810 Query q = session.createQuery(query.toString());
811 List list = QueryUtil.list(q, getDialect(), begin, end);
812
813 if (obc == null) {
814 Collections.sort(list);
815 }
816
817 FinderCache.putResult(finderClassName, finderMethodName,
818 finderParams, finderArgs, list);
819
820 return list;
821 }
822 catch (Exception e) {
823 throw HibernateUtil.processException(e);
824 }
825 finally {
826 closeSession(session);
827 }
828 }
829 else {
830 return (List)result;
831 }
832 }
833
834 public void removeByUserId(long userId) throws SystemException {
835 Iterator itr = findByUserId(userId).iterator();
836
837 while (itr.hasNext()) {
838 DLFileRank dlFileRank = (DLFileRank)itr.next();
839 remove(dlFileRank);
840 }
841 }
842
843 public void removeByF_N(long folderId, String name)
844 throws SystemException {
845 Iterator itr = findByF_N(folderId, name).iterator();
846
847 while (itr.hasNext()) {
848 DLFileRank dlFileRank = (DLFileRank)itr.next();
849 remove(dlFileRank);
850 }
851 }
852
853 public void removeByC_U_F_N(long companyId, long userId, long folderId,
854 String name) throws NoSuchFileRankException, SystemException {
855 DLFileRank dlFileRank = findByC_U_F_N(companyId, userId, folderId, name);
856 remove(dlFileRank);
857 }
858
859 public void removeAll() throws SystemException {
860 Iterator itr = findAll().iterator();
861
862 while (itr.hasNext()) {
863 remove((DLFileRank)itr.next());
864 }
865 }
866
867 public int countByUserId(long userId) throws SystemException {
868 String finderClassName = DLFileRank.class.getName();
869 String finderMethodName = "countByUserId";
870 String[] finderParams = new String[] { Long.class.getName() };
871 Object[] finderArgs = new Object[] { new Long(userId) };
872 Object result = FinderCache.getResult(finderClassName,
873 finderMethodName, finderParams, finderArgs, getSessionFactory());
874
875 if (result == null) {
876 Session session = null;
877
878 try {
879 session = openSession();
880
881 StringMaker query = new StringMaker();
882 query.append("SELECT COUNT(*) ");
883 query.append(
884 "FROM com.liferay.portlet.documentlibrary.model.DLFileRank WHERE ");
885 query.append("userId = ?");
886 query.append(" ");
887
888 Query q = session.createQuery(query.toString());
889 int queryPos = 0;
890 q.setLong(queryPos++, userId);
891
892 Long count = null;
893 Iterator itr = q.list().iterator();
894
895 if (itr.hasNext()) {
896 count = (Long)itr.next();
897 }
898
899 if (count == null) {
900 count = new Long(0);
901 }
902
903 FinderCache.putResult(finderClassName, finderMethodName,
904 finderParams, finderArgs, count);
905
906 return count.intValue();
907 }
908 catch (Exception e) {
909 throw HibernateUtil.processException(e);
910 }
911 finally {
912 closeSession(session);
913 }
914 }
915 else {
916 return ((Long)result).intValue();
917 }
918 }
919
920 public int countByF_N(long folderId, String name) throws SystemException {
921 String finderClassName = DLFileRank.class.getName();
922 String finderMethodName = "countByF_N";
923 String[] finderParams = new String[] {
924 Long.class.getName(), String.class.getName()
925 };
926 Object[] finderArgs = new Object[] { new Long(folderId), name };
927 Object result = FinderCache.getResult(finderClassName,
928 finderMethodName, finderParams, finderArgs, getSessionFactory());
929
930 if (result == null) {
931 Session session = null;
932
933 try {
934 session = openSession();
935
936 StringMaker query = new StringMaker();
937 query.append("SELECT COUNT(*) ");
938 query.append(
939 "FROM com.liferay.portlet.documentlibrary.model.DLFileRank WHERE ");
940 query.append("folderId = ?");
941 query.append(" AND ");
942
943 if (name == null) {
944 query.append("name IS NULL");
945 }
946 else {
947 query.append("name = ?");
948 }
949
950 query.append(" ");
951
952 Query q = session.createQuery(query.toString());
953 int queryPos = 0;
954 q.setLong(queryPos++, folderId);
955
956 if (name != null) {
957 q.setString(queryPos++, name);
958 }
959
960 Long count = null;
961 Iterator itr = q.list().iterator();
962
963 if (itr.hasNext()) {
964 count = (Long)itr.next();
965 }
966
967 if (count == null) {
968 count = new Long(0);
969 }
970
971 FinderCache.putResult(finderClassName, finderMethodName,
972 finderParams, finderArgs, count);
973
974 return count.intValue();
975 }
976 catch (Exception e) {
977 throw HibernateUtil.processException(e);
978 }
979 finally {
980 closeSession(session);
981 }
982 }
983 else {
984 return ((Long)result).intValue();
985 }
986 }
987
988 public int countByC_U_F_N(long companyId, long userId, long folderId,
989 String name) throws SystemException {
990 String finderClassName = DLFileRank.class.getName();
991 String finderMethodName = "countByC_U_F_N";
992 String[] finderParams = new String[] {
993 Long.class.getName(), Long.class.getName(), Long.class.getName(),
994 String.class.getName()
995 };
996 Object[] finderArgs = new Object[] {
997 new Long(companyId), new Long(userId), new Long(folderId), name
998 };
999 Object result = FinderCache.getResult(finderClassName,
1000 finderMethodName, finderParams, finderArgs, getSessionFactory());
1001
1002 if (result == null) {
1003 Session session = null;
1004
1005 try {
1006 session = openSession();
1007
1008 StringMaker query = new StringMaker();
1009 query.append("SELECT COUNT(*) ");
1010 query.append(
1011 "FROM com.liferay.portlet.documentlibrary.model.DLFileRank WHERE ");
1012 query.append("companyId = ?");
1013 query.append(" AND ");
1014 query.append("userId = ?");
1015 query.append(" AND ");
1016 query.append("folderId = ?");
1017 query.append(" AND ");
1018
1019 if (name == null) {
1020 query.append("name IS NULL");
1021 }
1022 else {
1023 query.append("name = ?");
1024 }
1025
1026 query.append(" ");
1027
1028 Query q = session.createQuery(query.toString());
1029 int queryPos = 0;
1030 q.setLong(queryPos++, companyId);
1031 q.setLong(queryPos++, userId);
1032 q.setLong(queryPos++, folderId);
1033
1034 if (name != null) {
1035 q.setString(queryPos++, name);
1036 }
1037
1038 Long count = null;
1039 Iterator itr = q.list().iterator();
1040
1041 if (itr.hasNext()) {
1042 count = (Long)itr.next();
1043 }
1044
1045 if (count == null) {
1046 count = new Long(0);
1047 }
1048
1049 FinderCache.putResult(finderClassName, finderMethodName,
1050 finderParams, finderArgs, count);
1051
1052 return count.intValue();
1053 }
1054 catch (Exception e) {
1055 throw HibernateUtil.processException(e);
1056 }
1057 finally {
1058 closeSession(session);
1059 }
1060 }
1061 else {
1062 return ((Long)result).intValue();
1063 }
1064 }
1065
1066 public int countAll() throws SystemException {
1067 String finderClassName = DLFileRank.class.getName();
1068 String finderMethodName = "countAll";
1069 String[] finderParams = new String[] { };
1070 Object[] finderArgs = new Object[] { };
1071 Object result = FinderCache.getResult(finderClassName,
1072 finderMethodName, finderParams, finderArgs, getSessionFactory());
1073
1074 if (result == null) {
1075 Session session = null;
1076
1077 try {
1078 session = openSession();
1079
1080 StringMaker query = new StringMaker();
1081 query.append("SELECT COUNT(*) ");
1082 query.append(
1083 "FROM com.liferay.portlet.documentlibrary.model.DLFileRank");
1084
1085 Query q = session.createQuery(query.toString());
1086 Long count = null;
1087 Iterator itr = q.list().iterator();
1088
1089 if (itr.hasNext()) {
1090 count = (Long)itr.next();
1091 }
1092
1093 if (count == null) {
1094 count = new Long(0);
1095 }
1096
1097 FinderCache.putResult(finderClassName, finderMethodName,
1098 finderParams, finderArgs, count);
1099
1100 return count.intValue();
1101 }
1102 catch (Exception e) {
1103 throw HibernateUtil.processException(e);
1104 }
1105 finally {
1106 closeSession(session);
1107 }
1108 }
1109 else {
1110 return ((Long)result).intValue();
1111 }
1112 }
1113
1114 protected void initDao() {
1115 }
1116
1117 private static Log _log = LogFactory.getLog(DLFileRankPersistenceImpl.class);
1118}