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                 (!dlFileShortcut.getUuid()
355                                     .equals(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                 (!dlFileShortcut.getUuid()
366                                     .equals(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                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
442 
443                 if (uuid == null) {
444                     query.append("uuid_ IS NULL");
445                 }
446                 else {
447                     query.append("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                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
508 
509                 if (uuid == null) {
510                     query.append("uuid_ IS NULL");
511                 }
512                 else {
513                     query.append("uuid_ = ?");
514                 }
515 
516                 query.append(" ");
517 
518                 if (obc != null) {
519                     query.append("ORDER BY ");
520                     query.append(obc.getOrderBy());
521                 }
522 
523                 Query q = session.createQuery(query.toString());
524 
525                 QueryPos qPos = QueryPos.getInstance(q);
526 
527                 if (uuid != null) {
528                     qPos.add(uuid);
529                 }
530 
531                 list = (List<DLFileShortcut>)QueryUtil.list(q, getDialect(),
532                         start, end);
533             }
534             catch (Exception e) {
535                 throw processException(e);
536             }
537             finally {
538                 if (list == null) {
539                     list = new ArrayList<DLFileShortcut>();
540                 }
541 
542                 cacheResult(list);
543 
544                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
545                     finderArgs, list);
546 
547                 closeSession(session);
548             }
549         }
550 
551         return list;
552     }
553 
554     public DLFileShortcut findByUuid_First(String uuid, OrderByComparator obc)
555         throws NoSuchFileShortcutException, SystemException {
556         List<DLFileShortcut> list = findByUuid(uuid, 0, 1, obc);
557 
558         if (list.isEmpty()) {
559             StringBuilder msg = new StringBuilder();
560 
561             msg.append("No DLFileShortcut exists with the key {");
562 
563             msg.append("uuid=" + uuid);
564 
565             msg.append(StringPool.CLOSE_CURLY_BRACE);
566 
567             throw new NoSuchFileShortcutException(msg.toString());
568         }
569         else {
570             return list.get(0);
571         }
572     }
573 
574     public DLFileShortcut findByUuid_Last(String uuid, OrderByComparator obc)
575         throws NoSuchFileShortcutException, SystemException {
576         int count = countByUuid(uuid);
577 
578         List<DLFileShortcut> list = findByUuid(uuid, count - 1, count, obc);
579 
580         if (list.isEmpty()) {
581             StringBuilder msg = new StringBuilder();
582 
583             msg.append("No DLFileShortcut exists with the key {");
584 
585             msg.append("uuid=" + uuid);
586 
587             msg.append(StringPool.CLOSE_CURLY_BRACE);
588 
589             throw new NoSuchFileShortcutException(msg.toString());
590         }
591         else {
592             return list.get(0);
593         }
594     }
595 
596     public DLFileShortcut[] findByUuid_PrevAndNext(long fileShortcutId,
597         String uuid, OrderByComparator obc)
598         throws NoSuchFileShortcutException, SystemException {
599         DLFileShortcut dlFileShortcut = findByPrimaryKey(fileShortcutId);
600 
601         int count = countByUuid(uuid);
602 
603         Session session = null;
604 
605         try {
606             session = openSession();
607 
608             StringBuilder query = new StringBuilder();
609 
610             query.append(
611                 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
612 
613             if (uuid == null) {
614                 query.append("uuid_ IS NULL");
615             }
616             else {
617                 query.append("uuid_ = ?");
618             }
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             if (uuid != null) {
632                 qPos.add(uuid);
633             }
634 
635             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
636                     dlFileShortcut);
637 
638             DLFileShortcut[] array = new DLFileShortcutImpl[3];
639 
640             array[0] = (DLFileShortcut)objArray[0];
641             array[1] = (DLFileShortcut)objArray[1];
642             array[2] = (DLFileShortcut)objArray[2];
643 
644             return array;
645         }
646         catch (Exception e) {
647             throw processException(e);
648         }
649         finally {
650             closeSession(session);
651         }
652     }
653 
654     public DLFileShortcut findByUUID_G(String uuid, long groupId)
655         throws NoSuchFileShortcutException, SystemException {
656         DLFileShortcut dlFileShortcut = fetchByUUID_G(uuid, groupId);
657 
658         if (dlFileShortcut == null) {
659             StringBuilder msg = new StringBuilder();
660 
661             msg.append("No DLFileShortcut exists with the key {");
662 
663             msg.append("uuid=" + uuid);
664 
665             msg.append(", ");
666             msg.append("groupId=" + groupId);
667 
668             msg.append(StringPool.CLOSE_CURLY_BRACE);
669 
670             if (_log.isWarnEnabled()) {
671                 _log.warn(msg.toString());
672             }
673 
674             throw new NoSuchFileShortcutException(msg.toString());
675         }
676 
677         return dlFileShortcut;
678     }
679 
680     public DLFileShortcut fetchByUUID_G(String uuid, long groupId)
681         throws SystemException {
682         return fetchByUUID_G(uuid, groupId, true);
683     }
684 
685     public DLFileShortcut fetchByUUID_G(String uuid, long groupId,
686         boolean retrieveFromCache) throws SystemException {
687         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
688 
689         Object result = null;
690 
691         if (retrieveFromCache) {
692             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
693                     finderArgs, this);
694         }
695 
696         if (result == null) {
697             Session session = null;
698 
699             try {
700                 session = openSession();
701 
702                 StringBuilder query = new StringBuilder();
703 
704                 query.append(
705                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
706 
707                 if (uuid == null) {
708                     query.append("uuid_ IS NULL");
709                 }
710                 else {
711                     query.append("uuid_ = ?");
712                 }
713 
714                 query.append(" AND ");
715 
716                 query.append("groupId = ?");
717 
718                 query.append(" ");
719 
720                 Query q = session.createQuery(query.toString());
721 
722                 QueryPos qPos = QueryPos.getInstance(q);
723 
724                 if (uuid != null) {
725                     qPos.add(uuid);
726                 }
727 
728                 qPos.add(groupId);
729 
730                 List<DLFileShortcut> list = q.list();
731 
732                 result = list;
733 
734                 DLFileShortcut dlFileShortcut = null;
735 
736                 if (list.isEmpty()) {
737                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
738                         finderArgs, list);
739                 }
740                 else {
741                     dlFileShortcut = list.get(0);
742 
743                     cacheResult(dlFileShortcut);
744 
745                     if ((dlFileShortcut.getUuid() == null) ||
746                             !dlFileShortcut.getUuid().equals(uuid) ||
747                             (dlFileShortcut.getGroupId() != groupId)) {
748                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
749                             finderArgs, list);
750                     }
751                 }
752 
753                 return dlFileShortcut;
754             }
755             catch (Exception e) {
756                 throw processException(e);
757             }
758             finally {
759                 if (result == null) {
760                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
761                         finderArgs, new ArrayList<DLFileShortcut>());
762                 }
763 
764                 closeSession(session);
765             }
766         }
767         else {
768             if (result instanceof List) {
769                 return null;
770             }
771             else {
772                 return (DLFileShortcut)result;
773             }
774         }
775     }
776 
777     public List<DLFileShortcut> findByFolderId(long folderId)
778         throws SystemException {
779         Object[] finderArgs = new Object[] { new Long(folderId) };
780 
781         List<DLFileShortcut> list = (List<DLFileShortcut>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_FOLDERID,
782                 finderArgs, this);
783 
784         if (list == null) {
785             Session session = null;
786 
787             try {
788                 session = openSession();
789 
790                 StringBuilder query = new StringBuilder();
791 
792                 query.append(
793                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
794 
795                 query.append("folderId = ?");
796 
797                 query.append(" ");
798 
799                 Query q = session.createQuery(query.toString());
800 
801                 QueryPos qPos = QueryPos.getInstance(q);
802 
803                 qPos.add(folderId);
804 
805                 list = q.list();
806             }
807             catch (Exception e) {
808                 throw processException(e);
809             }
810             finally {
811                 if (list == null) {
812                     list = new ArrayList<DLFileShortcut>();
813                 }
814 
815                 cacheResult(list);
816 
817                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_FOLDERID,
818                     finderArgs, list);
819 
820                 closeSession(session);
821             }
822         }
823 
824         return list;
825     }
826 
827     public List<DLFileShortcut> findByFolderId(long folderId, int start, int end)
828         throws SystemException {
829         return findByFolderId(folderId, start, end, null);
830     }
831 
832     public List<DLFileShortcut> findByFolderId(long folderId, int start,
833         int end, OrderByComparator obc) throws SystemException {
834         Object[] finderArgs = new Object[] {
835                 new Long(folderId),
836                 
837                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
838             };
839 
840         List<DLFileShortcut> list = (List<DLFileShortcut>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_FOLDERID,
841                 finderArgs, this);
842 
843         if (list == null) {
844             Session session = null;
845 
846             try {
847                 session = openSession();
848 
849                 StringBuilder query = new StringBuilder();
850 
851                 query.append(
852                     "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
853 
854                 query.append("folderId = ?");
855 
856                 query.append(" ");
857 
858                 if (obc != null) {
859                     query.append("ORDER BY ");
860                     query.append(obc.getOrderBy());
861                 }
862 
863                 Query q = session.createQuery(query.toString());
864 
865                 QueryPos qPos = QueryPos.getInstance(q);
866 
867                 qPos.add(folderId);
868 
869                 list = (List<DLFileShortcut>)QueryUtil.list(q, getDialect(),
870                         start, end);
871             }
872             catch (Exception e) {
873                 throw processException(e);
874             }
875             finally {
876                 if (list == null) {
877                     list = new ArrayList<DLFileShortcut>();
878                 }
879 
880                 cacheResult(list);
881 
882                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_FOLDERID,
883                     finderArgs, list);
884 
885                 closeSession(session);
886             }
887         }
888 
889         return list;
890     }
891 
892     public DLFileShortcut findByFolderId_First(long folderId,
893         OrderByComparator obc)
894         throws NoSuchFileShortcutException, SystemException {
895         List<DLFileShortcut> list = findByFolderId(folderId, 0, 1, obc);
896 
897         if (list.isEmpty()) {
898             StringBuilder msg = new StringBuilder();
899 
900             msg.append("No DLFileShortcut exists with the key {");
901 
902             msg.append("folderId=" + folderId);
903 
904             msg.append(StringPool.CLOSE_CURLY_BRACE);
905 
906             throw new NoSuchFileShortcutException(msg.toString());
907         }
908         else {
909             return list.get(0);
910         }
911     }
912 
913     public DLFileShortcut findByFolderId_Last(long folderId,
914         OrderByComparator obc)
915         throws NoSuchFileShortcutException, SystemException {
916         int count = countByFolderId(folderId);
917 
918         List<DLFileShortcut> list = findByFolderId(folderId, count - 1, count,
919                 obc);
920 
921         if (list.isEmpty()) {
922             StringBuilder msg = new StringBuilder();
923 
924             msg.append("No DLFileShortcut exists with the key {");
925 
926             msg.append("folderId=" + folderId);
927 
928             msg.append(StringPool.CLOSE_CURLY_BRACE);
929 
930             throw new NoSuchFileShortcutException(msg.toString());
931         }
932         else {
933             return list.get(0);
934         }
935     }
936 
937     public DLFileShortcut[] findByFolderId_PrevAndNext(long fileShortcutId,
938         long folderId, OrderByComparator obc)
939         throws NoSuchFileShortcutException, SystemException {
940         DLFileShortcut dlFileShortcut = findByPrimaryKey(fileShortcutId);
941 
942         int count = countByFolderId(folderId);
943 
944         Session session = null;
945 
946         try {
947             session = openSession();
948 
949             StringBuilder query = new StringBuilder();
950 
951             query.append(
952                 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
953 
954             query.append("folderId = ?");
955 
956             query.append(" ");
957 
958             if (obc != null) {
959                 query.append("ORDER BY ");
960                 query.append(obc.getOrderBy());
961             }
962 
963             Query q = session.createQuery(query.toString());
964 
965             QueryPos qPos = QueryPos.getInstance(q);
966 
967             qPos.add(folderId);
968 
969             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
970                     dlFileShortcut);
971 
972             DLFileShortcut[] array = new DLFileShortcutImpl[3];
973 
974             array[0] = (DLFileShortcut)objArray[0];
975             array[1] = (DLFileShortcut)objArray[1];
976             array[2] = (DLFileShortcut)objArray[2];
977 
978             return array;
979         }
980         catch (Exception e) {
981             throw processException(e);
982         }
983         finally {
984             closeSession(session);
985         }
986     }
987 
988     public List<DLFileShortcut> findByTF_TN(long toFolderId, String toName)
989         throws SystemException {
990         Object[] finderArgs = new Object[] { new Long(toFolderId), toName };
991 
992         List<DLFileShortcut> list = (List<DLFileShortcut>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TF_TN,
993                 finderArgs, this);
994 
995         if (list == null) {
996             Session session = null;
997 
998             try {
999                 session = openSession();
1000
1001                StringBuilder query = new StringBuilder();
1002
1003                query.append(
1004                    "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
1005
1006                query.append("toFolderId = ?");
1007
1008                query.append(" AND ");
1009
1010                if (toName == null) {
1011                    query.append("toName IS NULL");
1012                }
1013                else {
1014                    query.append("toName = ?");
1015                }
1016
1017                query.append(" ");
1018
1019                Query q = session.createQuery(query.toString());
1020
1021                QueryPos qPos = QueryPos.getInstance(q);
1022
1023                qPos.add(toFolderId);
1024
1025                if (toName != null) {
1026                    qPos.add(toName);
1027                }
1028
1029                list = q.list();
1030            }
1031            catch (Exception e) {
1032                throw processException(e);
1033            }
1034            finally {
1035                if (list == null) {
1036                    list = new ArrayList<DLFileShortcut>();
1037                }
1038
1039                cacheResult(list);
1040
1041                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TF_TN,
1042                    finderArgs, list);
1043
1044                closeSession(session);
1045            }
1046        }
1047
1048        return list;
1049    }
1050
1051    public List<DLFileShortcut> findByTF_TN(long toFolderId, String toName,
1052        int start, int end) throws SystemException {
1053        return findByTF_TN(toFolderId, toName, start, end, null);
1054    }
1055
1056    public List<DLFileShortcut> findByTF_TN(long toFolderId, String toName,
1057        int start, int end, OrderByComparator obc) throws SystemException {
1058        Object[] finderArgs = new Object[] {
1059                new Long(toFolderId),
1060                
1061                toName,
1062                
1063                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1064            };
1065
1066        List<DLFileShortcut> list = (List<DLFileShortcut>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_TF_TN,
1067                finderArgs, this);
1068
1069        if (list == null) {
1070            Session session = null;
1071
1072            try {
1073                session = openSession();
1074
1075                StringBuilder query = new StringBuilder();
1076
1077                query.append(
1078                    "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
1079
1080                query.append("toFolderId = ?");
1081
1082                query.append(" AND ");
1083
1084                if (toName == null) {
1085                    query.append("toName IS NULL");
1086                }
1087                else {
1088                    query.append("toName = ?");
1089                }
1090
1091                query.append(" ");
1092
1093                if (obc != null) {
1094                    query.append("ORDER BY ");
1095                    query.append(obc.getOrderBy());
1096                }
1097
1098                Query q = session.createQuery(query.toString());
1099
1100                QueryPos qPos = QueryPos.getInstance(q);
1101
1102                qPos.add(toFolderId);
1103
1104                if (toName != null) {
1105                    qPos.add(toName);
1106                }
1107
1108                list = (List<DLFileShortcut>)QueryUtil.list(q, getDialect(),
1109                        start, end);
1110            }
1111            catch (Exception e) {
1112                throw processException(e);
1113            }
1114            finally {
1115                if (list == null) {
1116                    list = new ArrayList<DLFileShortcut>();
1117                }
1118
1119                cacheResult(list);
1120
1121                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_TF_TN,
1122                    finderArgs, list);
1123
1124                closeSession(session);
1125            }
1126        }
1127
1128        return list;
1129    }
1130
1131    public DLFileShortcut findByTF_TN_First(long toFolderId, String toName,
1132        OrderByComparator obc)
1133        throws NoSuchFileShortcutException, SystemException {
1134        List<DLFileShortcut> list = findByTF_TN(toFolderId, toName, 0, 1, obc);
1135
1136        if (list.isEmpty()) {
1137            StringBuilder msg = new StringBuilder();
1138
1139            msg.append("No DLFileShortcut exists with the key {");
1140
1141            msg.append("toFolderId=" + toFolderId);
1142
1143            msg.append(", ");
1144            msg.append("toName=" + toName);
1145
1146            msg.append(StringPool.CLOSE_CURLY_BRACE);
1147
1148            throw new NoSuchFileShortcutException(msg.toString());
1149        }
1150        else {
1151            return list.get(0);
1152        }
1153    }
1154
1155    public DLFileShortcut findByTF_TN_Last(long toFolderId, String toName,
1156        OrderByComparator obc)
1157        throws NoSuchFileShortcutException, SystemException {
1158        int count = countByTF_TN(toFolderId, toName);
1159
1160        List<DLFileShortcut> list = findByTF_TN(toFolderId, toName, count - 1,
1161                count, obc);
1162
1163        if (list.isEmpty()) {
1164            StringBuilder msg = new StringBuilder();
1165
1166            msg.append("No DLFileShortcut exists with the key {");
1167
1168            msg.append("toFolderId=" + toFolderId);
1169
1170            msg.append(", ");
1171            msg.append("toName=" + toName);
1172
1173            msg.append(StringPool.CLOSE_CURLY_BRACE);
1174
1175            throw new NoSuchFileShortcutException(msg.toString());
1176        }
1177        else {
1178            return list.get(0);
1179        }
1180    }
1181
1182    public DLFileShortcut[] findByTF_TN_PrevAndNext(long fileShortcutId,
1183        long toFolderId, String toName, OrderByComparator obc)
1184        throws NoSuchFileShortcutException, SystemException {
1185        DLFileShortcut dlFileShortcut = findByPrimaryKey(fileShortcutId);
1186
1187        int count = countByTF_TN(toFolderId, toName);
1188
1189        Session session = null;
1190
1191        try {
1192            session = openSession();
1193
1194            StringBuilder query = new StringBuilder();
1195
1196            query.append(
1197                "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
1198
1199            query.append("toFolderId = ?");
1200
1201            query.append(" AND ");
1202
1203            if (toName == null) {
1204                query.append("toName IS NULL");
1205            }
1206            else {
1207                query.append("toName = ?");
1208            }
1209
1210            query.append(" ");
1211
1212            if (obc != null) {
1213                query.append("ORDER BY ");
1214                query.append(obc.getOrderBy());
1215            }
1216
1217            Query q = session.createQuery(query.toString());
1218
1219            QueryPos qPos = QueryPos.getInstance(q);
1220
1221            qPos.add(toFolderId);
1222
1223            if (toName != null) {
1224                qPos.add(toName);
1225            }
1226
1227            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1228                    dlFileShortcut);
1229
1230            DLFileShortcut[] array = new DLFileShortcutImpl[3];
1231
1232            array[0] = (DLFileShortcut)objArray[0];
1233            array[1] = (DLFileShortcut)objArray[1];
1234            array[2] = (DLFileShortcut)objArray[2];
1235
1236            return array;
1237        }
1238        catch (Exception e) {
1239            throw processException(e);
1240        }
1241        finally {
1242            closeSession(session);
1243        }
1244    }
1245
1246    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1247        throws SystemException {
1248        Session session = null;
1249
1250        try {
1251            session = openSession();
1252
1253            dynamicQuery.compile(session);
1254
1255            return dynamicQuery.list();
1256        }
1257        catch (Exception e) {
1258            throw processException(e);
1259        }
1260        finally {
1261            closeSession(session);
1262        }
1263    }
1264
1265    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1266        int start, int end) throws SystemException {
1267        Session session = null;
1268
1269        try {
1270            session = openSession();
1271
1272            dynamicQuery.setLimit(start, end);
1273
1274            dynamicQuery.compile(session);
1275
1276            return dynamicQuery.list();
1277        }
1278        catch (Exception e) {
1279            throw processException(e);
1280        }
1281        finally {
1282            closeSession(session);
1283        }
1284    }
1285
1286    public List<DLFileShortcut> findAll() throws SystemException {
1287        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1288    }
1289
1290    public List<DLFileShortcut> findAll(int start, int end)
1291        throws SystemException {
1292        return findAll(start, end, null);
1293    }
1294
1295    public List<DLFileShortcut> findAll(int start, int end,
1296        OrderByComparator obc) throws SystemException {
1297        Object[] finderArgs = new Object[] {
1298                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1299            };
1300
1301        List<DLFileShortcut> list = (List<DLFileShortcut>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1302                finderArgs, this);
1303
1304        if (list == null) {
1305            Session session = null;
1306
1307            try {
1308                session = openSession();
1309
1310                StringBuilder query = new StringBuilder();
1311
1312                query.append(
1313                    "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut ");
1314
1315                if (obc != null) {
1316                    query.append("ORDER BY ");
1317                    query.append(obc.getOrderBy());
1318                }
1319
1320                Query q = session.createQuery(query.toString());
1321
1322                if (obc == null) {
1323                    list = (List<DLFileShortcut>)QueryUtil.list(q,
1324                            getDialect(), start, end, false);
1325
1326                    Collections.sort(list);
1327                }
1328                else {
1329                    list = (List<DLFileShortcut>)QueryUtil.list(q,
1330                            getDialect(), start, end);
1331                }
1332            }
1333            catch (Exception e) {
1334                throw processException(e);
1335            }
1336            finally {
1337                if (list == null) {
1338                    list = new ArrayList<DLFileShortcut>();
1339                }
1340
1341                cacheResult(list);
1342
1343                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1344
1345                closeSession(session);
1346            }
1347        }
1348
1349        return list;
1350    }
1351
1352    public void removeByUuid(String uuid) throws SystemException {
1353        for (DLFileShortcut dlFileShortcut : findByUuid(uuid)) {
1354            remove(dlFileShortcut);
1355        }
1356    }
1357
1358    public void removeByUUID_G(String uuid, long groupId)
1359        throws NoSuchFileShortcutException, SystemException {
1360        DLFileShortcut dlFileShortcut = findByUUID_G(uuid, groupId);
1361
1362        remove(dlFileShortcut);
1363    }
1364
1365    public void removeByFolderId(long folderId) throws SystemException {
1366        for (DLFileShortcut dlFileShortcut : findByFolderId(folderId)) {
1367            remove(dlFileShortcut);
1368        }
1369    }
1370
1371    public void removeByTF_TN(long toFolderId, String toName)
1372        throws SystemException {
1373        for (DLFileShortcut dlFileShortcut : findByTF_TN(toFolderId, toName)) {
1374            remove(dlFileShortcut);
1375        }
1376    }
1377
1378    public void removeAll() throws SystemException {
1379        for (DLFileShortcut dlFileShortcut : findAll()) {
1380            remove(dlFileShortcut);
1381        }
1382    }
1383
1384    public int countByUuid(String uuid) throws SystemException {
1385        Object[] finderArgs = new Object[] { uuid };
1386
1387        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1388                finderArgs, this);
1389
1390        if (count == null) {
1391            Session session = null;
1392
1393            try {
1394                session = openSession();
1395
1396                StringBuilder query = new StringBuilder();
1397
1398                query.append("SELECT COUNT(*) ");
1399                query.append(
1400                    "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
1401
1402                if (uuid == null) {
1403                    query.append("uuid_ IS NULL");
1404                }
1405                else {
1406                    query.append("uuid_ = ?");
1407                }
1408
1409                query.append(" ");
1410
1411                Query q = session.createQuery(query.toString());
1412
1413                QueryPos qPos = QueryPos.getInstance(q);
1414
1415                if (uuid != null) {
1416                    qPos.add(uuid);
1417                }
1418
1419                count = (Long)q.uniqueResult();
1420            }
1421            catch (Exception e) {
1422                throw processException(e);
1423            }
1424            finally {
1425                if (count == null) {
1426                    count = Long.valueOf(0);
1427                }
1428
1429                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1430                    finderArgs, count);
1431
1432                closeSession(session);
1433            }
1434        }
1435
1436        return count.intValue();
1437    }
1438
1439    public int countByUUID_G(String uuid, long groupId)
1440        throws SystemException {
1441        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1442
1443        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1444                finderArgs, this);
1445
1446        if (count == null) {
1447            Session session = null;
1448
1449            try {
1450                session = openSession();
1451
1452                StringBuilder query = new StringBuilder();
1453
1454                query.append("SELECT COUNT(*) ");
1455                query.append(
1456                    "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
1457
1458                if (uuid == null) {
1459                    query.append("uuid_ IS NULL");
1460                }
1461                else {
1462                    query.append("uuid_ = ?");
1463                }
1464
1465                query.append(" AND ");
1466
1467                query.append("groupId = ?");
1468
1469                query.append(" ");
1470
1471                Query q = session.createQuery(query.toString());
1472
1473                QueryPos qPos = QueryPos.getInstance(q);
1474
1475                if (uuid != null) {
1476                    qPos.add(uuid);
1477                }
1478
1479                qPos.add(groupId);
1480
1481                count = (Long)q.uniqueResult();
1482            }
1483            catch (Exception e) {
1484                throw processException(e);
1485            }
1486            finally {
1487                if (count == null) {
1488                    count = Long.valueOf(0);
1489                }
1490
1491                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1492                    finderArgs, count);
1493
1494                closeSession(session);
1495            }
1496        }
1497
1498        return count.intValue();
1499    }
1500
1501    public int countByFolderId(long folderId) throws SystemException {
1502        Object[] finderArgs = new Object[] { new Long(folderId) };
1503
1504        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_FOLDERID,
1505                finderArgs, this);
1506
1507        if (count == null) {
1508            Session session = null;
1509
1510            try {
1511                session = openSession();
1512
1513                StringBuilder query = new StringBuilder();
1514
1515                query.append("SELECT COUNT(*) ");
1516                query.append(
1517                    "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
1518
1519                query.append("folderId = ?");
1520
1521                query.append(" ");
1522
1523                Query q = session.createQuery(query.toString());
1524
1525                QueryPos qPos = QueryPos.getInstance(q);
1526
1527                qPos.add(folderId);
1528
1529                count = (Long)q.uniqueResult();
1530            }
1531            catch (Exception e) {
1532                throw processException(e);
1533            }
1534            finally {
1535                if (count == null) {
1536                    count = Long.valueOf(0);
1537                }
1538
1539                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FOLDERID,
1540                    finderArgs, count);
1541
1542                closeSession(session);
1543            }
1544        }
1545
1546        return count.intValue();
1547    }
1548
1549    public int countByTF_TN(long toFolderId, String toName)
1550        throws SystemException {
1551        Object[] finderArgs = new Object[] { new Long(toFolderId), toName };
1552
1553        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TF_TN,
1554                finderArgs, this);
1555
1556        if (count == null) {
1557            Session session = null;
1558
1559            try {
1560                session = openSession();
1561
1562                StringBuilder query = new StringBuilder();
1563
1564                query.append("SELECT COUNT(*) ");
1565                query.append(
1566                    "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
1567
1568                query.append("toFolderId = ?");
1569
1570                query.append(" AND ");
1571
1572                if (toName == null) {
1573                    query.append("toName IS NULL");
1574                }
1575                else {
1576                    query.append("toName = ?");
1577                }
1578
1579                query.append(" ");
1580
1581                Query q = session.createQuery(query.toString());
1582
1583                QueryPos qPos = QueryPos.getInstance(q);
1584
1585                qPos.add(toFolderId);
1586
1587                if (toName != null) {
1588                    qPos.add(toName);
1589                }
1590
1591                count = (Long)q.uniqueResult();
1592            }
1593            catch (Exception e) {
1594                throw processException(e);
1595            }
1596            finally {
1597                if (count == null) {
1598                    count = Long.valueOf(0);
1599                }
1600
1601                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TF_TN,
1602                    finderArgs, count);
1603
1604                closeSession(session);
1605            }
1606        }
1607
1608        return count.intValue();
1609    }
1610
1611    public int countAll() throws SystemException {
1612        Object[] finderArgs = new Object[0];
1613
1614        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1615                finderArgs, this);
1616
1617        if (count == null) {
1618            Session session = null;
1619
1620            try {
1621                session = openSession();
1622
1623                Query q = session.createQuery(
1624                        "SELECT COUNT(*) FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut");
1625
1626                count = (Long)q.uniqueResult();
1627            }
1628            catch (Exception e) {
1629                throw processException(e);
1630            }
1631            finally {
1632                if (count == null) {
1633                    count = Long.valueOf(0);
1634                }
1635
1636                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1637                    count);
1638
1639                closeSession(session);
1640            }
1641        }
1642
1643        return count.intValue();
1644    }
1645
1646    public void afterPropertiesSet() {
1647        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1648                    com.liferay.portal.util.PropsUtil.get(
1649                        "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileShortcut")));
1650
1651        if (listenerClassNames.length > 0) {
1652            try {
1653                List<ModelListener<DLFileShortcut>> listenersList = new ArrayList<ModelListener<DLFileShortcut>>();
1654
1655                for (String listenerClassName : listenerClassNames) {
1656                    listenersList.add((ModelListener<DLFileShortcut>)Class.forName(
1657                            listenerClassName).newInstance());
1658                }
1659
1660                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1661            }
1662            catch (Exception e) {
1663                _log.error(e);
1664            }
1665        }
1666    }
1667
1668    @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistence.impl")
1669    protected com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistence dlFileEntryPersistence;
1670    @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFileRankPersistence.impl")
1671    protected com.liferay.portlet.documentlibrary.service.persistence.DLFileRankPersistence dlFileRankPersistence;
1672    @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFileShortcutPersistence.impl")
1673    protected com.liferay.portlet.documentlibrary.service.persistence.DLFileShortcutPersistence dlFileShortcutPersistence;
1674    @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFileVersionPersistence.impl")
1675    protected com.liferay.portlet.documentlibrary.service.persistence.DLFileVersionPersistence dlFileVersionPersistence;
1676    @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence.impl")
1677    protected com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence dlFolderPersistence;
1678    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1679    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1680    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1681    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1682    private static Log _log = LogFactoryUtil.getLog(DLFileShortcutPersistenceImpl.class);
1683}