1
14
15 package com.liferay.portlet.documentlibrary.service.persistence;
16
17 import com.liferay.portal.NoSuchModelException;
18 import com.liferay.portal.SystemException;
19 import com.liferay.portal.kernel.annotation.BeanReference;
20 import com.liferay.portal.kernel.cache.CacheRegistry;
21 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23 import com.liferay.portal.kernel.dao.orm.FinderPath;
24 import com.liferay.portal.kernel.dao.orm.Query;
25 import com.liferay.portal.kernel.dao.orm.QueryPos;
26 import com.liferay.portal.kernel.dao.orm.QueryUtil;
27 import com.liferay.portal.kernel.dao.orm.Session;
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.OrderByComparator;
32 import com.liferay.portal.kernel.util.StringBundler;
33 import com.liferay.portal.kernel.util.StringPool;
34 import com.liferay.portal.kernel.util.StringUtil;
35 import com.liferay.portal.kernel.util.Validator;
36 import com.liferay.portal.model.ModelListener;
37 import com.liferay.portal.service.persistence.BatchSessionUtil;
38 import com.liferay.portal.service.persistence.ResourcePersistence;
39 import com.liferay.portal.service.persistence.UserPersistence;
40 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41
42 import com.liferay.portlet.documentlibrary.NoSuchFileVersionException;
43 import com.liferay.portlet.documentlibrary.model.DLFileVersion;
44 import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionImpl;
45 import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionModelImpl;
46
47 import java.io.Serializable;
48
49 import java.util.ArrayList;
50 import java.util.Collections;
51 import java.util.List;
52
53
66 public class DLFileVersionPersistenceImpl extends BasePersistenceImpl<DLFileVersion>
67 implements DLFileVersionPersistence {
68 public static final String FINDER_CLASS_NAME_ENTITY = DLFileVersionImpl.class.getName();
69 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
70 ".List";
71 public static final FinderPath FINDER_PATH_FIND_BY_F_N = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
72 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
73 FINDER_CLASS_NAME_LIST, "findByF_N",
74 new String[] { Long.class.getName(), String.class.getName() });
75 public static final FinderPath FINDER_PATH_FIND_BY_OBC_F_N = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
76 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
77 FINDER_CLASS_NAME_LIST, "findByF_N",
78 new String[] {
79 Long.class.getName(), String.class.getName(),
80
81 "java.lang.Integer", "java.lang.Integer",
82 "com.liferay.portal.kernel.util.OrderByComparator"
83 });
84 public static final FinderPath FINDER_PATH_COUNT_BY_F_N = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
85 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
86 FINDER_CLASS_NAME_LIST, "countByF_N",
87 new String[] { Long.class.getName(), String.class.getName() });
88 public static final FinderPath FINDER_PATH_FETCH_BY_F_N_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
89 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
90 FINDER_CLASS_NAME_ENTITY, "fetchByF_N_V",
91 new String[] {
92 Long.class.getName(), String.class.getName(),
93 Double.class.getName()
94 });
95 public static final FinderPath FINDER_PATH_COUNT_BY_F_N_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
96 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
97 FINDER_CLASS_NAME_LIST, "countByF_N_V",
98 new String[] {
99 Long.class.getName(), String.class.getName(),
100 Double.class.getName()
101 });
102 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
103 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
104 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
105 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
106 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
107 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
108
109 public void cacheResult(DLFileVersion dlFileVersion) {
110 EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
111 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
112 dlFileVersion);
113
114 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_N_V,
115 new Object[] {
116 new Long(dlFileVersion.getFolderId()),
117
118 dlFileVersion.getName(), new Double(dlFileVersion.getVersion())
119 }, dlFileVersion);
120 }
121
122 public void cacheResult(List<DLFileVersion> dlFileVersions) {
123 for (DLFileVersion dlFileVersion : dlFileVersions) {
124 if (EntityCacheUtil.getResult(
125 DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
126 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
127 this) == null) {
128 cacheResult(dlFileVersion);
129 }
130 }
131 }
132
133 public void clearCache() {
134 CacheRegistry.clear(DLFileVersionImpl.class.getName());
135 EntityCacheUtil.clearCache(DLFileVersionImpl.class.getName());
136 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
137 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
138 }
139
140 public DLFileVersion create(long fileVersionId) {
141 DLFileVersion dlFileVersion = new DLFileVersionImpl();
142
143 dlFileVersion.setNew(true);
144 dlFileVersion.setPrimaryKey(fileVersionId);
145
146 return dlFileVersion;
147 }
148
149 public DLFileVersion remove(Serializable primaryKey)
150 throws NoSuchModelException, SystemException {
151 return remove(((Long)primaryKey).longValue());
152 }
153
154 public DLFileVersion remove(long fileVersionId)
155 throws NoSuchFileVersionException, SystemException {
156 Session session = null;
157
158 try {
159 session = openSession();
160
161 DLFileVersion dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
162 new Long(fileVersionId));
163
164 if (dlFileVersion == null) {
165 if (_log.isWarnEnabled()) {
166 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileVersionId);
167 }
168
169 throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
170 fileVersionId);
171 }
172
173 return remove(dlFileVersion);
174 }
175 catch (NoSuchFileVersionException nsee) {
176 throw nsee;
177 }
178 catch (Exception e) {
179 throw processException(e);
180 }
181 finally {
182 closeSession(session);
183 }
184 }
185
186 public DLFileVersion remove(DLFileVersion dlFileVersion)
187 throws SystemException {
188 for (ModelListener<DLFileVersion> listener : listeners) {
189 listener.onBeforeRemove(dlFileVersion);
190 }
191
192 dlFileVersion = removeImpl(dlFileVersion);
193
194 for (ModelListener<DLFileVersion> listener : listeners) {
195 listener.onAfterRemove(dlFileVersion);
196 }
197
198 return dlFileVersion;
199 }
200
201 protected DLFileVersion removeImpl(DLFileVersion dlFileVersion)
202 throws SystemException {
203 dlFileVersion = toUnwrappedModel(dlFileVersion);
204
205 Session session = null;
206
207 try {
208 session = openSession();
209
210 if (dlFileVersion.isCachedModel() || BatchSessionUtil.isEnabled()) {
211 Object staleObject = session.get(DLFileVersionImpl.class,
212 dlFileVersion.getPrimaryKeyObj());
213
214 if (staleObject != null) {
215 session.evict(staleObject);
216 }
217 }
218
219 session.delete(dlFileVersion);
220
221 session.flush();
222 }
223 catch (Exception e) {
224 throw processException(e);
225 }
226 finally {
227 closeSession(session);
228 }
229
230 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
231
232 DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
233
234 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_F_N_V,
235 new Object[] {
236 new Long(dlFileVersionModelImpl.getOriginalFolderId()),
237
238 dlFileVersionModelImpl.getOriginalName(),
239 new Double(dlFileVersionModelImpl.getOriginalVersion())
240 });
241
242 EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
243 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
244
245 return dlFileVersion;
246 }
247
248
251 public DLFileVersion update(DLFileVersion dlFileVersion)
252 throws SystemException {
253 if (_log.isWarnEnabled()) {
254 _log.warn(
255 "Using the deprecated update(DLFileVersion dlFileVersion) method. Use update(DLFileVersion dlFileVersion, boolean merge) instead.");
256 }
257
258 return update(dlFileVersion, false);
259 }
260
261 public DLFileVersion updateImpl(
262 com.liferay.portlet.documentlibrary.model.DLFileVersion dlFileVersion,
263 boolean merge) throws SystemException {
264 dlFileVersion = toUnwrappedModel(dlFileVersion);
265
266 boolean isNew = dlFileVersion.isNew();
267
268 DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
269
270 Session session = null;
271
272 try {
273 session = openSession();
274
275 BatchSessionUtil.update(session, dlFileVersion, merge);
276
277 dlFileVersion.setNew(false);
278 }
279 catch (Exception e) {
280 throw processException(e);
281 }
282 finally {
283 closeSession(session);
284 }
285
286 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
287
288 EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
289 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
290 dlFileVersion);
291
292 if (!isNew &&
293 ((dlFileVersion.getFolderId() != dlFileVersionModelImpl.getOriginalFolderId()) ||
294 !Validator.equals(dlFileVersion.getName(),
295 dlFileVersionModelImpl.getOriginalName()) ||
296 (dlFileVersion.getVersion() != dlFileVersionModelImpl.getOriginalVersion()))) {
297 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_F_N_V,
298 new Object[] {
299 new Long(dlFileVersionModelImpl.getOriginalFolderId()),
300
301 dlFileVersionModelImpl.getOriginalName(),
302 new Double(dlFileVersionModelImpl.getOriginalVersion())
303 });
304 }
305
306 if (isNew ||
307 ((dlFileVersion.getFolderId() != dlFileVersionModelImpl.getOriginalFolderId()) ||
308 !Validator.equals(dlFileVersion.getName(),
309 dlFileVersionModelImpl.getOriginalName()) ||
310 (dlFileVersion.getVersion() != dlFileVersionModelImpl.getOriginalVersion()))) {
311 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_N_V,
312 new Object[] {
313 new Long(dlFileVersion.getFolderId()),
314
315 dlFileVersion.getName(), new Double(dlFileVersion.getVersion())
316 }, dlFileVersion);
317 }
318
319 return dlFileVersion;
320 }
321
322 protected DLFileVersion toUnwrappedModel(DLFileVersion dlFileVersion) {
323 if (dlFileVersion instanceof DLFileVersionImpl) {
324 return dlFileVersion;
325 }
326
327 DLFileVersionImpl dlFileVersionImpl = new DLFileVersionImpl();
328
329 dlFileVersionImpl.setNew(dlFileVersion.isNew());
330 dlFileVersionImpl.setPrimaryKey(dlFileVersion.getPrimaryKey());
331
332 dlFileVersionImpl.setFileVersionId(dlFileVersion.getFileVersionId());
333 dlFileVersionImpl.setGroupId(dlFileVersion.getGroupId());
334 dlFileVersionImpl.setCompanyId(dlFileVersion.getCompanyId());
335 dlFileVersionImpl.setUserId(dlFileVersion.getUserId());
336 dlFileVersionImpl.setUserName(dlFileVersion.getUserName());
337 dlFileVersionImpl.setCreateDate(dlFileVersion.getCreateDate());
338 dlFileVersionImpl.setFolderId(dlFileVersion.getFolderId());
339 dlFileVersionImpl.setName(dlFileVersion.getName());
340 dlFileVersionImpl.setDescription(dlFileVersion.getDescription());
341 dlFileVersionImpl.setVersion(dlFileVersion.getVersion());
342 dlFileVersionImpl.setSize(dlFileVersion.getSize());
343
344 return dlFileVersionImpl;
345 }
346
347 public DLFileVersion findByPrimaryKey(Serializable primaryKey)
348 throws NoSuchModelException, SystemException {
349 return findByPrimaryKey(((Long)primaryKey).longValue());
350 }
351
352 public DLFileVersion findByPrimaryKey(long fileVersionId)
353 throws NoSuchFileVersionException, SystemException {
354 DLFileVersion dlFileVersion = fetchByPrimaryKey(fileVersionId);
355
356 if (dlFileVersion == null) {
357 if (_log.isWarnEnabled()) {
358 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileVersionId);
359 }
360
361 throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
362 fileVersionId);
363 }
364
365 return dlFileVersion;
366 }
367
368 public DLFileVersion fetchByPrimaryKey(Serializable primaryKey)
369 throws SystemException {
370 return fetchByPrimaryKey(((Long)primaryKey).longValue());
371 }
372
373 public DLFileVersion fetchByPrimaryKey(long fileVersionId)
374 throws SystemException {
375 DLFileVersion dlFileVersion = (DLFileVersion)EntityCacheUtil.getResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
376 DLFileVersionImpl.class, fileVersionId, this);
377
378 if (dlFileVersion == null) {
379 Session session = null;
380
381 try {
382 session = openSession();
383
384 dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
385 new Long(fileVersionId));
386 }
387 catch (Exception e) {
388 throw processException(e);
389 }
390 finally {
391 if (dlFileVersion != null) {
392 cacheResult(dlFileVersion);
393 }
394
395 closeSession(session);
396 }
397 }
398
399 return dlFileVersion;
400 }
401
402 public List<DLFileVersion> findByF_N(long folderId, String name)
403 throws SystemException {
404 Object[] finderArgs = new Object[] { new Long(folderId), name };
405
406 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_F_N,
407 finderArgs, this);
408
409 if (list == null) {
410 Session session = null;
411
412 try {
413 session = openSession();
414
415 StringBundler query = new StringBundler(4);
416
417 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
418
419 query.append(_FINDER_COLUMN_F_N_FOLDERID_2);
420
421 if (name == null) {
422 query.append(_FINDER_COLUMN_F_N_NAME_1);
423 }
424 else {
425 if (name.equals(StringPool.BLANK)) {
426 query.append(_FINDER_COLUMN_F_N_NAME_3);
427 }
428 else {
429 query.append(_FINDER_COLUMN_F_N_NAME_2);
430 }
431 }
432
433 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
434
435 String sql = query.toString();
436
437 Query q = session.createQuery(sql);
438
439 QueryPos qPos = QueryPos.getInstance(q);
440
441 qPos.add(folderId);
442
443 if (name != null) {
444 qPos.add(name);
445 }
446
447 list = q.list();
448 }
449 catch (Exception e) {
450 throw processException(e);
451 }
452 finally {
453 if (list == null) {
454 list = new ArrayList<DLFileVersion>();
455 }
456
457 cacheResult(list);
458
459 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_F_N, finderArgs,
460 list);
461
462 closeSession(session);
463 }
464 }
465
466 return list;
467 }
468
469 public List<DLFileVersion> findByF_N(long folderId, String name, int start,
470 int end) throws SystemException {
471 return findByF_N(folderId, name, start, end, null);
472 }
473
474 public List<DLFileVersion> findByF_N(long folderId, String name, int start,
475 int end, OrderByComparator orderByComparator) throws SystemException {
476 Object[] finderArgs = new Object[] {
477 new Long(folderId),
478
479 name,
480
481 String.valueOf(start), String.valueOf(end),
482 String.valueOf(orderByComparator)
483 };
484
485 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_F_N,
486 finderArgs, this);
487
488 if (list == null) {
489 Session session = null;
490
491 try {
492 session = openSession();
493
494 StringBundler query = null;
495
496 if (orderByComparator != null) {
497 query = new StringBundler(4 +
498 (orderByComparator.getOrderByFields().length * 3));
499 }
500 else {
501 query = new StringBundler(4);
502 }
503
504 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
505
506 query.append(_FINDER_COLUMN_F_N_FOLDERID_2);
507
508 if (name == null) {
509 query.append(_FINDER_COLUMN_F_N_NAME_1);
510 }
511 else {
512 if (name.equals(StringPool.BLANK)) {
513 query.append(_FINDER_COLUMN_F_N_NAME_3);
514 }
515 else {
516 query.append(_FINDER_COLUMN_F_N_NAME_2);
517 }
518 }
519
520 if (orderByComparator != null) {
521 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
522 orderByComparator);
523 }
524
525 else {
526 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
527 }
528
529 String sql = query.toString();
530
531 Query q = session.createQuery(sql);
532
533 QueryPos qPos = QueryPos.getInstance(q);
534
535 qPos.add(folderId);
536
537 if (name != null) {
538 qPos.add(name);
539 }
540
541 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
542 start, end);
543 }
544 catch (Exception e) {
545 throw processException(e);
546 }
547 finally {
548 if (list == null) {
549 list = new ArrayList<DLFileVersion>();
550 }
551
552 cacheResult(list);
553
554 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_F_N,
555 finderArgs, list);
556
557 closeSession(session);
558 }
559 }
560
561 return list;
562 }
563
564 public DLFileVersion findByF_N_First(long folderId, String name,
565 OrderByComparator orderByComparator)
566 throws NoSuchFileVersionException, SystemException {
567 List<DLFileVersion> list = findByF_N(folderId, name, 0, 1,
568 orderByComparator);
569
570 if (list.isEmpty()) {
571 StringBundler msg = new StringBundler(6);
572
573 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
574
575 msg.append("folderId=");
576 msg.append(folderId);
577
578 msg.append(", name=");
579 msg.append(name);
580
581 msg.append(StringPool.CLOSE_CURLY_BRACE);
582
583 throw new NoSuchFileVersionException(msg.toString());
584 }
585 else {
586 return list.get(0);
587 }
588 }
589
590 public DLFileVersion findByF_N_Last(long folderId, String name,
591 OrderByComparator orderByComparator)
592 throws NoSuchFileVersionException, SystemException {
593 int count = countByF_N(folderId, name);
594
595 List<DLFileVersion> list = findByF_N(folderId, name, count - 1, count,
596 orderByComparator);
597
598 if (list.isEmpty()) {
599 StringBundler msg = new StringBundler(6);
600
601 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
602
603 msg.append("folderId=");
604 msg.append(folderId);
605
606 msg.append(", name=");
607 msg.append(name);
608
609 msg.append(StringPool.CLOSE_CURLY_BRACE);
610
611 throw new NoSuchFileVersionException(msg.toString());
612 }
613 else {
614 return list.get(0);
615 }
616 }
617
618 public DLFileVersion[] findByF_N_PrevAndNext(long fileVersionId,
619 long folderId, String name, OrderByComparator orderByComparator)
620 throws NoSuchFileVersionException, SystemException {
621 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
622
623 int count = countByF_N(folderId, name);
624
625 Session session = null;
626
627 try {
628 session = openSession();
629
630 StringBundler query = null;
631
632 if (orderByComparator != null) {
633 query = new StringBundler(4 +
634 (orderByComparator.getOrderByFields().length * 3));
635 }
636 else {
637 query = new StringBundler(4);
638 }
639
640 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
641
642 query.append(_FINDER_COLUMN_F_N_FOLDERID_2);
643
644 if (name == null) {
645 query.append(_FINDER_COLUMN_F_N_NAME_1);
646 }
647 else {
648 if (name.equals(StringPool.BLANK)) {
649 query.append(_FINDER_COLUMN_F_N_NAME_3);
650 }
651 else {
652 query.append(_FINDER_COLUMN_F_N_NAME_2);
653 }
654 }
655
656 if (orderByComparator != null) {
657 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
658 orderByComparator);
659 }
660
661 else {
662 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
663 }
664
665 String sql = query.toString();
666
667 Query q = session.createQuery(sql);
668
669 QueryPos qPos = QueryPos.getInstance(q);
670
671 qPos.add(folderId);
672
673 if (name != null) {
674 qPos.add(name);
675 }
676
677 Object[] objArray = QueryUtil.getPrevAndNext(q, count,
678 orderByComparator, dlFileVersion);
679
680 DLFileVersion[] array = new DLFileVersionImpl[3];
681
682 array[0] = (DLFileVersion)objArray[0];
683 array[1] = (DLFileVersion)objArray[1];
684 array[2] = (DLFileVersion)objArray[2];
685
686 return array;
687 }
688 catch (Exception e) {
689 throw processException(e);
690 }
691 finally {
692 closeSession(session);
693 }
694 }
695
696 public DLFileVersion findByF_N_V(long folderId, String name, double version)
697 throws NoSuchFileVersionException, SystemException {
698 DLFileVersion dlFileVersion = fetchByF_N_V(folderId, name, version);
699
700 if (dlFileVersion == null) {
701 StringBundler msg = new StringBundler(8);
702
703 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
704
705 msg.append("folderId=");
706 msg.append(folderId);
707
708 msg.append(", name=");
709 msg.append(name);
710
711 msg.append(", version=");
712 msg.append(version);
713
714 msg.append(StringPool.CLOSE_CURLY_BRACE);
715
716 if (_log.isWarnEnabled()) {
717 _log.warn(msg.toString());
718 }
719
720 throw new NoSuchFileVersionException(msg.toString());
721 }
722
723 return dlFileVersion;
724 }
725
726 public DLFileVersion fetchByF_N_V(long folderId, String name, double version)
727 throws SystemException {
728 return fetchByF_N_V(folderId, name, version, true);
729 }
730
731 public DLFileVersion fetchByF_N_V(long folderId, String name,
732 double version, boolean retrieveFromCache) throws SystemException {
733 Object[] finderArgs = new Object[] {
734 new Long(folderId),
735
736 name, new Double(version)
737 };
738
739 Object result = null;
740
741 if (retrieveFromCache) {
742 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_F_N_V,
743 finderArgs, this);
744 }
745
746 if (result == null) {
747 Session session = null;
748
749 try {
750 session = openSession();
751
752 StringBundler query = new StringBundler(5);
753
754 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
755
756 query.append(_FINDER_COLUMN_F_N_V_FOLDERID_2);
757
758 if (name == null) {
759 query.append(_FINDER_COLUMN_F_N_V_NAME_1);
760 }
761 else {
762 if (name.equals(StringPool.BLANK)) {
763 query.append(_FINDER_COLUMN_F_N_V_NAME_3);
764 }
765 else {
766 query.append(_FINDER_COLUMN_F_N_V_NAME_2);
767 }
768 }
769
770 query.append(_FINDER_COLUMN_F_N_V_VERSION_2);
771
772 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
773
774 String sql = query.toString();
775
776 Query q = session.createQuery(sql);
777
778 QueryPos qPos = QueryPos.getInstance(q);
779
780 qPos.add(folderId);
781
782 if (name != null) {
783 qPos.add(name);
784 }
785
786 qPos.add(version);
787
788 List<DLFileVersion> list = q.list();
789
790 result = list;
791
792 DLFileVersion dlFileVersion = null;
793
794 if (list.isEmpty()) {
795 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_N_V,
796 finderArgs, list);
797 }
798 else {
799 dlFileVersion = list.get(0);
800
801 cacheResult(dlFileVersion);
802
803 if ((dlFileVersion.getFolderId() != folderId) ||
804 (dlFileVersion.getName() == null) ||
805 !dlFileVersion.getName().equals(name) ||
806 (dlFileVersion.getVersion() != version)) {
807 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_N_V,
808 finderArgs, dlFileVersion);
809 }
810 }
811
812 return dlFileVersion;
813 }
814 catch (Exception e) {
815 throw processException(e);
816 }
817 finally {
818 if (result == null) {
819 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_N_V,
820 finderArgs, new ArrayList<DLFileVersion>());
821 }
822
823 closeSession(session);
824 }
825 }
826 else {
827 if (result instanceof List<?>) {
828 return null;
829 }
830 else {
831 return (DLFileVersion)result;
832 }
833 }
834 }
835
836 public List<DLFileVersion> findAll() throws SystemException {
837 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
838 }
839
840 public List<DLFileVersion> findAll(int start, int end)
841 throws SystemException {
842 return findAll(start, end, null);
843 }
844
845 public List<DLFileVersion> findAll(int start, int end,
846 OrderByComparator orderByComparator) throws SystemException {
847 Object[] finderArgs = new Object[] {
848 String.valueOf(start), String.valueOf(end),
849 String.valueOf(orderByComparator)
850 };
851
852 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
853 finderArgs, this);
854
855 if (list == null) {
856 Session session = null;
857
858 try {
859 session = openSession();
860
861 StringBundler query = null;
862 String sql = null;
863
864 if (orderByComparator != null) {
865 query = new StringBundler(2 +
866 (orderByComparator.getOrderByFields().length * 3));
867
868 query.append(_SQL_SELECT_DLFILEVERSION);
869
870 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
871 orderByComparator);
872
873 sql = query.toString();
874 }
875
876 else {
877 sql = _SQL_SELECT_DLFILEVERSION.concat(DLFileVersionModelImpl.ORDER_BY_JPQL);
878 }
879
880 Query q = session.createQuery(sql);
881
882 if (orderByComparator == null) {
883 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
884 start, end, false);
885
886 Collections.sort(list);
887 }
888 else {
889 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
890 start, end);
891 }
892 }
893 catch (Exception e) {
894 throw processException(e);
895 }
896 finally {
897 if (list == null) {
898 list = new ArrayList<DLFileVersion>();
899 }
900
901 cacheResult(list);
902
903 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
904
905 closeSession(session);
906 }
907 }
908
909 return list;
910 }
911
912 public void removeByF_N(long folderId, String name)
913 throws SystemException {
914 for (DLFileVersion dlFileVersion : findByF_N(folderId, name)) {
915 remove(dlFileVersion);
916 }
917 }
918
919 public void removeByF_N_V(long folderId, String name, double version)
920 throws NoSuchFileVersionException, SystemException {
921 DLFileVersion dlFileVersion = findByF_N_V(folderId, name, version);
922
923 remove(dlFileVersion);
924 }
925
926 public void removeAll() throws SystemException {
927 for (DLFileVersion dlFileVersion : findAll()) {
928 remove(dlFileVersion);
929 }
930 }
931
932 public int countByF_N(long folderId, String name) throws SystemException {
933 Object[] finderArgs = new Object[] { new Long(folderId), name };
934
935 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_F_N,
936 finderArgs, this);
937
938 if (count == null) {
939 Session session = null;
940
941 try {
942 session = openSession();
943
944 StringBundler query = new StringBundler(3);
945
946 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
947
948 query.append(_FINDER_COLUMN_F_N_FOLDERID_2);
949
950 if (name == null) {
951 query.append(_FINDER_COLUMN_F_N_NAME_1);
952 }
953 else {
954 if (name.equals(StringPool.BLANK)) {
955 query.append(_FINDER_COLUMN_F_N_NAME_3);
956 }
957 else {
958 query.append(_FINDER_COLUMN_F_N_NAME_2);
959 }
960 }
961
962 String sql = query.toString();
963
964 Query q = session.createQuery(sql);
965
966 QueryPos qPos = QueryPos.getInstance(q);
967
968 qPos.add(folderId);
969
970 if (name != null) {
971 qPos.add(name);
972 }
973
974 count = (Long)q.uniqueResult();
975 }
976 catch (Exception e) {
977 throw processException(e);
978 }
979 finally {
980 if (count == null) {
981 count = Long.valueOf(0);
982 }
983
984 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_N, finderArgs,
985 count);
986
987 closeSession(session);
988 }
989 }
990
991 return count.intValue();
992 }
993
994 public int countByF_N_V(long folderId, String name, double version)
995 throws SystemException {
996 Object[] finderArgs = new Object[] {
997 new Long(folderId),
998
999 name, new Double(version)
1000 };
1001
1002 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_F_N_V,
1003 finderArgs, this);
1004
1005 if (count == null) {
1006 Session session = null;
1007
1008 try {
1009 session = openSession();
1010
1011 StringBundler query = new StringBundler(4);
1012
1013 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1014
1015 query.append(_FINDER_COLUMN_F_N_V_FOLDERID_2);
1016
1017 if (name == null) {
1018 query.append(_FINDER_COLUMN_F_N_V_NAME_1);
1019 }
1020 else {
1021 if (name.equals(StringPool.BLANK)) {
1022 query.append(_FINDER_COLUMN_F_N_V_NAME_3);
1023 }
1024 else {
1025 query.append(_FINDER_COLUMN_F_N_V_NAME_2);
1026 }
1027 }
1028
1029 query.append(_FINDER_COLUMN_F_N_V_VERSION_2);
1030
1031 String sql = query.toString();
1032
1033 Query q = session.createQuery(sql);
1034
1035 QueryPos qPos = QueryPos.getInstance(q);
1036
1037 qPos.add(folderId);
1038
1039 if (name != null) {
1040 qPos.add(name);
1041 }
1042
1043 qPos.add(version);
1044
1045 count = (Long)q.uniqueResult();
1046 }
1047 catch (Exception e) {
1048 throw processException(e);
1049 }
1050 finally {
1051 if (count == null) {
1052 count = Long.valueOf(0);
1053 }
1054
1055 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_N_V,
1056 finderArgs, count);
1057
1058 closeSession(session);
1059 }
1060 }
1061
1062 return count.intValue();
1063 }
1064
1065 public int countAll() throws SystemException {
1066 Object[] finderArgs = new Object[0];
1067
1068 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1069 finderArgs, this);
1070
1071 if (count == null) {
1072 Session session = null;
1073
1074 try {
1075 session = openSession();
1076
1077 Query q = session.createQuery(_SQL_COUNT_DLFILEVERSION);
1078
1079 count = (Long)q.uniqueResult();
1080 }
1081 catch (Exception e) {
1082 throw processException(e);
1083 }
1084 finally {
1085 if (count == null) {
1086 count = Long.valueOf(0);
1087 }
1088
1089 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1090 count);
1091
1092 closeSession(session);
1093 }
1094 }
1095
1096 return count.intValue();
1097 }
1098
1099 public void afterPropertiesSet() {
1100 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1101 com.liferay.portal.util.PropsUtil.get(
1102 "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileVersion")));
1103
1104 if (listenerClassNames.length > 0) {
1105 try {
1106 List<ModelListener<DLFileVersion>> listenersList = new ArrayList<ModelListener<DLFileVersion>>();
1107
1108 for (String listenerClassName : listenerClassNames) {
1109 listenersList.add((ModelListener<DLFileVersion>)Class.forName(
1110 listenerClassName).newInstance());
1111 }
1112
1113 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1114 }
1115 catch (Exception e) {
1116 _log.error(e);
1117 }
1118 }
1119 }
1120
1121 @BeanReference(type = DLFileEntryPersistence.class)
1122 protected DLFileEntryPersistence dlFileEntryPersistence;
1123 @BeanReference(type = DLFileRankPersistence.class)
1124 protected DLFileRankPersistence dlFileRankPersistence;
1125 @BeanReference(type = DLFileShortcutPersistence.class)
1126 protected DLFileShortcutPersistence dlFileShortcutPersistence;
1127 @BeanReference(type = DLFileVersionPersistence.class)
1128 protected DLFileVersionPersistence dlFileVersionPersistence;
1129 @BeanReference(type = DLFolderPersistence.class)
1130 protected DLFolderPersistence dlFolderPersistence;
1131 @BeanReference(type = ResourcePersistence.class)
1132 protected ResourcePersistence resourcePersistence;
1133 @BeanReference(type = UserPersistence.class)
1134 protected UserPersistence userPersistence;
1135 private static final String _SQL_SELECT_DLFILEVERSION = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion";
1136 private static final String _SQL_SELECT_DLFILEVERSION_WHERE = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion WHERE ";
1137 private static final String _SQL_COUNT_DLFILEVERSION = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion";
1138 private static final String _SQL_COUNT_DLFILEVERSION_WHERE = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion WHERE ";
1139 private static final String _FINDER_COLUMN_F_N_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
1140 private static final String _FINDER_COLUMN_F_N_NAME_1 = "dlFileVersion.name IS NULL";
1141 private static final String _FINDER_COLUMN_F_N_NAME_2 = "dlFileVersion.name = ?";
1142 private static final String _FINDER_COLUMN_F_N_NAME_3 = "(dlFileVersion.name IS NULL OR dlFileVersion.name = ?)";
1143 private static final String _FINDER_COLUMN_F_N_V_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
1144 private static final String _FINDER_COLUMN_F_N_V_NAME_1 = "dlFileVersion.name IS NULL AND ";
1145 private static final String _FINDER_COLUMN_F_N_V_NAME_2 = "dlFileVersion.name = ? AND ";
1146 private static final String _FINDER_COLUMN_F_N_V_NAME_3 = "(dlFileVersion.name IS NULL OR dlFileVersion.name = ?) AND ";
1147 private static final String _FINDER_COLUMN_F_N_V_VERSION_2 = "dlFileVersion.version = ?";
1148 private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileVersion.";
1149 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileVersion exists with the primary key ";
1150 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileVersion exists with the key {";
1151 private static Log _log = LogFactoryUtil.getLog(DLFileVersionPersistenceImpl.class);
1152}