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