1   /**
2    * Copyright (c) 2000-2008 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.GetterUtil;
29  import com.liferay.portal.kernel.util.OrderByComparator;
30  import com.liferay.portal.kernel.util.StringMaker;
31  import com.liferay.portal.kernel.util.StringPool;
32  import com.liferay.portal.kernel.util.Validator;
33  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
34  import com.liferay.portal.model.ModelListener;
35  import com.liferay.portal.service.persistence.BasePersistence;
36  import com.liferay.portal.spring.hibernate.FinderCache;
37  import com.liferay.portal.spring.hibernate.HibernateUtil;
38  import com.liferay.portal.util.PropsUtil;
39  
40  import com.liferay.portlet.documentlibrary.NoSuchFileShortcutException;
41  import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
42  import com.liferay.portlet.documentlibrary.model.impl.DLFileShortcutImpl;
43  import com.liferay.portlet.documentlibrary.model.impl.DLFileShortcutModelImpl;
44  
45  import com.liferay.util.dao.hibernate.QueryUtil;
46  
47  import org.apache.commons.logging.Log;
48  import org.apache.commons.logging.LogFactory;
49  
50  import org.hibernate.Query;
51  import org.hibernate.Session;
52  
53  import java.util.Collections;
54  import java.util.Iterator;
55  import java.util.List;
56  
57  /**
58   * <a href="DLFileShortcutPersistenceImpl.java.html"><b><i>View Source</i></b></a>
59   *
60   * @author Brian Wing Shun Chan
61   *
62   */
63  public class DLFileShortcutPersistenceImpl extends BasePersistence
64      implements DLFileShortcutPersistence {
65      public DLFileShortcut create(long fileShortcutId) {
66          DLFileShortcut dlFileShortcut = new DLFileShortcutImpl();
67  
68          dlFileShortcut.setNew(true);
69          dlFileShortcut.setPrimaryKey(fileShortcutId);
70  
71          String uuid = PortalUUIDUtil.generate();
72  
73          dlFileShortcut.setUuid(uuid);
74  
75          return dlFileShortcut;
76      }
77  
78      public DLFileShortcut remove(long fileShortcutId)
79          throws NoSuchFileShortcutException, SystemException {
80          Session session = null;
81  
82          try {
83              session = openSession();
84  
85              DLFileShortcut dlFileShortcut = (DLFileShortcut)session.get(DLFileShortcutImpl.class,
86                      new Long(fileShortcutId));
87  
88              if (dlFileShortcut == null) {
89                  if (_log.isWarnEnabled()) {
90                      _log.warn("No DLFileShortcut exists with the primary key " +
91                          fileShortcutId);
92                  }
93  
94                  throw new NoSuchFileShortcutException(
95                      "No DLFileShortcut exists with the primary key " +
96                      fileShortcutId);
97              }
98  
99              return remove(dlFileShortcut);
100         }
101         catch (NoSuchFileShortcutException nsee) {
102             throw nsee;
103         }
104         catch (Exception e) {
105             throw HibernateUtil.processException(e);
106         }
107         finally {
108             closeSession(session);
109         }
110     }
111 
112     public DLFileShortcut remove(DLFileShortcut dlFileShortcut)
113         throws SystemException {
114         ModelListener listener = _getListener();
115 
116         if (listener != null) {
117             listener.onBeforeRemove(dlFileShortcut);
118         }
119 
120         dlFileShortcut = removeImpl(dlFileShortcut);
121 
122         if (listener != null) {
123             listener.onAfterRemove(dlFileShortcut);
124         }
125 
126         return dlFileShortcut;
127     }
128 
129     protected DLFileShortcut removeImpl(DLFileShortcut dlFileShortcut)
130         throws SystemException {
131         Session session = null;
132 
133         try {
134             session = openSession();
135 
136             session.delete(dlFileShortcut);
137 
138             session.flush();
139 
140             return dlFileShortcut;
141         }
142         catch (Exception e) {
143             throw HibernateUtil.processException(e);
144         }
145         finally {
146             closeSession(session);
147 
148             FinderCache.clearCache(DLFileShortcut.class.getName());
149         }
150     }
151 
152     public DLFileShortcut update(DLFileShortcut dlFileShortcut)
153         throws SystemException {
154         return update(dlFileShortcut, false);
155     }
156 
157     public DLFileShortcut update(DLFileShortcut dlFileShortcut, boolean merge)
158         throws SystemException {
159         ModelListener listener = _getListener();
160 
161         boolean isNew = dlFileShortcut.isNew();
162 
163         if (listener != null) {
164             if (isNew) {
165                 listener.onBeforeCreate(dlFileShortcut);
166             }
167             else {
168                 listener.onBeforeUpdate(dlFileShortcut);
169             }
170         }
171 
172         dlFileShortcut = updateImpl(dlFileShortcut, merge);
173 
174         if (listener != null) {
175             if (isNew) {
176                 listener.onAfterCreate(dlFileShortcut);
177             }
178             else {
179                 listener.onAfterUpdate(dlFileShortcut);
180             }
181         }
182 
183         return dlFileShortcut;
184     }
185 
186     public DLFileShortcut updateImpl(
187         com.liferay.portlet.documentlibrary.model.DLFileShortcut dlFileShortcut,
188         boolean merge) throws SystemException {
189         if (Validator.isNull(dlFileShortcut.getUuid())) {
190             String uuid = PortalUUIDUtil.generate();
191 
192             dlFileShortcut.setUuid(uuid);
193         }
194 
195         Session session = null;
196 
197         try {
198             session = openSession();
199 
200             if (merge) {
201                 session.merge(dlFileShortcut);
202             }
203             else {
204                 if (dlFileShortcut.isNew()) {
205                     session.save(dlFileShortcut);
206                 }
207             }
208 
209             session.flush();
210 
211             dlFileShortcut.setNew(false);
212 
213             return dlFileShortcut;
214         }
215         catch (Exception e) {
216             throw HibernateUtil.processException(e);
217         }
218         finally {
219             closeSession(session);
220 
221             FinderCache.clearCache(DLFileShortcut.class.getName());
222         }
223     }
224 
225     public DLFileShortcut findByPrimaryKey(long fileShortcutId)
226         throws NoSuchFileShortcutException, SystemException {
227         DLFileShortcut dlFileShortcut = fetchByPrimaryKey(fileShortcutId);
228 
229         if (dlFileShortcut == null) {
230             if (_log.isWarnEnabled()) {
231                 _log.warn("No DLFileShortcut exists with the primary key " +
232                     fileShortcutId);
233             }
234 
235             throw new NoSuchFileShortcutException(
236                 "No DLFileShortcut exists with the primary key " +
237                 fileShortcutId);
238         }
239 
240         return dlFileShortcut;
241     }
242 
243     public DLFileShortcut fetchByPrimaryKey(long fileShortcutId)
244         throws SystemException {
245         Session session = null;
246 
247         try {
248             session = openSession();
249 
250             return (DLFileShortcut)session.get(DLFileShortcutImpl.class,
251                 new Long(fileShortcutId));
252         }
253         catch (Exception e) {
254             throw HibernateUtil.processException(e);
255         }
256         finally {
257             closeSession(session);
258         }
259     }
260 
261     public List findByUuid(String uuid) throws SystemException {
262         boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
263         String finderClassName = DLFileShortcut.class.getName();
264         String finderMethodName = "findByUuid";
265         String[] finderParams = new String[] { String.class.getName() };
266         Object[] finderArgs = new Object[] { uuid };
267 
268         Object result = null;
269 
270         if (finderClassNameCacheEnabled) {
271             result = FinderCache.getResult(finderClassName, finderMethodName,
272                     finderParams, finderArgs, getSessionFactory());
273         }
274 
275         if (result == null) {
276             Session session = null;
277 
278             try {
279                 session = openSession();
280 
281                 StringMaker query = new StringMaker();
282 
283                 query.append(
284                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
285 
286                 if (uuid == null) {
287                     query.append("uuid_ IS NULL");
288                 }
289                 else {
290                     query.append("uuid_ = ?");
291                 }
292 
293                 query.append(" ");
294 
295                 Query q = session.createQuery(query.toString());
296 
297                 int queryPos = 0;
298 
299                 if (uuid != null) {
300                     q.setString(queryPos++, uuid);
301                 }
302 
303                 List list = q.list();
304 
305                 FinderCache.putResult(finderClassNameCacheEnabled,
306                     finderClassName, finderMethodName, finderParams,
307                     finderArgs, list);
308 
309                 return list;
310             }
311             catch (Exception e) {
312                 throw HibernateUtil.processException(e);
313             }
314             finally {
315                 closeSession(session);
316             }
317         }
318         else {
319             return (List)result;
320         }
321     }
322 
323     public List findByUuid(String uuid, int begin, int end)
324         throws SystemException {
325         return findByUuid(uuid, begin, end, null);
326     }
327 
328     public List findByUuid(String uuid, int begin, int end,
329         OrderByComparator obc) throws SystemException {
330         boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
331         String finderClassName = DLFileShortcut.class.getName();
332         String finderMethodName = "findByUuid";
333         String[] finderParams = new String[] {
334                 String.class.getName(),
335                 
336                 "java.lang.Integer", "java.lang.Integer",
337                 "com.liferay.portal.kernel.util.OrderByComparator"
338             };
339         Object[] finderArgs = new Object[] {
340                 uuid,
341                 
342                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
343             };
344 
345         Object result = null;
346 
347         if (finderClassNameCacheEnabled) {
348             result = FinderCache.getResult(finderClassName, finderMethodName,
349                     finderParams, finderArgs, getSessionFactory());
350         }
351 
352         if (result == null) {
353             Session session = null;
354 
355             try {
356                 session = openSession();
357 
358                 StringMaker query = new StringMaker();
359 
360                 query.append(
361                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
362 
363                 if (uuid == null) {
364                     query.append("uuid_ IS NULL");
365                 }
366                 else {
367                     query.append("uuid_ = ?");
368                 }
369 
370                 query.append(" ");
371 
372                 if (obc != null) {
373                     query.append("ORDER BY ");
374                     query.append(obc.getOrderBy());
375                 }
376 
377                 Query q = session.createQuery(query.toString());
378 
379                 int queryPos = 0;
380 
381                 if (uuid != null) {
382                     q.setString(queryPos++, uuid);
383                 }
384 
385                 List list = QueryUtil.list(q, getDialect(), begin, end);
386 
387                 FinderCache.putResult(finderClassNameCacheEnabled,
388                     finderClassName, finderMethodName, finderParams,
389                     finderArgs, list);
390 
391                 return list;
392             }
393             catch (Exception e) {
394                 throw HibernateUtil.processException(e);
395             }
396             finally {
397                 closeSession(session);
398             }
399         }
400         else {
401             return (List)result;
402         }
403     }
404 
405     public DLFileShortcut findByUuid_First(String uuid, OrderByComparator obc)
406         throws NoSuchFileShortcutException, SystemException {
407         List list = findByUuid(uuid, 0, 1, obc);
408 
409         if (list.size() == 0) {
410             StringMaker msg = new StringMaker();
411 
412             msg.append("No DLFileShortcut exists with the key {");
413 
414             msg.append("uuid=" + uuid);
415 
416             msg.append(StringPool.CLOSE_CURLY_BRACE);
417 
418             throw new NoSuchFileShortcutException(msg.toString());
419         }
420         else {
421             return (DLFileShortcut)list.get(0);
422         }
423     }
424 
425     public DLFileShortcut findByUuid_Last(String uuid, OrderByComparator obc)
426         throws NoSuchFileShortcutException, SystemException {
427         int count = countByUuid(uuid);
428 
429         List list = findByUuid(uuid, count - 1, count, obc);
430 
431         if (list.size() == 0) {
432             StringMaker msg = new StringMaker();
433 
434             msg.append("No DLFileShortcut exists with the key {");
435 
436             msg.append("uuid=" + uuid);
437 
438             msg.append(StringPool.CLOSE_CURLY_BRACE);
439 
440             throw new NoSuchFileShortcutException(msg.toString());
441         }
442         else {
443             return (DLFileShortcut)list.get(0);
444         }
445     }
446 
447     public DLFileShortcut[] findByUuid_PrevAndNext(long fileShortcutId,
448         String uuid, OrderByComparator obc)
449         throws NoSuchFileShortcutException, SystemException {
450         DLFileShortcut dlFileShortcut = findByPrimaryKey(fileShortcutId);
451 
452         int count = countByUuid(uuid);
453 
454         Session session = null;
455 
456         try {
457             session = openSession();
458 
459             StringMaker query = new StringMaker();
460 
461             query.append(
462                 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
463 
464             if (uuid == null) {
465                 query.append("uuid_ IS NULL");
466             }
467             else {
468                 query.append("uuid_ = ?");
469             }
470 
471             query.append(" ");
472 
473             if (obc != null) {
474                 query.append("ORDER BY ");
475                 query.append(obc.getOrderBy());
476             }
477 
478             Query q = session.createQuery(query.toString());
479 
480             int queryPos = 0;
481 
482             if (uuid != null) {
483                 q.setString(queryPos++, uuid);
484             }
485 
486             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
487                     dlFileShortcut);
488 
489             DLFileShortcut[] array = new DLFileShortcutImpl[3];
490 
491             array[0] = (DLFileShortcut)objArray[0];
492             array[1] = (DLFileShortcut)objArray[1];
493             array[2] = (DLFileShortcut)objArray[2];
494 
495             return array;
496         }
497         catch (Exception e) {
498             throw HibernateUtil.processException(e);
499         }
500         finally {
501             closeSession(session);
502         }
503     }
504 
505     public List findByFolderId(long folderId) throws SystemException {
506         boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
507         String finderClassName = DLFileShortcut.class.getName();
508         String finderMethodName = "findByFolderId";
509         String[] finderParams = new String[] { Long.class.getName() };
510         Object[] finderArgs = new Object[] { new Long(folderId) };
511 
512         Object result = null;
513 
514         if (finderClassNameCacheEnabled) {
515             result = FinderCache.getResult(finderClassName, finderMethodName,
516                     finderParams, finderArgs, getSessionFactory());
517         }
518 
519         if (result == null) {
520             Session session = null;
521 
522             try {
523                 session = openSession();
524 
525                 StringMaker query = new StringMaker();
526 
527                 query.append(
528                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
529 
530                 query.append("folderId = ?");
531 
532                 query.append(" ");
533 
534                 Query q = session.createQuery(query.toString());
535 
536                 int queryPos = 0;
537 
538                 q.setLong(queryPos++, folderId);
539 
540                 List list = q.list();
541 
542                 FinderCache.putResult(finderClassNameCacheEnabled,
543                     finderClassName, finderMethodName, finderParams,
544                     finderArgs, list);
545 
546                 return list;
547             }
548             catch (Exception e) {
549                 throw HibernateUtil.processException(e);
550             }
551             finally {
552                 closeSession(session);
553             }
554         }
555         else {
556             return (List)result;
557         }
558     }
559 
560     public List findByFolderId(long folderId, int begin, int end)
561         throws SystemException {
562         return findByFolderId(folderId, begin, end, null);
563     }
564 
565     public List findByFolderId(long folderId, int begin, int end,
566         OrderByComparator obc) throws SystemException {
567         boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
568         String finderClassName = DLFileShortcut.class.getName();
569         String finderMethodName = "findByFolderId";
570         String[] finderParams = new String[] {
571                 Long.class.getName(),
572                 
573                 "java.lang.Integer", "java.lang.Integer",
574                 "com.liferay.portal.kernel.util.OrderByComparator"
575             };
576         Object[] finderArgs = new Object[] {
577                 new Long(folderId),
578                 
579                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
580             };
581 
582         Object result = null;
583 
584         if (finderClassNameCacheEnabled) {
585             result = FinderCache.getResult(finderClassName, finderMethodName,
586                     finderParams, finderArgs, getSessionFactory());
587         }
588 
589         if (result == null) {
590             Session session = null;
591 
592             try {
593                 session = openSession();
594 
595                 StringMaker query = new StringMaker();
596 
597                 query.append(
598                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
599 
600                 query.append("folderId = ?");
601 
602                 query.append(" ");
603 
604                 if (obc != null) {
605                     query.append("ORDER BY ");
606                     query.append(obc.getOrderBy());
607                 }
608 
609                 Query q = session.createQuery(query.toString());
610 
611                 int queryPos = 0;
612 
613                 q.setLong(queryPos++, folderId);
614 
615                 List list = QueryUtil.list(q, getDialect(), begin, end);
616 
617                 FinderCache.putResult(finderClassNameCacheEnabled,
618                     finderClassName, finderMethodName, finderParams,
619                     finderArgs, list);
620 
621                 return list;
622             }
623             catch (Exception e) {
624                 throw HibernateUtil.processException(e);
625             }
626             finally {
627                 closeSession(session);
628             }
629         }
630         else {
631             return (List)result;
632         }
633     }
634 
635     public DLFileShortcut findByFolderId_First(long folderId,
636         OrderByComparator obc)
637         throws NoSuchFileShortcutException, SystemException {
638         List list = findByFolderId(folderId, 0, 1, obc);
639 
640         if (list.size() == 0) {
641             StringMaker msg = new StringMaker();
642 
643             msg.append("No DLFileShortcut exists with the key {");
644 
645             msg.append("folderId=" + folderId);
646 
647             msg.append(StringPool.CLOSE_CURLY_BRACE);
648 
649             throw new NoSuchFileShortcutException(msg.toString());
650         }
651         else {
652             return (DLFileShortcut)list.get(0);
653         }
654     }
655 
656     public DLFileShortcut findByFolderId_Last(long folderId,
657         OrderByComparator obc)
658         throws NoSuchFileShortcutException, SystemException {
659         int count = countByFolderId(folderId);
660 
661         List list = findByFolderId(folderId, count - 1, count, obc);
662 
663         if (list.size() == 0) {
664             StringMaker msg = new StringMaker();
665 
666             msg.append("No DLFileShortcut exists with the key {");
667 
668             msg.append("folderId=" + folderId);
669 
670             msg.append(StringPool.CLOSE_CURLY_BRACE);
671 
672             throw new NoSuchFileShortcutException(msg.toString());
673         }
674         else {
675             return (DLFileShortcut)list.get(0);
676         }
677     }
678 
679     public DLFileShortcut[] findByFolderId_PrevAndNext(long fileShortcutId,
680         long folderId, OrderByComparator obc)
681         throws NoSuchFileShortcutException, SystemException {
682         DLFileShortcut dlFileShortcut = findByPrimaryKey(fileShortcutId);
683 
684         int count = countByFolderId(folderId);
685 
686         Session session = null;
687 
688         try {
689             session = openSession();
690 
691             StringMaker query = new StringMaker();
692 
693             query.append(
694                 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
695 
696             query.append("folderId = ?");
697 
698             query.append(" ");
699 
700             if (obc != null) {
701                 query.append("ORDER BY ");
702                 query.append(obc.getOrderBy());
703             }
704 
705             Query q = session.createQuery(query.toString());
706 
707             int queryPos = 0;
708 
709             q.setLong(queryPos++, folderId);
710 
711             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
712                     dlFileShortcut);
713 
714             DLFileShortcut[] array = new DLFileShortcutImpl[3];
715 
716             array[0] = (DLFileShortcut)objArray[0];
717             array[1] = (DLFileShortcut)objArray[1];
718             array[2] = (DLFileShortcut)objArray[2];
719 
720             return array;
721         }
722         catch (Exception e) {
723             throw HibernateUtil.processException(e);
724         }
725         finally {
726             closeSession(session);
727         }
728     }
729 
730     public List findByTF_TN(long toFolderId, String toName)
731         throws SystemException {
732         boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
733         String finderClassName = DLFileShortcut.class.getName();
734         String finderMethodName = "findByTF_TN";
735         String[] finderParams = new String[] {
736                 Long.class.getName(), String.class.getName()
737             };
738         Object[] finderArgs = new Object[] { new Long(toFolderId), toName };
739 
740         Object result = null;
741 
742         if (finderClassNameCacheEnabled) {
743             result = FinderCache.getResult(finderClassName, finderMethodName,
744                     finderParams, finderArgs, getSessionFactory());
745         }
746 
747         if (result == null) {
748             Session session = null;
749 
750             try {
751                 session = openSession();
752 
753                 StringMaker query = new StringMaker();
754 
755                 query.append(
756                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
757 
758                 query.append("toFolderId = ?");
759 
760                 query.append(" AND ");
761 
762                 if (toName == null) {
763                     query.append("toName IS NULL");
764                 }
765                 else {
766                     query.append("toName = ?");
767                 }
768 
769                 query.append(" ");
770 
771                 Query q = session.createQuery(query.toString());
772 
773                 int queryPos = 0;
774 
775                 q.setLong(queryPos++, toFolderId);
776 
777                 if (toName != null) {
778                     q.setString(queryPos++, toName);
779                 }
780 
781                 List list = q.list();
782 
783                 FinderCache.putResult(finderClassNameCacheEnabled,
784                     finderClassName, finderMethodName, finderParams,
785                     finderArgs, list);
786 
787                 return list;
788             }
789             catch (Exception e) {
790                 throw HibernateUtil.processException(e);
791             }
792             finally {
793                 closeSession(session);
794             }
795         }
796         else {
797             return (List)result;
798         }
799     }
800 
801     public List findByTF_TN(long toFolderId, String toName, int begin, int end)
802         throws SystemException {
803         return findByTF_TN(toFolderId, toName, begin, end, null);
804     }
805 
806     public List findByTF_TN(long toFolderId, String toName, int begin, int end,
807         OrderByComparator obc) throws SystemException {
808         boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
809         String finderClassName = DLFileShortcut.class.getName();
810         String finderMethodName = "findByTF_TN";
811         String[] finderParams = new String[] {
812                 Long.class.getName(), String.class.getName(),
813                 
814                 "java.lang.Integer", "java.lang.Integer",
815                 "com.liferay.portal.kernel.util.OrderByComparator"
816             };
817         Object[] finderArgs = new Object[] {
818                 new Long(toFolderId),
819                 
820                 toName,
821                 
822                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
823             };
824 
825         Object result = null;
826 
827         if (finderClassNameCacheEnabled) {
828             result = FinderCache.getResult(finderClassName, finderMethodName,
829                     finderParams, finderArgs, getSessionFactory());
830         }
831 
832         if (result == null) {
833             Session session = null;
834 
835             try {
836                 session = openSession();
837 
838                 StringMaker query = new StringMaker();
839 
840                 query.append(
841                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
842 
843                 query.append("toFolderId = ?");
844 
845                 query.append(" AND ");
846 
847                 if (toName == null) {
848                     query.append("toName IS NULL");
849                 }
850                 else {
851                     query.append("toName = ?");
852                 }
853 
854                 query.append(" ");
855 
856                 if (obc != null) {
857                     query.append("ORDER BY ");
858                     query.append(obc.getOrderBy());
859                 }
860 
861                 Query q = session.createQuery(query.toString());
862 
863                 int queryPos = 0;
864 
865                 q.setLong(queryPos++, toFolderId);
866 
867                 if (toName != null) {
868                     q.setString(queryPos++, toName);
869                 }
870 
871                 List list = QueryUtil.list(q, getDialect(), begin, end);
872 
873                 FinderCache.putResult(finderClassNameCacheEnabled,
874                     finderClassName, finderMethodName, finderParams,
875                     finderArgs, list);
876 
877                 return list;
878             }
879             catch (Exception e) {
880                 throw HibernateUtil.processException(e);
881             }
882             finally {
883                 closeSession(session);
884             }
885         }
886         else {
887             return (List)result;
888         }
889     }
890 
891     public DLFileShortcut findByTF_TN_First(long toFolderId, String toName,
892         OrderByComparator obc)
893         throws NoSuchFileShortcutException, SystemException {
894         List list = findByTF_TN(toFolderId, toName, 0, 1, obc);
895 
896         if (list.size() == 0) {
897             StringMaker msg = new StringMaker();
898 
899             msg.append("No DLFileShortcut exists with the key {");
900 
901             msg.append("toFolderId=" + toFolderId);
902 
903             msg.append(", ");
904             msg.append("toName=" + toName);
905 
906             msg.append(StringPool.CLOSE_CURLY_BRACE);
907 
908             throw new NoSuchFileShortcutException(msg.toString());
909         }
910         else {
911             return (DLFileShortcut)list.get(0);
912         }
913     }
914 
915     public DLFileShortcut findByTF_TN_Last(long toFolderId, String toName,
916         OrderByComparator obc)
917         throws NoSuchFileShortcutException, SystemException {
918         int count = countByTF_TN(toFolderId, toName);
919 
920         List list = findByTF_TN(toFolderId, toName, count - 1, count, obc);
921 
922         if (list.size() == 0) {
923             StringMaker msg = new StringMaker();
924 
925             msg.append("No DLFileShortcut exists with the key {");
926 
927             msg.append("toFolderId=" + toFolderId);
928 
929             msg.append(", ");
930             msg.append("toName=" + toName);
931 
932             msg.append(StringPool.CLOSE_CURLY_BRACE);
933 
934             throw new NoSuchFileShortcutException(msg.toString());
935         }
936         else {
937             return (DLFileShortcut)list.get(0);
938         }
939     }
940 
941     public DLFileShortcut[] findByTF_TN_PrevAndNext(long fileShortcutId,
942         long toFolderId, String toName, OrderByComparator obc)
943         throws NoSuchFileShortcutException, SystemException {
944         DLFileShortcut dlFileShortcut = findByPrimaryKey(fileShortcutId);
945 
946         int count = countByTF_TN(toFolderId, toName);
947 
948         Session session = null;
949 
950         try {
951             session = openSession();
952 
953             StringMaker query = new StringMaker();
954 
955             query.append(
956                 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
957 
958             query.append("toFolderId = ?");
959 
960             query.append(" AND ");
961 
962             if (toName == null) {
963                 query.append("toName IS NULL");
964             }
965             else {
966                 query.append("toName = ?");
967             }
968 
969             query.append(" ");
970 
971             if (obc != null) {
972                 query.append("ORDER BY ");
973                 query.append(obc.getOrderBy());
974             }
975 
976             Query q = session.createQuery(query.toString());
977 
978             int queryPos = 0;
979 
980             q.setLong(queryPos++, toFolderId);
981 
982             if (toName != null) {
983                 q.setString(queryPos++, toName);
984             }
985 
986             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
987                     dlFileShortcut);
988 
989             DLFileShortcut[] array = new DLFileShortcutImpl[3];
990 
991             array[0] = (DLFileShortcut)objArray[0];
992             array[1] = (DLFileShortcut)objArray[1];
993             array[2] = (DLFileShortcut)objArray[2];
994 
995             return array;
996         }
997         catch (Exception e) {
998             throw HibernateUtil.processException(e);
999         }
1000        finally {
1001            closeSession(session);
1002        }
1003    }
1004
1005    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
1006        throws SystemException {
1007        Session session = null;
1008
1009        try {
1010            session = openSession();
1011
1012            DynamicQuery query = queryInitializer.initialize(session);
1013
1014            return query.list();
1015        }
1016        catch (Exception e) {
1017            throw HibernateUtil.processException(e);
1018        }
1019        finally {
1020            closeSession(session);
1021        }
1022    }
1023
1024    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
1025        int begin, int end) throws SystemException {
1026        Session session = null;
1027
1028        try {
1029            session = openSession();
1030
1031            DynamicQuery query = queryInitializer.initialize(session);
1032
1033            query.setLimit(begin, end);
1034
1035            return query.list();
1036        }
1037        catch (Exception e) {
1038            throw HibernateUtil.processException(e);
1039        }
1040        finally {
1041            closeSession(session);
1042        }
1043    }
1044
1045    public List findAll() throws SystemException {
1046        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1047    }
1048
1049    public List findAll(int begin, int end) throws SystemException {
1050        return findAll(begin, end, null);
1051    }
1052
1053    public List findAll(int begin, int end, OrderByComparator obc)
1054        throws SystemException {
1055        boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
1056        String finderClassName = DLFileShortcut.class.getName();
1057        String finderMethodName = "findAll";
1058        String[] finderParams = new String[] {
1059                "java.lang.Integer", "java.lang.Integer",
1060                "com.liferay.portal.kernel.util.OrderByComparator"
1061            };
1062        Object[] finderArgs = new Object[] {
1063                String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1064            };
1065
1066        Object result = null;
1067
1068        if (finderClassNameCacheEnabled) {
1069            result = FinderCache.getResult(finderClassName, finderMethodName,
1070                    finderParams, finderArgs, getSessionFactory());
1071        }
1072
1073        if (result == null) {
1074            Session session = null;
1075
1076            try {
1077                session = openSession();
1078
1079                StringMaker query = new StringMaker();
1080
1081                query.append(
1082                    "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut ");
1083
1084                if (obc != null) {
1085                    query.append("ORDER BY ");
1086                    query.append(obc.getOrderBy());
1087                }
1088
1089                Query q = session.createQuery(query.toString());
1090
1091                List list = QueryUtil.list(q, getDialect(), begin, end);
1092
1093                if (obc == null) {
1094                    Collections.sort(list);
1095                }
1096
1097                FinderCache.putResult(finderClassNameCacheEnabled,
1098                    finderClassName, finderMethodName, finderParams,
1099                    finderArgs, list);
1100
1101                return list;
1102            }
1103            catch (Exception e) {
1104                throw HibernateUtil.processException(e);
1105            }
1106            finally {
1107                closeSession(session);
1108            }
1109        }
1110        else {
1111            return (List)result;
1112        }
1113    }
1114
1115    public void removeByUuid(String uuid) throws SystemException {
1116        Iterator itr = findByUuid(uuid).iterator();
1117
1118        while (itr.hasNext()) {
1119            DLFileShortcut dlFileShortcut = (DLFileShortcut)itr.next();
1120
1121            remove(dlFileShortcut);
1122        }
1123    }
1124
1125    public void removeByFolderId(long folderId) throws SystemException {
1126        Iterator itr = findByFolderId(folderId).iterator();
1127
1128        while (itr.hasNext()) {
1129            DLFileShortcut dlFileShortcut = (DLFileShortcut)itr.next();
1130
1131            remove(dlFileShortcut);
1132        }
1133    }
1134
1135    public void removeByTF_TN(long toFolderId, String toName)
1136        throws SystemException {
1137        Iterator itr = findByTF_TN(toFolderId, toName).iterator();
1138
1139        while (itr.hasNext()) {
1140            DLFileShortcut dlFileShortcut = (DLFileShortcut)itr.next();
1141
1142            remove(dlFileShortcut);
1143        }
1144    }
1145
1146    public void removeAll() throws SystemException {
1147        Iterator itr = findAll().iterator();
1148
1149        while (itr.hasNext()) {
1150            remove((DLFileShortcut)itr.next());
1151        }
1152    }
1153
1154    public int countByUuid(String uuid) throws SystemException {
1155        boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
1156        String finderClassName = DLFileShortcut.class.getName();
1157        String finderMethodName = "countByUuid";
1158        String[] finderParams = new String[] { String.class.getName() };
1159        Object[] finderArgs = new Object[] { uuid };
1160
1161        Object result = null;
1162
1163        if (finderClassNameCacheEnabled) {
1164            result = FinderCache.getResult(finderClassName, finderMethodName,
1165                    finderParams, finderArgs, getSessionFactory());
1166        }
1167
1168        if (result == null) {
1169            Session session = null;
1170
1171            try {
1172                session = openSession();
1173
1174                StringMaker query = new StringMaker();
1175
1176                query.append("SELECT COUNT(*) ");
1177                query.append(
1178                    "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
1179
1180                if (uuid == null) {
1181                    query.append("uuid_ IS NULL");
1182                }
1183                else {
1184                    query.append("uuid_ = ?");
1185                }
1186
1187                query.append(" ");
1188
1189                Query q = session.createQuery(query.toString());
1190
1191                int queryPos = 0;
1192
1193                if (uuid != null) {
1194                    q.setString(queryPos++, uuid);
1195                }
1196
1197                Long count = null;
1198
1199                Iterator itr = q.list().iterator();
1200
1201                if (itr.hasNext()) {
1202                    count = (Long)itr.next();
1203                }
1204
1205                if (count == null) {
1206                    count = new Long(0);
1207                }
1208
1209                FinderCache.putResult(finderClassNameCacheEnabled,
1210                    finderClassName, finderMethodName, finderParams,
1211                    finderArgs, count);
1212
1213                return count.intValue();
1214            }
1215            catch (Exception e) {
1216                throw HibernateUtil.processException(e);
1217            }
1218            finally {
1219                closeSession(session);
1220            }
1221        }
1222        else {
1223            return ((Long)result).intValue();
1224        }
1225    }
1226
1227    public int countByFolderId(long folderId) throws SystemException {
1228        boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
1229        String finderClassName = DLFileShortcut.class.getName();
1230        String finderMethodName = "countByFolderId";
1231        String[] finderParams = new String[] { Long.class.getName() };
1232        Object[] finderArgs = new Object[] { new Long(folderId) };
1233
1234        Object result = null;
1235
1236        if (finderClassNameCacheEnabled) {
1237            result = FinderCache.getResult(finderClassName, finderMethodName,
1238                    finderParams, finderArgs, getSessionFactory());
1239        }
1240
1241        if (result == null) {
1242            Session session = null;
1243
1244            try {
1245                session = openSession();
1246
1247                StringMaker query = new StringMaker();
1248
1249                query.append("SELECT COUNT(*) ");
1250                query.append(
1251                    "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
1252
1253                query.append("folderId = ?");
1254
1255                query.append(" ");
1256
1257                Query q = session.createQuery(query.toString());
1258
1259                int queryPos = 0;
1260
1261                q.setLong(queryPos++, folderId);
1262
1263                Long count = null;
1264
1265                Iterator itr = q.list().iterator();
1266
1267                if (itr.hasNext()) {
1268                    count = (Long)itr.next();
1269                }
1270
1271                if (count == null) {
1272                    count = new Long(0);
1273                }
1274
1275                FinderCache.putResult(finderClassNameCacheEnabled,
1276                    finderClassName, finderMethodName, finderParams,
1277                    finderArgs, count);
1278
1279                return count.intValue();
1280            }
1281            catch (Exception e) {
1282                throw HibernateUtil.processException(e);
1283            }
1284            finally {
1285                closeSession(session);
1286            }
1287        }
1288        else {
1289            return ((Long)result).intValue();
1290        }
1291    }
1292
1293    public int countByTF_TN(long toFolderId, String toName)
1294        throws SystemException {
1295        boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
1296        String finderClassName = DLFileShortcut.class.getName();
1297        String finderMethodName = "countByTF_TN";
1298        String[] finderParams = new String[] {
1299                Long.class.getName(), String.class.getName()
1300            };
1301        Object[] finderArgs = new Object[] { new Long(toFolderId), toName };
1302
1303        Object result = null;
1304
1305        if (finderClassNameCacheEnabled) {
1306            result = FinderCache.getResult(finderClassName, finderMethodName,
1307                    finderParams, finderArgs, getSessionFactory());
1308        }
1309
1310        if (result == null) {
1311            Session session = null;
1312
1313            try {
1314                session = openSession();
1315
1316                StringMaker query = new StringMaker();
1317
1318                query.append("SELECT COUNT(*) ");
1319                query.append(
1320                    "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
1321
1322                query.append("toFolderId = ?");
1323
1324                query.append(" AND ");
1325
1326                if (toName == null) {
1327                    query.append("toName IS NULL");
1328                }
1329                else {
1330                    query.append("toName = ?");
1331                }
1332
1333                query.append(" ");
1334
1335                Query q = session.createQuery(query.toString());
1336
1337                int queryPos = 0;
1338
1339                q.setLong(queryPos++, toFolderId);
1340
1341                if (toName != null) {
1342                    q.setString(queryPos++, toName);
1343                }
1344
1345                Long count = null;
1346
1347                Iterator itr = q.list().iterator();
1348
1349                if (itr.hasNext()) {
1350                    count = (Long)itr.next();
1351                }
1352
1353                if (count == null) {
1354                    count = new Long(0);
1355                }
1356
1357                FinderCache.putResult(finderClassNameCacheEnabled,
1358                    finderClassName, finderMethodName, finderParams,
1359                    finderArgs, count);
1360
1361                return count.intValue();
1362            }
1363            catch (Exception e) {
1364                throw HibernateUtil.processException(e);
1365            }
1366            finally {
1367                closeSession(session);
1368            }
1369        }
1370        else {
1371            return ((Long)result).intValue();
1372        }
1373    }
1374
1375    public int countAll() throws SystemException {
1376        boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
1377        String finderClassName = DLFileShortcut.class.getName();
1378        String finderMethodName = "countAll";
1379        String[] finderParams = new String[] {  };
1380        Object[] finderArgs = new Object[] {  };
1381
1382        Object result = null;
1383
1384        if (finderClassNameCacheEnabled) {
1385            result = FinderCache.getResult(finderClassName, finderMethodName,
1386                    finderParams, finderArgs, getSessionFactory());
1387        }
1388
1389        if (result == null) {
1390            Session session = null;
1391
1392            try {
1393                session = openSession();
1394
1395                Query q = session.createQuery(
1396                        "SELECT COUNT(*) FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut");
1397
1398                Long count = null;
1399
1400                Iterator itr = q.list().iterator();
1401
1402                if (itr.hasNext()) {
1403                    count = (Long)itr.next();
1404                }
1405
1406                if (count == null) {
1407                    count = new Long(0);
1408                }
1409
1410                FinderCache.putResult(finderClassNameCacheEnabled,
1411                    finderClassName, finderMethodName, finderParams,
1412                    finderArgs, count);
1413
1414                return count.intValue();
1415            }
1416            catch (Exception e) {
1417                throw HibernateUtil.processException(e);
1418            }
1419            finally {
1420                closeSession(session);
1421            }
1422        }
1423        else {
1424            return ((Long)result).intValue();
1425        }
1426    }
1427
1428    protected void initDao() {
1429    }
1430
1431    private static ModelListener _getListener() {
1432        if (Validator.isNotNull(_LISTENER)) {
1433            try {
1434                return (ModelListener)Class.forName(_LISTENER).newInstance();
1435            }
1436            catch (Exception e) {
1437                _log.error(e);
1438            }
1439        }
1440
1441        return null;
1442    }
1443
1444    private static final String _LISTENER = GetterUtil.getString(PropsUtil.get(
1445                "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileShortcut"));
1446    private static Log _log = LogFactory.getLog(DLFileShortcutPersistenceImpl.class);
1447}