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