1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
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.NoSuchFileShortcutException;
36  import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
37  import com.liferay.portlet.documentlibrary.model.impl.DLFileShortcutImpl;
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  /**
52   * <a href="DLFileShortcutPersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   */
57  public class DLFileShortcutPersistenceImpl extends BasePersistence
58      implements DLFileShortcutPersistence {
59      public DLFileShortcut create(long fileShortcutId) {
60          DLFileShortcut dlFileShortcut = new DLFileShortcutImpl();
61          dlFileShortcut.setNew(true);
62          dlFileShortcut.setPrimaryKey(fileShortcutId);
63  
64          return dlFileShortcut;
65      }
66  
67      public DLFileShortcut remove(long fileShortcutId)
68          throws NoSuchFileShortcutException, SystemException {
69          Session session = null;
70  
71          try {
72              session = openSession();
73  
74              DLFileShortcut dlFileShortcut = (DLFileShortcut)session.get(DLFileShortcutImpl.class,
75                      new Long(fileShortcutId));
76  
77              if (dlFileShortcut == null) {
78                  if (_log.isWarnEnabled()) {
79                      _log.warn("No DLFileShortcut exists with the primary key " +
80                          fileShortcutId);
81                  }
82  
83                  throw new NoSuchFileShortcutException(
84                      "No DLFileShortcut exists with the primary key " +
85                      fileShortcutId);
86              }
87  
88              return remove(dlFileShortcut);
89          }
90          catch (NoSuchFileShortcutException nsee) {
91              throw nsee;
92          }
93          catch (Exception e) {
94              throw HibernateUtil.processException(e);
95          }
96          finally {
97              closeSession(session);
98          }
99      }
100 
101     public DLFileShortcut remove(DLFileShortcut dlFileShortcut)
102         throws SystemException {
103         Session session = null;
104 
105         try {
106             session = openSession();
107             session.delete(dlFileShortcut);
108             session.flush();
109 
110             return dlFileShortcut;
111         }
112         catch (Exception e) {
113             throw HibernateUtil.processException(e);
114         }
115         finally {
116             closeSession(session);
117             FinderCache.clearCache(DLFileShortcut.class.getName());
118         }
119     }
120 
121     public DLFileShortcut update(
122         com.liferay.portlet.documentlibrary.model.DLFileShortcut dlFileShortcut)
123         throws SystemException {
124         return update(dlFileShortcut, false);
125     }
126 
127     public DLFileShortcut update(
128         com.liferay.portlet.documentlibrary.model.DLFileShortcut dlFileShortcut,
129         boolean merge) throws SystemException {
130         Session session = null;
131 
132         try {
133             session = openSession();
134 
135             if (merge) {
136                 session.merge(dlFileShortcut);
137             }
138             else {
139                 if (dlFileShortcut.isNew()) {
140                     session.save(dlFileShortcut);
141                 }
142             }
143 
144             session.flush();
145             dlFileShortcut.setNew(false);
146 
147             return dlFileShortcut;
148         }
149         catch (Exception e) {
150             throw HibernateUtil.processException(e);
151         }
152         finally {
153             closeSession(session);
154             FinderCache.clearCache(DLFileShortcut.class.getName());
155         }
156     }
157 
158     public DLFileShortcut findByPrimaryKey(long fileShortcutId)
159         throws NoSuchFileShortcutException, SystemException {
160         DLFileShortcut dlFileShortcut = fetchByPrimaryKey(fileShortcutId);
161 
162         if (dlFileShortcut == null) {
163             if (_log.isWarnEnabled()) {
164                 _log.warn("No DLFileShortcut exists with the primary key " +
165                     fileShortcutId);
166             }
167 
168             throw new NoSuchFileShortcutException(
169                 "No DLFileShortcut exists with the primary key " +
170                 fileShortcutId);
171         }
172 
173         return dlFileShortcut;
174     }
175 
176     public DLFileShortcut fetchByPrimaryKey(long fileShortcutId)
177         throws SystemException {
178         Session session = null;
179 
180         try {
181             session = openSession();
182 
183             return (DLFileShortcut)session.get(DLFileShortcutImpl.class,
184                 new Long(fileShortcutId));
185         }
186         catch (Exception e) {
187             throw HibernateUtil.processException(e);
188         }
189         finally {
190             closeSession(session);
191         }
192     }
193 
194     public List findByFolderId(long folderId) throws SystemException {
195         String finderClassName = DLFileShortcut.class.getName();
196         String finderMethodName = "findByFolderId";
197         String[] finderParams = new String[] { Long.class.getName() };
198         Object[] finderArgs = new Object[] { new Long(folderId) };
199         Object result = FinderCache.getResult(finderClassName,
200                 finderMethodName, finderParams, finderArgs, getSessionFactory());
201 
202         if (result == null) {
203             Session session = null;
204 
205             try {
206                 session = openSession();
207 
208                 StringMaker query = new StringMaker();
209                 query.append(
210                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
211                 query.append("folderId = ?");
212                 query.append(" ");
213 
214                 Query q = session.createQuery(query.toString());
215                 int queryPos = 0;
216                 q.setLong(queryPos++, folderId);
217 
218                 List list = q.list();
219                 FinderCache.putResult(finderClassName, finderMethodName,
220                     finderParams, finderArgs, list);
221 
222                 return list;
223             }
224             catch (Exception e) {
225                 throw HibernateUtil.processException(e);
226             }
227             finally {
228                 closeSession(session);
229             }
230         }
231         else {
232             return (List)result;
233         }
234     }
235 
236     public List findByFolderId(long folderId, int begin, int end)
237         throws SystemException {
238         return findByFolderId(folderId, begin, end, null);
239     }
240 
241     public List findByFolderId(long folderId, int begin, int end,
242         OrderByComparator obc) throws SystemException {
243         String finderClassName = DLFileShortcut.class.getName();
244         String finderMethodName = "findByFolderId";
245         String[] finderParams = new String[] {
246                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
247                 "com.liferay.portal.kernel.util.OrderByComparator"
248             };
249         Object[] finderArgs = new Object[] {
250                 new Long(folderId), String.valueOf(begin), String.valueOf(end),
251                 String.valueOf(obc)
252             };
253         Object result = FinderCache.getResult(finderClassName,
254                 finderMethodName, finderParams, finderArgs, getSessionFactory());
255 
256         if (result == null) {
257             Session session = null;
258 
259             try {
260                 session = openSession();
261 
262                 StringMaker query = new StringMaker();
263                 query.append(
264                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
265                 query.append("folderId = ?");
266                 query.append(" ");
267 
268                 if (obc != null) {
269                     query.append("ORDER BY ");
270                     query.append(obc.getOrderBy());
271                 }
272 
273                 Query q = session.createQuery(query.toString());
274                 int queryPos = 0;
275                 q.setLong(queryPos++, folderId);
276 
277                 List list = QueryUtil.list(q, getDialect(), begin, end);
278                 FinderCache.putResult(finderClassName, finderMethodName,
279                     finderParams, finderArgs, list);
280 
281                 return list;
282             }
283             catch (Exception e) {
284                 throw HibernateUtil.processException(e);
285             }
286             finally {
287                 closeSession(session);
288             }
289         }
290         else {
291             return (List)result;
292         }
293     }
294 
295     public DLFileShortcut findByFolderId_First(long folderId,
296         OrderByComparator obc)
297         throws NoSuchFileShortcutException, SystemException {
298         List list = findByFolderId(folderId, 0, 1, obc);
299 
300         if (list.size() == 0) {
301             StringMaker msg = new StringMaker();
302             msg.append("No DLFileShortcut exists with the key ");
303             msg.append(StringPool.OPEN_CURLY_BRACE);
304             msg.append("folderId=");
305             msg.append(folderId);
306             msg.append(StringPool.CLOSE_CURLY_BRACE);
307             throw new NoSuchFileShortcutException(msg.toString());
308         }
309         else {
310             return (DLFileShortcut)list.get(0);
311         }
312     }
313 
314     public DLFileShortcut findByFolderId_Last(long folderId,
315         OrderByComparator obc)
316         throws NoSuchFileShortcutException, SystemException {
317         int count = countByFolderId(folderId);
318         List list = findByFolderId(folderId, count - 1, count, obc);
319 
320         if (list.size() == 0) {
321             StringMaker msg = new StringMaker();
322             msg.append("No DLFileShortcut exists with the key ");
323             msg.append(StringPool.OPEN_CURLY_BRACE);
324             msg.append("folderId=");
325             msg.append(folderId);
326             msg.append(StringPool.CLOSE_CURLY_BRACE);
327             throw new NoSuchFileShortcutException(msg.toString());
328         }
329         else {
330             return (DLFileShortcut)list.get(0);
331         }
332     }
333 
334     public DLFileShortcut[] findByFolderId_PrevAndNext(long fileShortcutId,
335         long folderId, OrderByComparator obc)
336         throws NoSuchFileShortcutException, SystemException {
337         DLFileShortcut dlFileShortcut = findByPrimaryKey(fileShortcutId);
338         int count = countByFolderId(folderId);
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.DLFileShortcut WHERE ");
347             query.append("folderId = ?");
348             query.append(" ");
349 
350             if (obc != null) {
351                 query.append("ORDER BY ");
352                 query.append(obc.getOrderBy());
353             }
354 
355             Query q = session.createQuery(query.toString());
356             int queryPos = 0;
357             q.setLong(queryPos++, folderId);
358 
359             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
360                     dlFileShortcut);
361             DLFileShortcut[] array = new DLFileShortcutImpl[3];
362             array[0] = (DLFileShortcut)objArray[0];
363             array[1] = (DLFileShortcut)objArray[1];
364             array[2] = (DLFileShortcut)objArray[2];
365 
366             return array;
367         }
368         catch (Exception e) {
369             throw HibernateUtil.processException(e);
370         }
371         finally {
372             closeSession(session);
373         }
374     }
375 
376     public List findByTF_TN(long toFolderId, String toName)
377         throws SystemException {
378         String finderClassName = DLFileShortcut.class.getName();
379         String finderMethodName = "findByTF_TN";
380         String[] finderParams = new String[] {
381                 Long.class.getName(), String.class.getName()
382             };
383         Object[] finderArgs = new Object[] { new Long(toFolderId), toName };
384         Object result = FinderCache.getResult(finderClassName,
385                 finderMethodName, finderParams, finderArgs, getSessionFactory());
386 
387         if (result == null) {
388             Session session = null;
389 
390             try {
391                 session = openSession();
392 
393                 StringMaker query = new StringMaker();
394                 query.append(
395                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
396                 query.append("toFolderId = ?");
397                 query.append(" AND ");
398 
399                 if (toName == null) {
400                     query.append("toName IS NULL");
401                 }
402                 else {
403                     query.append("toName = ?");
404                 }
405 
406                 query.append(" ");
407 
408                 Query q = session.createQuery(query.toString());
409                 int queryPos = 0;
410                 q.setLong(queryPos++, toFolderId);
411 
412                 if (toName != null) {
413                     q.setString(queryPos++, toName);
414                 }
415 
416                 List list = q.list();
417                 FinderCache.putResult(finderClassName, finderMethodName,
418                     finderParams, finderArgs, list);
419 
420                 return list;
421             }
422             catch (Exception e) {
423                 throw HibernateUtil.processException(e);
424             }
425             finally {
426                 closeSession(session);
427             }
428         }
429         else {
430             return (List)result;
431         }
432     }
433 
434     public List findByTF_TN(long toFolderId, String toName, int begin, int end)
435         throws SystemException {
436         return findByTF_TN(toFolderId, toName, begin, end, null);
437     }
438 
439     public List findByTF_TN(long toFolderId, String toName, int begin, int end,
440         OrderByComparator obc) throws SystemException {
441         String finderClassName = DLFileShortcut.class.getName();
442         String finderMethodName = "findByTF_TN";
443         String[] finderParams = new String[] {
444                 Long.class.getName(), String.class.getName(),
445                 "java.lang.Integer", "java.lang.Integer",
446                 "com.liferay.portal.kernel.util.OrderByComparator"
447             };
448         Object[] finderArgs = new Object[] {
449                 new Long(toFolderId), toName, String.valueOf(begin),
450                 String.valueOf(end), String.valueOf(obc)
451             };
452         Object result = FinderCache.getResult(finderClassName,
453                 finderMethodName, finderParams, finderArgs, getSessionFactory());
454 
455         if (result == null) {
456             Session session = null;
457 
458             try {
459                 session = openSession();
460 
461                 StringMaker query = new StringMaker();
462                 query.append(
463                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
464                 query.append("toFolderId = ?");
465                 query.append(" AND ");
466 
467                 if (toName == null) {
468                     query.append("toName IS NULL");
469                 }
470                 else {
471                     query.append("toName = ?");
472                 }
473 
474                 query.append(" ");
475 
476                 if (obc != null) {
477                     query.append("ORDER BY ");
478                     query.append(obc.getOrderBy());
479                 }
480 
481                 Query q = session.createQuery(query.toString());
482                 int queryPos = 0;
483                 q.setLong(queryPos++, toFolderId);
484 
485                 if (toName != null) {
486                     q.setString(queryPos++, toName);
487                 }
488 
489                 List list = QueryUtil.list(q, getDialect(), begin, end);
490                 FinderCache.putResult(finderClassName, finderMethodName,
491                     finderParams, finderArgs, list);
492 
493                 return list;
494             }
495             catch (Exception e) {
496                 throw HibernateUtil.processException(e);
497             }
498             finally {
499                 closeSession(session);
500             }
501         }
502         else {
503             return (List)result;
504         }
505     }
506 
507     public DLFileShortcut findByTF_TN_First(long toFolderId, String toName,
508         OrderByComparator obc)
509         throws NoSuchFileShortcutException, SystemException {
510         List list = findByTF_TN(toFolderId, toName, 0, 1, obc);
511 
512         if (list.size() == 0) {
513             StringMaker msg = new StringMaker();
514             msg.append("No DLFileShortcut exists with the key ");
515             msg.append(StringPool.OPEN_CURLY_BRACE);
516             msg.append("toFolderId=");
517             msg.append(toFolderId);
518             msg.append(", ");
519             msg.append("toName=");
520             msg.append(toName);
521             msg.append(StringPool.CLOSE_CURLY_BRACE);
522             throw new NoSuchFileShortcutException(msg.toString());
523         }
524         else {
525             return (DLFileShortcut)list.get(0);
526         }
527     }
528 
529     public DLFileShortcut findByTF_TN_Last(long toFolderId, String toName,
530         OrderByComparator obc)
531         throws NoSuchFileShortcutException, SystemException {
532         int count = countByTF_TN(toFolderId, toName);
533         List list = findByTF_TN(toFolderId, toName, count - 1, count, obc);
534 
535         if (list.size() == 0) {
536             StringMaker msg = new StringMaker();
537             msg.append("No DLFileShortcut exists with the key ");
538             msg.append(StringPool.OPEN_CURLY_BRACE);
539             msg.append("toFolderId=");
540             msg.append(toFolderId);
541             msg.append(", ");
542             msg.append("toName=");
543             msg.append(toName);
544             msg.append(StringPool.CLOSE_CURLY_BRACE);
545             throw new NoSuchFileShortcutException(msg.toString());
546         }
547         else {
548             return (DLFileShortcut)list.get(0);
549         }
550     }
551 
552     public DLFileShortcut[] findByTF_TN_PrevAndNext(long fileShortcutId,
553         long toFolderId, String toName, OrderByComparator obc)
554         throws NoSuchFileShortcutException, SystemException {
555         DLFileShortcut dlFileShortcut = findByPrimaryKey(fileShortcutId);
556         int count = countByTF_TN(toFolderId, toName);
557         Session session = null;
558 
559         try {
560             session = openSession();
561 
562             StringMaker query = new StringMaker();
563             query.append(
564                 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
565             query.append("toFolderId = ?");
566             query.append(" AND ");
567 
568             if (toName == null) {
569                 query.append("toName IS NULL");
570             }
571             else {
572                 query.append("toName = ?");
573             }
574 
575             query.append(" ");
576 
577             if (obc != null) {
578                 query.append("ORDER BY ");
579                 query.append(obc.getOrderBy());
580             }
581 
582             Query q = session.createQuery(query.toString());
583             int queryPos = 0;
584             q.setLong(queryPos++, toFolderId);
585 
586             if (toName != null) {
587                 q.setString(queryPos++, toName);
588             }
589 
590             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
591                     dlFileShortcut);
592             DLFileShortcut[] array = new DLFileShortcutImpl[3];
593             array[0] = (DLFileShortcut)objArray[0];
594             array[1] = (DLFileShortcut)objArray[1];
595             array[2] = (DLFileShortcut)objArray[2];
596 
597             return array;
598         }
599         catch (Exception e) {
600             throw HibernateUtil.processException(e);
601         }
602         finally {
603             closeSession(session);
604         }
605     }
606 
607     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
608         throws SystemException {
609         Session session = null;
610 
611         try {
612             session = openSession();
613 
614             DynamicQuery query = queryInitializer.initialize(session);
615 
616             return query.list();
617         }
618         catch (Exception e) {
619             throw HibernateUtil.processException(e);
620         }
621         finally {
622             closeSession(session);
623         }
624     }
625 
626     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
627         int begin, int end) throws SystemException {
628         Session session = null;
629 
630         try {
631             session = openSession();
632 
633             DynamicQuery query = queryInitializer.initialize(session);
634             query.setLimit(begin, end);
635 
636             return query.list();
637         }
638         catch (Exception e) {
639             throw HibernateUtil.processException(e);
640         }
641         finally {
642             closeSession(session);
643         }
644     }
645 
646     public List findAll() throws SystemException {
647         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
648     }
649 
650     public List findAll(int begin, int end) throws SystemException {
651         return findAll(begin, end, null);
652     }
653 
654     public List findAll(int begin, int end, OrderByComparator obc)
655         throws SystemException {
656         String finderClassName = DLFileShortcut.class.getName();
657         String finderMethodName = "findAll";
658         String[] finderParams = new String[] {
659                 "java.lang.Integer", "java.lang.Integer",
660                 "com.liferay.portal.kernel.util.OrderByComparator"
661             };
662         Object[] finderArgs = new Object[] {
663                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
664             };
665         Object result = FinderCache.getResult(finderClassName,
666                 finderMethodName, finderParams, finderArgs, getSessionFactory());
667 
668         if (result == null) {
669             Session session = null;
670 
671             try {
672                 session = openSession();
673 
674                 StringMaker query = new StringMaker();
675                 query.append(
676                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut ");
677 
678                 if (obc != null) {
679                     query.append("ORDER BY ");
680                     query.append(obc.getOrderBy());
681                 }
682 
683                 Query q = session.createQuery(query.toString());
684                 List list = QueryUtil.list(q, getDialect(), begin, end);
685 
686                 if (obc == null) {
687                     Collections.sort(list);
688                 }
689 
690                 FinderCache.putResult(finderClassName, finderMethodName,
691                     finderParams, finderArgs, list);
692 
693                 return list;
694             }
695             catch (Exception e) {
696                 throw HibernateUtil.processException(e);
697             }
698             finally {
699                 closeSession(session);
700             }
701         }
702         else {
703             return (List)result;
704         }
705     }
706 
707     public void removeByFolderId(long folderId) throws SystemException {
708         Iterator itr = findByFolderId(folderId).iterator();
709 
710         while (itr.hasNext()) {
711             DLFileShortcut dlFileShortcut = (DLFileShortcut)itr.next();
712             remove(dlFileShortcut);
713         }
714     }
715 
716     public void removeByTF_TN(long toFolderId, String toName)
717         throws SystemException {
718         Iterator itr = findByTF_TN(toFolderId, toName).iterator();
719 
720         while (itr.hasNext()) {
721             DLFileShortcut dlFileShortcut = (DLFileShortcut)itr.next();
722             remove(dlFileShortcut);
723         }
724     }
725 
726     public void removeAll() throws SystemException {
727         Iterator itr = findAll().iterator();
728 
729         while (itr.hasNext()) {
730             remove((DLFileShortcut)itr.next());
731         }
732     }
733 
734     public int countByFolderId(long folderId) throws SystemException {
735         String finderClassName = DLFileShortcut.class.getName();
736         String finderMethodName = "countByFolderId";
737         String[] finderParams = new String[] { Long.class.getName() };
738         Object[] finderArgs = new Object[] { new Long(folderId) };
739         Object result = FinderCache.getResult(finderClassName,
740                 finderMethodName, finderParams, finderArgs, getSessionFactory());
741 
742         if (result == null) {
743             Session session = null;
744 
745             try {
746                 session = openSession();
747 
748                 StringMaker query = new StringMaker();
749                 query.append("SELECT COUNT(*) ");
750                 query.append(
751                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
752                 query.append("folderId = ?");
753                 query.append(" ");
754 
755                 Query q = session.createQuery(query.toString());
756                 int queryPos = 0;
757                 q.setLong(queryPos++, folderId);
758 
759                 Long count = null;
760                 Iterator itr = q.list().iterator();
761 
762                 if (itr.hasNext()) {
763                     count = (Long)itr.next();
764                 }
765 
766                 if (count == null) {
767                     count = new Long(0);
768                 }
769 
770                 FinderCache.putResult(finderClassName, finderMethodName,
771                     finderParams, finderArgs, count);
772 
773                 return count.intValue();
774             }
775             catch (Exception e) {
776                 throw HibernateUtil.processException(e);
777             }
778             finally {
779                 closeSession(session);
780             }
781         }
782         else {
783             return ((Long)result).intValue();
784         }
785     }
786 
787     public int countByTF_TN(long toFolderId, String toName)
788         throws SystemException {
789         String finderClassName = DLFileShortcut.class.getName();
790         String finderMethodName = "countByTF_TN";
791         String[] finderParams = new String[] {
792                 Long.class.getName(), String.class.getName()
793             };
794         Object[] finderArgs = new Object[] { new Long(toFolderId), toName };
795         Object result = FinderCache.getResult(finderClassName,
796                 finderMethodName, finderParams, finderArgs, getSessionFactory());
797 
798         if (result == null) {
799             Session session = null;
800 
801             try {
802                 session = openSession();
803 
804                 StringMaker query = new StringMaker();
805                 query.append("SELECT COUNT(*) ");
806                 query.append(
807                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
808                 query.append("toFolderId = ?");
809                 query.append(" AND ");
810 
811                 if (toName == null) {
812                     query.append("toName IS NULL");
813                 }
814                 else {
815                     query.append("toName = ?");
816                 }
817 
818                 query.append(" ");
819 
820                 Query q = session.createQuery(query.toString());
821                 int queryPos = 0;
822                 q.setLong(queryPos++, toFolderId);
823 
824                 if (toName != null) {
825                     q.setString(queryPos++, toName);
826                 }
827 
828                 Long count = null;
829                 Iterator itr = q.list().iterator();
830 
831                 if (itr.hasNext()) {
832                     count = (Long)itr.next();
833                 }
834 
835                 if (count == null) {
836                     count = new Long(0);
837                 }
838 
839                 FinderCache.putResult(finderClassName, finderMethodName,
840                     finderParams, finderArgs, count);
841 
842                 return count.intValue();
843             }
844             catch (Exception e) {
845                 throw HibernateUtil.processException(e);
846             }
847             finally {
848                 closeSession(session);
849             }
850         }
851         else {
852             return ((Long)result).intValue();
853         }
854     }
855 
856     public int countAll() throws SystemException {
857         String finderClassName = DLFileShortcut.class.getName();
858         String finderMethodName = "countAll";
859         String[] finderParams = new String[] {  };
860         Object[] finderArgs = new Object[] {  };
861         Object result = FinderCache.getResult(finderClassName,
862                 finderMethodName, finderParams, finderArgs, getSessionFactory());
863 
864         if (result == null) {
865             Session session = null;
866 
867             try {
868                 session = openSession();
869 
870                 StringMaker query = new StringMaker();
871                 query.append("SELECT COUNT(*) ");
872                 query.append(
873                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut");
874 
875                 Query q = session.createQuery(query.toString());
876                 Long count = null;
877                 Iterator itr = q.list().iterator();
878 
879                 if (itr.hasNext()) {
880                     count = (Long)itr.next();
881                 }
882 
883                 if (count == null) {
884                     count = new Long(0);
885                 }
886 
887                 FinderCache.putResult(finderClassName, finderMethodName,
888                     finderParams, finderArgs, count);
889 
890                 return count.intValue();
891             }
892             catch (Exception e) {
893                 throw HibernateUtil.processException(e);
894             }
895             finally {
896                 closeSession(session);
897             }
898         }
899         else {
900             return ((Long)result).intValue();
901         }
902     }
903 
904     protected void initDao() {
905     }
906 
907     private static Log _log = LogFactory.getLog(DLFileShortcutPersistenceImpl.class);
908 }