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