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