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