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