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