001
014
015 package com.liferay.portlet.documentlibrary.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.service.persistence.BatchSessionUtil;
041 import com.liferay.portal.service.persistence.ResourcePersistence;
042 import com.liferay.portal.service.persistence.UserPersistence;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import com.liferay.portlet.documentlibrary.NoSuchFileVersionException;
046 import com.liferay.portlet.documentlibrary.model.DLFileVersion;
047 import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionImpl;
048 import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionModelImpl;
049
050 import java.io.Serializable;
051
052 import java.util.ArrayList;
053 import java.util.Collections;
054 import java.util.List;
055
056
068 public class DLFileVersionPersistenceImpl extends BasePersistenceImpl<DLFileVersion>
069 implements DLFileVersionPersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = DLFileVersionImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
081 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
082 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083 "findByUuid",
084 new String[] {
085 String.class.getName(),
086
087 "java.lang.Integer", "java.lang.Integer",
088 "com.liferay.portal.kernel.util.OrderByComparator"
089 });
090 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
091 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
092 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
093 "findByUuid", new String[] { String.class.getName() },
094 DLFileVersionModelImpl.UUID_COLUMN_BITMASK);
095 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
096 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
098 new String[] { String.class.getName() });
099 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
100 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
101 DLFileVersionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
102 new String[] { String.class.getName(), Long.class.getName() },
103 DLFileVersionModelImpl.UUID_COLUMN_BITMASK |
104 DLFileVersionModelImpl.GROUPID_COLUMN_BITMASK);
105 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
106 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
108 new String[] { String.class.getName(), Long.class.getName() });
109 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID =
110 new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
111 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
112 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
113 "findByFileEntryId",
114 new String[] {
115 Long.class.getName(),
116
117 "java.lang.Integer", "java.lang.Integer",
118 "com.liferay.portal.kernel.util.OrderByComparator"
119 });
120 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID =
121 new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
122 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
123 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
124 "findByFileEntryId", new String[] { Long.class.getName() },
125 DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK);
126 public static final FinderPath FINDER_PATH_COUNT_BY_FILEENTRYID = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
127 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
128 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFileEntryId",
129 new String[] { Long.class.getName() });
130 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_MIMETYPE = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
131 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
132 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
133 "findByMimeType",
134 new String[] {
135 String.class.getName(),
136
137 "java.lang.Integer", "java.lang.Integer",
138 "com.liferay.portal.kernel.util.OrderByComparator"
139 });
140 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE =
141 new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
142 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
143 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
144 "findByMimeType", new String[] { String.class.getName() },
145 DLFileVersionModelImpl.MIMETYPE_COLUMN_BITMASK);
146 public static final FinderPath FINDER_PATH_COUNT_BY_MIMETYPE = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
147 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
148 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByMimeType",
149 new String[] { String.class.getName() });
150 public static final FinderPath FINDER_PATH_FETCH_BY_F_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
151 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
152 DLFileVersionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByF_V",
153 new String[] { Long.class.getName(), String.class.getName() },
154 DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
155 DLFileVersionModelImpl.VERSION_COLUMN_BITMASK);
156 public static final FinderPath FINDER_PATH_COUNT_BY_F_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
157 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
158 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByF_V",
159 new String[] { Long.class.getName(), String.class.getName() });
160 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
161 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
162 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
163 "findByF_S",
164 new String[] {
165 Long.class.getName(), Integer.class.getName(),
166
167 "java.lang.Integer", "java.lang.Integer",
168 "com.liferay.portal.kernel.util.OrderByComparator"
169 });
170 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
171 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
172 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
173 "findByF_S",
174 new String[] { Long.class.getName(), Integer.class.getName() },
175 DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
176 DLFileVersionModelImpl.STATUS_COLUMN_BITMASK);
177 public static final FinderPath FINDER_PATH_COUNT_BY_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
178 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
179 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByF_S",
180 new String[] { Long.class.getName(), Integer.class.getName() });
181 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
182 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
183 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
184 "findByG_F_S",
185 new String[] {
186 Long.class.getName(), Long.class.getName(),
187 Integer.class.getName(),
188
189 "java.lang.Integer", "java.lang.Integer",
190 "com.liferay.portal.kernel.util.OrderByComparator"
191 });
192 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
193 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
194 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
195 "findByG_F_S",
196 new String[] {
197 Long.class.getName(), Long.class.getName(),
198 Integer.class.getName()
199 },
200 DLFileVersionModelImpl.GROUPID_COLUMN_BITMASK |
201 DLFileVersionModelImpl.FOLDERID_COLUMN_BITMASK |
202 DLFileVersionModelImpl.STATUS_COLUMN_BITMASK);
203 public static final FinderPath FINDER_PATH_COUNT_BY_G_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
204 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
205 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_F_S",
206 new String[] {
207 Long.class.getName(), Long.class.getName(),
208 Integer.class.getName()
209 });
210 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_T_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
211 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
212 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
213 "findByG_F_T_V",
214 new String[] {
215 Long.class.getName(), Long.class.getName(),
216 String.class.getName(), String.class.getName(),
217
218 "java.lang.Integer", "java.lang.Integer",
219 "com.liferay.portal.kernel.util.OrderByComparator"
220 });
221 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V =
222 new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
223 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
224 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
225 "findByG_F_T_V",
226 new String[] {
227 Long.class.getName(), Long.class.getName(),
228 String.class.getName(), String.class.getName()
229 },
230 DLFileVersionModelImpl.GROUPID_COLUMN_BITMASK |
231 DLFileVersionModelImpl.FOLDERID_COLUMN_BITMASK |
232 DLFileVersionModelImpl.TITLE_COLUMN_BITMASK |
233 DLFileVersionModelImpl.VERSION_COLUMN_BITMASK);
234 public static final FinderPath FINDER_PATH_COUNT_BY_G_F_T_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
235 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
236 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_F_T_V",
237 new String[] {
238 Long.class.getName(), Long.class.getName(),
239 String.class.getName(), String.class.getName()
240 });
241 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
242 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
243 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
244 "findAll", new String[0]);
245 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
246 DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
247 DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
248 "findAll", new String[0]);
249 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
250 DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
251 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
252
253
258 public void cacheResult(DLFileVersion dlFileVersion) {
259 EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
260 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
261 dlFileVersion);
262
263 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
264 new Object[] {
265 dlFileVersion.getUuid(),
266 Long.valueOf(dlFileVersion.getGroupId())
267 }, dlFileVersion);
268
269 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_V,
270 new Object[] {
271 Long.valueOf(dlFileVersion.getFileEntryId()),
272
273 dlFileVersion.getVersion()
274 }, dlFileVersion);
275
276 dlFileVersion.resetOriginalValues();
277 }
278
279
284 public void cacheResult(List<DLFileVersion> dlFileVersions) {
285 for (DLFileVersion dlFileVersion : dlFileVersions) {
286 if (EntityCacheUtil.getResult(
287 DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
288 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey()) == null) {
289 cacheResult(dlFileVersion);
290 }
291 else {
292 dlFileVersion.resetOriginalValues();
293 }
294 }
295 }
296
297
304 @Override
305 public void clearCache() {
306 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
307 CacheRegistryUtil.clear(DLFileVersionImpl.class.getName());
308 }
309
310 EntityCacheUtil.clearCache(DLFileVersionImpl.class.getName());
311
312 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
313 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
314 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
315 }
316
317
324 @Override
325 public void clearCache(DLFileVersion dlFileVersion) {
326 EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
327 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
328
329 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
330 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
331
332 clearUniqueFindersCache(dlFileVersion);
333 }
334
335 @Override
336 public void clearCache(List<DLFileVersion> dlFileVersions) {
337 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
338 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
339
340 for (DLFileVersion dlFileVersion : dlFileVersions) {
341 EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
342 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
343
344 clearUniqueFindersCache(dlFileVersion);
345 }
346 }
347
348 protected void cacheUniqueFindersCache(DLFileVersion dlFileVersion) {
349 if (dlFileVersion.isNew()) {
350 Object[] args = new Object[] {
351 dlFileVersion.getUuid(),
352 Long.valueOf(dlFileVersion.getGroupId())
353 };
354
355 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
356 Long.valueOf(1));
357 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
358 dlFileVersion);
359
360 args = new Object[] {
361 Long.valueOf(dlFileVersion.getFileEntryId()),
362
363 dlFileVersion.getVersion()
364 };
365
366 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_V, args,
367 Long.valueOf(1));
368 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_V, args,
369 dlFileVersion);
370 }
371 else {
372 DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
373
374 if ((dlFileVersionModelImpl.getColumnBitmask() &
375 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
376 Object[] args = new Object[] {
377 dlFileVersion.getUuid(),
378 Long.valueOf(dlFileVersion.getGroupId())
379 };
380
381 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
382 Long.valueOf(1));
383 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
384 dlFileVersion);
385 }
386
387 if ((dlFileVersionModelImpl.getColumnBitmask() &
388 FINDER_PATH_FETCH_BY_F_V.getColumnBitmask()) != 0) {
389 Object[] args = new Object[] {
390 Long.valueOf(dlFileVersion.getFileEntryId()),
391
392 dlFileVersion.getVersion()
393 };
394
395 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_V, args,
396 Long.valueOf(1));
397 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_V, args,
398 dlFileVersion);
399 }
400 }
401 }
402
403 protected void clearUniqueFindersCache(DLFileVersion dlFileVersion) {
404 DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
405
406 Object[] args = new Object[] {
407 dlFileVersion.getUuid(),
408 Long.valueOf(dlFileVersion.getGroupId())
409 };
410
411 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
412 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
413
414 if ((dlFileVersionModelImpl.getColumnBitmask() &
415 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
416 args = new Object[] {
417 dlFileVersionModelImpl.getOriginalUuid(),
418 Long.valueOf(dlFileVersionModelImpl.getOriginalGroupId())
419 };
420
421 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
422 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
423 }
424
425 args = new Object[] {
426 Long.valueOf(dlFileVersion.getFileEntryId()),
427
428 dlFileVersion.getVersion()
429 };
430
431 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_F_V, args);
432 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_F_V, args);
433
434 if ((dlFileVersionModelImpl.getColumnBitmask() &
435 FINDER_PATH_FETCH_BY_F_V.getColumnBitmask()) != 0) {
436 args = new Object[] {
437 Long.valueOf(dlFileVersionModelImpl.getOriginalFileEntryId()),
438
439 dlFileVersionModelImpl.getOriginalVersion()
440 };
441
442 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_F_V, args);
443 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_F_V, args);
444 }
445 }
446
447
453 public DLFileVersion create(long fileVersionId) {
454 DLFileVersion dlFileVersion = new DLFileVersionImpl();
455
456 dlFileVersion.setNew(true);
457 dlFileVersion.setPrimaryKey(fileVersionId);
458
459 String uuid = PortalUUIDUtil.generate();
460
461 dlFileVersion.setUuid(uuid);
462
463 return dlFileVersion;
464 }
465
466
474 public DLFileVersion remove(long fileVersionId)
475 throws NoSuchFileVersionException, SystemException {
476 return remove(Long.valueOf(fileVersionId));
477 }
478
479
487 @Override
488 public DLFileVersion remove(Serializable primaryKey)
489 throws NoSuchFileVersionException, SystemException {
490 Session session = null;
491
492 try {
493 session = openSession();
494
495 DLFileVersion dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
496 primaryKey);
497
498 if (dlFileVersion == null) {
499 if (_log.isWarnEnabled()) {
500 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
501 }
502
503 throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
504 primaryKey);
505 }
506
507 return remove(dlFileVersion);
508 }
509 catch (NoSuchFileVersionException nsee) {
510 throw nsee;
511 }
512 catch (Exception e) {
513 throw processException(e);
514 }
515 finally {
516 closeSession(session);
517 }
518 }
519
520 @Override
521 protected DLFileVersion removeImpl(DLFileVersion dlFileVersion)
522 throws SystemException {
523 dlFileVersion = toUnwrappedModel(dlFileVersion);
524
525 Session session = null;
526
527 try {
528 session = openSession();
529
530 BatchSessionUtil.delete(session, dlFileVersion);
531 }
532 catch (Exception e) {
533 throw processException(e);
534 }
535 finally {
536 closeSession(session);
537 }
538
539 clearCache(dlFileVersion);
540
541 return dlFileVersion;
542 }
543
544 @Override
545 public DLFileVersion updateImpl(
546 com.liferay.portlet.documentlibrary.model.DLFileVersion dlFileVersion,
547 boolean merge) throws SystemException {
548 dlFileVersion = toUnwrappedModel(dlFileVersion);
549
550 boolean isNew = dlFileVersion.isNew();
551
552 DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
553
554 if (Validator.isNull(dlFileVersion.getUuid())) {
555 String uuid = PortalUUIDUtil.generate();
556
557 dlFileVersion.setUuid(uuid);
558 }
559
560 Session session = null;
561
562 try {
563 session = openSession();
564
565 BatchSessionUtil.update(session, dlFileVersion, merge);
566
567 dlFileVersion.setNew(false);
568 }
569 catch (Exception e) {
570 throw processException(e);
571 }
572 finally {
573 closeSession(session);
574 }
575
576 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
577
578 if (isNew || !DLFileVersionModelImpl.COLUMN_BITMASK_ENABLED) {
579 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
580 }
581
582 else {
583 if ((dlFileVersionModelImpl.getColumnBitmask() &
584 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
585 Object[] args = new Object[] {
586 dlFileVersionModelImpl.getOriginalUuid()
587 };
588
589 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
590 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
591 args);
592
593 args = new Object[] { dlFileVersionModelImpl.getUuid() };
594
595 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
596 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
597 args);
598 }
599
600 if ((dlFileVersionModelImpl.getColumnBitmask() &
601 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID.getColumnBitmask()) != 0) {
602 Object[] args = new Object[] {
603 Long.valueOf(dlFileVersionModelImpl.getOriginalFileEntryId())
604 };
605
606 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
607 args);
608 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
609 args);
610
611 args = new Object[] {
612 Long.valueOf(dlFileVersionModelImpl.getFileEntryId())
613 };
614
615 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
616 args);
617 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
618 args);
619 }
620
621 if ((dlFileVersionModelImpl.getColumnBitmask() &
622 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE.getColumnBitmask()) != 0) {
623 Object[] args = new Object[] {
624 dlFileVersionModelImpl.getOriginalMimeType()
625 };
626
627 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MIMETYPE, args);
628 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE,
629 args);
630
631 args = new Object[] { dlFileVersionModelImpl.getMimeType() };
632
633 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MIMETYPE, args);
634 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE,
635 args);
636 }
637
638 if ((dlFileVersionModelImpl.getColumnBitmask() &
639 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S.getColumnBitmask()) != 0) {
640 Object[] args = new Object[] {
641 Long.valueOf(dlFileVersionModelImpl.getOriginalFileEntryId()),
642 Integer.valueOf(dlFileVersionModelImpl.getOriginalStatus())
643 };
644
645 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_F_S, args);
646 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S,
647 args);
648
649 args = new Object[] {
650 Long.valueOf(dlFileVersionModelImpl.getFileEntryId()),
651 Integer.valueOf(dlFileVersionModelImpl.getStatus())
652 };
653
654 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_F_S, args);
655 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S,
656 args);
657 }
658
659 if ((dlFileVersionModelImpl.getColumnBitmask() &
660 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S.getColumnBitmask()) != 0) {
661 Object[] args = new Object[] {
662 Long.valueOf(dlFileVersionModelImpl.getOriginalGroupId()),
663 Long.valueOf(dlFileVersionModelImpl.getOriginalFolderId()),
664 Integer.valueOf(dlFileVersionModelImpl.getOriginalStatus())
665 };
666
667 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F_S, args);
668 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S,
669 args);
670
671 args = new Object[] {
672 Long.valueOf(dlFileVersionModelImpl.getGroupId()),
673 Long.valueOf(dlFileVersionModelImpl.getFolderId()),
674 Integer.valueOf(dlFileVersionModelImpl.getStatus())
675 };
676
677 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F_S, args);
678 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S,
679 args);
680 }
681
682 if ((dlFileVersionModelImpl.getColumnBitmask() &
683 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V.getColumnBitmask()) != 0) {
684 Object[] args = new Object[] {
685 Long.valueOf(dlFileVersionModelImpl.getOriginalGroupId()),
686 Long.valueOf(dlFileVersionModelImpl.getOriginalFolderId()),
687
688 dlFileVersionModelImpl.getOriginalTitle(),
689
690 dlFileVersionModelImpl.getOriginalVersion()
691 };
692
693 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F_T_V, args);
694 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V,
695 args);
696
697 args = new Object[] {
698 Long.valueOf(dlFileVersionModelImpl.getGroupId()),
699 Long.valueOf(dlFileVersionModelImpl.getFolderId()),
700
701 dlFileVersionModelImpl.getTitle(),
702
703 dlFileVersionModelImpl.getVersion()
704 };
705
706 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F_T_V, args);
707 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V,
708 args);
709 }
710 }
711
712 EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
713 DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
714 dlFileVersion);
715
716 clearUniqueFindersCache(dlFileVersion);
717 cacheUniqueFindersCache(dlFileVersion);
718
719 return dlFileVersion;
720 }
721
722 protected DLFileVersion toUnwrappedModel(DLFileVersion dlFileVersion) {
723 if (dlFileVersion instanceof DLFileVersionImpl) {
724 return dlFileVersion;
725 }
726
727 DLFileVersionImpl dlFileVersionImpl = new DLFileVersionImpl();
728
729 dlFileVersionImpl.setNew(dlFileVersion.isNew());
730 dlFileVersionImpl.setPrimaryKey(dlFileVersion.getPrimaryKey());
731
732 dlFileVersionImpl.setUuid(dlFileVersion.getUuid());
733 dlFileVersionImpl.setFileVersionId(dlFileVersion.getFileVersionId());
734 dlFileVersionImpl.setGroupId(dlFileVersion.getGroupId());
735 dlFileVersionImpl.setCompanyId(dlFileVersion.getCompanyId());
736 dlFileVersionImpl.setUserId(dlFileVersion.getUserId());
737 dlFileVersionImpl.setUserName(dlFileVersion.getUserName());
738 dlFileVersionImpl.setCreateDate(dlFileVersion.getCreateDate());
739 dlFileVersionImpl.setModifiedDate(dlFileVersion.getModifiedDate());
740 dlFileVersionImpl.setRepositoryId(dlFileVersion.getRepositoryId());
741 dlFileVersionImpl.setFolderId(dlFileVersion.getFolderId());
742 dlFileVersionImpl.setFileEntryId(dlFileVersion.getFileEntryId());
743 dlFileVersionImpl.setExtension(dlFileVersion.getExtension());
744 dlFileVersionImpl.setMimeType(dlFileVersion.getMimeType());
745 dlFileVersionImpl.setTitle(dlFileVersion.getTitle());
746 dlFileVersionImpl.setDescription(dlFileVersion.getDescription());
747 dlFileVersionImpl.setChangeLog(dlFileVersion.getChangeLog());
748 dlFileVersionImpl.setExtraSettings(dlFileVersion.getExtraSettings());
749 dlFileVersionImpl.setFileEntryTypeId(dlFileVersion.getFileEntryTypeId());
750 dlFileVersionImpl.setVersion(dlFileVersion.getVersion());
751 dlFileVersionImpl.setSize(dlFileVersion.getSize());
752 dlFileVersionImpl.setStatus(dlFileVersion.getStatus());
753 dlFileVersionImpl.setStatusByUserId(dlFileVersion.getStatusByUserId());
754 dlFileVersionImpl.setStatusByUserName(dlFileVersion.getStatusByUserName());
755 dlFileVersionImpl.setStatusDate(dlFileVersion.getStatusDate());
756
757 return dlFileVersionImpl;
758 }
759
760
768 @Override
769 public DLFileVersion findByPrimaryKey(Serializable primaryKey)
770 throws NoSuchModelException, SystemException {
771 return findByPrimaryKey(((Long)primaryKey).longValue());
772 }
773
774
782 public DLFileVersion findByPrimaryKey(long fileVersionId)
783 throws NoSuchFileVersionException, SystemException {
784 DLFileVersion dlFileVersion = fetchByPrimaryKey(fileVersionId);
785
786 if (dlFileVersion == null) {
787 if (_log.isWarnEnabled()) {
788 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileVersionId);
789 }
790
791 throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
792 fileVersionId);
793 }
794
795 return dlFileVersion;
796 }
797
798
805 @Override
806 public DLFileVersion fetchByPrimaryKey(Serializable primaryKey)
807 throws SystemException {
808 return fetchByPrimaryKey(((Long)primaryKey).longValue());
809 }
810
811
818 public DLFileVersion fetchByPrimaryKey(long fileVersionId)
819 throws SystemException {
820 DLFileVersion dlFileVersion = (DLFileVersion)EntityCacheUtil.getResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
821 DLFileVersionImpl.class, fileVersionId);
822
823 if (dlFileVersion == _nullDLFileVersion) {
824 return null;
825 }
826
827 if (dlFileVersion == null) {
828 Session session = null;
829
830 boolean hasException = false;
831
832 try {
833 session = openSession();
834
835 dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
836 Long.valueOf(fileVersionId));
837 }
838 catch (Exception e) {
839 hasException = true;
840
841 throw processException(e);
842 }
843 finally {
844 if (dlFileVersion != null) {
845 cacheResult(dlFileVersion);
846 }
847 else if (!hasException) {
848 EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
849 DLFileVersionImpl.class, fileVersionId,
850 _nullDLFileVersion);
851 }
852
853 closeSession(session);
854 }
855 }
856
857 return dlFileVersion;
858 }
859
860
867 public List<DLFileVersion> findByUuid(String uuid)
868 throws SystemException {
869 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
870 }
871
872
885 public List<DLFileVersion> findByUuid(String uuid, int start, int end)
886 throws SystemException {
887 return findByUuid(uuid, start, end, null);
888 }
889
890
904 public List<DLFileVersion> findByUuid(String uuid, int start, int end,
905 OrderByComparator orderByComparator) throws SystemException {
906 FinderPath finderPath = null;
907 Object[] finderArgs = null;
908
909 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
910 (orderByComparator == null)) {
911 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
912 finderArgs = new Object[] { uuid };
913 }
914 else {
915 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
916 finderArgs = new Object[] { uuid, start, end, orderByComparator };
917 }
918
919 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
920 finderArgs, this);
921
922 if ((list != null) && !list.isEmpty()) {
923 for (DLFileVersion dlFileVersion : list) {
924 if (!Validator.equals(uuid, dlFileVersion.getUuid())) {
925 list = null;
926
927 break;
928 }
929 }
930 }
931
932 if (list == null) {
933 StringBundler query = null;
934
935 if (orderByComparator != null) {
936 query = new StringBundler(3 +
937 (orderByComparator.getOrderByFields().length * 3));
938 }
939 else {
940 query = new StringBundler(3);
941 }
942
943 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
944
945 if (uuid == null) {
946 query.append(_FINDER_COLUMN_UUID_UUID_1);
947 }
948 else {
949 if (uuid.equals(StringPool.BLANK)) {
950 query.append(_FINDER_COLUMN_UUID_UUID_3);
951 }
952 else {
953 query.append(_FINDER_COLUMN_UUID_UUID_2);
954 }
955 }
956
957 if (orderByComparator != null) {
958 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
959 orderByComparator);
960 }
961
962 else {
963 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
964 }
965
966 String sql = query.toString();
967
968 Session session = null;
969
970 try {
971 session = openSession();
972
973 Query q = session.createQuery(sql);
974
975 QueryPos qPos = QueryPos.getInstance(q);
976
977 if (uuid != null) {
978 qPos.add(uuid);
979 }
980
981 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
982 start, end);
983 }
984 catch (Exception e) {
985 throw processException(e);
986 }
987 finally {
988 if (list == null) {
989 FinderCacheUtil.removeResult(finderPath, finderArgs);
990 }
991 else {
992 cacheResult(list);
993
994 FinderCacheUtil.putResult(finderPath, finderArgs, list);
995 }
996
997 closeSession(session);
998 }
999 }
1000
1001 return list;
1002 }
1003
1004
1013 public DLFileVersion findByUuid_First(String uuid,
1014 OrderByComparator orderByComparator)
1015 throws NoSuchFileVersionException, SystemException {
1016 DLFileVersion dlFileVersion = fetchByUuid_First(uuid, orderByComparator);
1017
1018 if (dlFileVersion != null) {
1019 return dlFileVersion;
1020 }
1021
1022 StringBundler msg = new StringBundler(4);
1023
1024 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1025
1026 msg.append("uuid=");
1027 msg.append(uuid);
1028
1029 msg.append(StringPool.CLOSE_CURLY_BRACE);
1030
1031 throw new NoSuchFileVersionException(msg.toString());
1032 }
1033
1034
1042 public DLFileVersion fetchByUuid_First(String uuid,
1043 OrderByComparator orderByComparator) throws SystemException {
1044 List<DLFileVersion> list = findByUuid(uuid, 0, 1, orderByComparator);
1045
1046 if (!list.isEmpty()) {
1047 return list.get(0);
1048 }
1049
1050 return null;
1051 }
1052
1053
1062 public DLFileVersion findByUuid_Last(String uuid,
1063 OrderByComparator orderByComparator)
1064 throws NoSuchFileVersionException, SystemException {
1065 DLFileVersion dlFileVersion = fetchByUuid_Last(uuid, orderByComparator);
1066
1067 if (dlFileVersion != null) {
1068 return dlFileVersion;
1069 }
1070
1071 StringBundler msg = new StringBundler(4);
1072
1073 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1074
1075 msg.append("uuid=");
1076 msg.append(uuid);
1077
1078 msg.append(StringPool.CLOSE_CURLY_BRACE);
1079
1080 throw new NoSuchFileVersionException(msg.toString());
1081 }
1082
1083
1091 public DLFileVersion fetchByUuid_Last(String uuid,
1092 OrderByComparator orderByComparator) throws SystemException {
1093 int count = countByUuid(uuid);
1094
1095 List<DLFileVersion> list = findByUuid(uuid, count - 1, count,
1096 orderByComparator);
1097
1098 if (!list.isEmpty()) {
1099 return list.get(0);
1100 }
1101
1102 return null;
1103 }
1104
1105
1115 public DLFileVersion[] findByUuid_PrevAndNext(long fileVersionId,
1116 String uuid, OrderByComparator orderByComparator)
1117 throws NoSuchFileVersionException, SystemException {
1118 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
1119
1120 Session session = null;
1121
1122 try {
1123 session = openSession();
1124
1125 DLFileVersion[] array = new DLFileVersionImpl[3];
1126
1127 array[0] = getByUuid_PrevAndNext(session, dlFileVersion, uuid,
1128 orderByComparator, true);
1129
1130 array[1] = dlFileVersion;
1131
1132 array[2] = getByUuid_PrevAndNext(session, dlFileVersion, uuid,
1133 orderByComparator, false);
1134
1135 return array;
1136 }
1137 catch (Exception e) {
1138 throw processException(e);
1139 }
1140 finally {
1141 closeSession(session);
1142 }
1143 }
1144
1145 protected DLFileVersion getByUuid_PrevAndNext(Session session,
1146 DLFileVersion dlFileVersion, String uuid,
1147 OrderByComparator orderByComparator, boolean previous) {
1148 StringBundler query = null;
1149
1150 if (orderByComparator != null) {
1151 query = new StringBundler(6 +
1152 (orderByComparator.getOrderByFields().length * 6));
1153 }
1154 else {
1155 query = new StringBundler(3);
1156 }
1157
1158 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1159
1160 if (uuid == null) {
1161 query.append(_FINDER_COLUMN_UUID_UUID_1);
1162 }
1163 else {
1164 if (uuid.equals(StringPool.BLANK)) {
1165 query.append(_FINDER_COLUMN_UUID_UUID_3);
1166 }
1167 else {
1168 query.append(_FINDER_COLUMN_UUID_UUID_2);
1169 }
1170 }
1171
1172 if (orderByComparator != null) {
1173 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1174
1175 if (orderByConditionFields.length > 0) {
1176 query.append(WHERE_AND);
1177 }
1178
1179 for (int i = 0; i < orderByConditionFields.length; i++) {
1180 query.append(_ORDER_BY_ENTITY_ALIAS);
1181 query.append(orderByConditionFields[i]);
1182
1183 if ((i + 1) < orderByConditionFields.length) {
1184 if (orderByComparator.isAscending() ^ previous) {
1185 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1186 }
1187 else {
1188 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1189 }
1190 }
1191 else {
1192 if (orderByComparator.isAscending() ^ previous) {
1193 query.append(WHERE_GREATER_THAN);
1194 }
1195 else {
1196 query.append(WHERE_LESSER_THAN);
1197 }
1198 }
1199 }
1200
1201 query.append(ORDER_BY_CLAUSE);
1202
1203 String[] orderByFields = orderByComparator.getOrderByFields();
1204
1205 for (int i = 0; i < orderByFields.length; i++) {
1206 query.append(_ORDER_BY_ENTITY_ALIAS);
1207 query.append(orderByFields[i]);
1208
1209 if ((i + 1) < orderByFields.length) {
1210 if (orderByComparator.isAscending() ^ previous) {
1211 query.append(ORDER_BY_ASC_HAS_NEXT);
1212 }
1213 else {
1214 query.append(ORDER_BY_DESC_HAS_NEXT);
1215 }
1216 }
1217 else {
1218 if (orderByComparator.isAscending() ^ previous) {
1219 query.append(ORDER_BY_ASC);
1220 }
1221 else {
1222 query.append(ORDER_BY_DESC);
1223 }
1224 }
1225 }
1226 }
1227
1228 else {
1229 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1230 }
1231
1232 String sql = query.toString();
1233
1234 Query q = session.createQuery(sql);
1235
1236 q.setFirstResult(0);
1237 q.setMaxResults(2);
1238
1239 QueryPos qPos = QueryPos.getInstance(q);
1240
1241 if (uuid != null) {
1242 qPos.add(uuid);
1243 }
1244
1245 if (orderByComparator != null) {
1246 Object[] values = orderByComparator.getOrderByConditionValues(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
1272 public DLFileVersion findByUUID_G(String uuid, long groupId)
1273 throws NoSuchFileVersionException, SystemException {
1274 DLFileVersion dlFileVersion = fetchByUUID_G(uuid, groupId);
1275
1276 if (dlFileVersion == null) {
1277 StringBundler msg = new StringBundler(6);
1278
1279 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1280
1281 msg.append("uuid=");
1282 msg.append(uuid);
1283
1284 msg.append(", groupId=");
1285 msg.append(groupId);
1286
1287 msg.append(StringPool.CLOSE_CURLY_BRACE);
1288
1289 if (_log.isWarnEnabled()) {
1290 _log.warn(msg.toString());
1291 }
1292
1293 throw new NoSuchFileVersionException(msg.toString());
1294 }
1295
1296 return dlFileVersion;
1297 }
1298
1299
1307 public DLFileVersion fetchByUUID_G(String uuid, long groupId)
1308 throws SystemException {
1309 return fetchByUUID_G(uuid, groupId, true);
1310 }
1311
1312
1321 public DLFileVersion fetchByUUID_G(String uuid, long groupId,
1322 boolean retrieveFromCache) throws SystemException {
1323 Object[] finderArgs = new Object[] { uuid, groupId };
1324
1325 Object result = null;
1326
1327 if (retrieveFromCache) {
1328 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1329 finderArgs, this);
1330 }
1331
1332 if (result instanceof DLFileVersion) {
1333 DLFileVersion dlFileVersion = (DLFileVersion)result;
1334
1335 if (!Validator.equals(uuid, dlFileVersion.getUuid()) ||
1336 (groupId != dlFileVersion.getGroupId())) {
1337 result = null;
1338 }
1339 }
1340
1341 if (result == null) {
1342 StringBundler query = new StringBundler(4);
1343
1344 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1345
1346 if (uuid == null) {
1347 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1348 }
1349 else {
1350 if (uuid.equals(StringPool.BLANK)) {
1351 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1352 }
1353 else {
1354 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1355 }
1356 }
1357
1358 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1359
1360 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1361
1362 String sql = query.toString();
1363
1364 Session session = null;
1365
1366 try {
1367 session = openSession();
1368
1369 Query q = session.createQuery(sql);
1370
1371 QueryPos qPos = QueryPos.getInstance(q);
1372
1373 if (uuid != null) {
1374 qPos.add(uuid);
1375 }
1376
1377 qPos.add(groupId);
1378
1379 List<DLFileVersion> list = q.list();
1380
1381 result = list;
1382
1383 DLFileVersion dlFileVersion = null;
1384
1385 if (list.isEmpty()) {
1386 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1387 finderArgs, list);
1388 }
1389 else {
1390 dlFileVersion = list.get(0);
1391
1392 cacheResult(dlFileVersion);
1393
1394 if ((dlFileVersion.getUuid() == null) ||
1395 !dlFileVersion.getUuid().equals(uuid) ||
1396 (dlFileVersion.getGroupId() != groupId)) {
1397 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1398 finderArgs, dlFileVersion);
1399 }
1400 }
1401
1402 return dlFileVersion;
1403 }
1404 catch (Exception e) {
1405 throw processException(e);
1406 }
1407 finally {
1408 if (result == null) {
1409 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1410 finderArgs);
1411 }
1412
1413 closeSession(session);
1414 }
1415 }
1416 else {
1417 if (result instanceof List<?>) {
1418 return null;
1419 }
1420 else {
1421 return (DLFileVersion)result;
1422 }
1423 }
1424 }
1425
1426
1433 public List<DLFileVersion> findByFileEntryId(long fileEntryId)
1434 throws SystemException {
1435 return findByFileEntryId(fileEntryId, QueryUtil.ALL_POS,
1436 QueryUtil.ALL_POS, null);
1437 }
1438
1439
1452 public List<DLFileVersion> findByFileEntryId(long fileEntryId, int start,
1453 int end) throws SystemException {
1454 return findByFileEntryId(fileEntryId, start, end, null);
1455 }
1456
1457
1471 public List<DLFileVersion> findByFileEntryId(long fileEntryId, int start,
1472 int end, OrderByComparator orderByComparator) throws SystemException {
1473 FinderPath finderPath = null;
1474 Object[] finderArgs = null;
1475
1476 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1477 (orderByComparator == null)) {
1478 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID;
1479 finderArgs = new Object[] { fileEntryId };
1480 }
1481 else {
1482 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID;
1483 finderArgs = new Object[] { fileEntryId, start, end, orderByComparator };
1484 }
1485
1486 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
1487 finderArgs, this);
1488
1489 if ((list != null) && !list.isEmpty()) {
1490 for (DLFileVersion dlFileVersion : list) {
1491 if ((fileEntryId != dlFileVersion.getFileEntryId())) {
1492 list = null;
1493
1494 break;
1495 }
1496 }
1497 }
1498
1499 if (list == null) {
1500 StringBundler query = null;
1501
1502 if (orderByComparator != null) {
1503 query = new StringBundler(3 +
1504 (orderByComparator.getOrderByFields().length * 3));
1505 }
1506 else {
1507 query = new StringBundler(3);
1508 }
1509
1510 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1511
1512 query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
1513
1514 if (orderByComparator != null) {
1515 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1516 orderByComparator);
1517 }
1518
1519 else {
1520 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1521 }
1522
1523 String sql = query.toString();
1524
1525 Session session = null;
1526
1527 try {
1528 session = openSession();
1529
1530 Query q = session.createQuery(sql);
1531
1532 QueryPos qPos = QueryPos.getInstance(q);
1533
1534 qPos.add(fileEntryId);
1535
1536 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1537 start, end);
1538 }
1539 catch (Exception e) {
1540 throw processException(e);
1541 }
1542 finally {
1543 if (list == null) {
1544 FinderCacheUtil.removeResult(finderPath, finderArgs);
1545 }
1546 else {
1547 cacheResult(list);
1548
1549 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1550 }
1551
1552 closeSession(session);
1553 }
1554 }
1555
1556 return list;
1557 }
1558
1559
1568 public DLFileVersion findByFileEntryId_First(long fileEntryId,
1569 OrderByComparator orderByComparator)
1570 throws NoSuchFileVersionException, SystemException {
1571 DLFileVersion dlFileVersion = fetchByFileEntryId_First(fileEntryId,
1572 orderByComparator);
1573
1574 if (dlFileVersion != null) {
1575 return dlFileVersion;
1576 }
1577
1578 StringBundler msg = new StringBundler(4);
1579
1580 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1581
1582 msg.append("fileEntryId=");
1583 msg.append(fileEntryId);
1584
1585 msg.append(StringPool.CLOSE_CURLY_BRACE);
1586
1587 throw new NoSuchFileVersionException(msg.toString());
1588 }
1589
1590
1598 public DLFileVersion fetchByFileEntryId_First(long fileEntryId,
1599 OrderByComparator orderByComparator) throws SystemException {
1600 List<DLFileVersion> list = findByFileEntryId(fileEntryId, 0, 1,
1601 orderByComparator);
1602
1603 if (!list.isEmpty()) {
1604 return list.get(0);
1605 }
1606
1607 return null;
1608 }
1609
1610
1619 public DLFileVersion findByFileEntryId_Last(long fileEntryId,
1620 OrderByComparator orderByComparator)
1621 throws NoSuchFileVersionException, SystemException {
1622 DLFileVersion dlFileVersion = fetchByFileEntryId_Last(fileEntryId,
1623 orderByComparator);
1624
1625 if (dlFileVersion != null) {
1626 return dlFileVersion;
1627 }
1628
1629 StringBundler msg = new StringBundler(4);
1630
1631 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1632
1633 msg.append("fileEntryId=");
1634 msg.append(fileEntryId);
1635
1636 msg.append(StringPool.CLOSE_CURLY_BRACE);
1637
1638 throw new NoSuchFileVersionException(msg.toString());
1639 }
1640
1641
1649 public DLFileVersion fetchByFileEntryId_Last(long fileEntryId,
1650 OrderByComparator orderByComparator) throws SystemException {
1651 int count = countByFileEntryId(fileEntryId);
1652
1653 List<DLFileVersion> list = findByFileEntryId(fileEntryId, count - 1,
1654 count, orderByComparator);
1655
1656 if (!list.isEmpty()) {
1657 return list.get(0);
1658 }
1659
1660 return null;
1661 }
1662
1663
1673 public DLFileVersion[] findByFileEntryId_PrevAndNext(long fileVersionId,
1674 long fileEntryId, OrderByComparator orderByComparator)
1675 throws NoSuchFileVersionException, SystemException {
1676 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
1677
1678 Session session = null;
1679
1680 try {
1681 session = openSession();
1682
1683 DLFileVersion[] array = new DLFileVersionImpl[3];
1684
1685 array[0] = getByFileEntryId_PrevAndNext(session, dlFileVersion,
1686 fileEntryId, orderByComparator, true);
1687
1688 array[1] = dlFileVersion;
1689
1690 array[2] = getByFileEntryId_PrevAndNext(session, dlFileVersion,
1691 fileEntryId, orderByComparator, false);
1692
1693 return array;
1694 }
1695 catch (Exception e) {
1696 throw processException(e);
1697 }
1698 finally {
1699 closeSession(session);
1700 }
1701 }
1702
1703 protected DLFileVersion getByFileEntryId_PrevAndNext(Session session,
1704 DLFileVersion dlFileVersion, long fileEntryId,
1705 OrderByComparator orderByComparator, boolean previous) {
1706 StringBundler query = null;
1707
1708 if (orderByComparator != null) {
1709 query = new StringBundler(6 +
1710 (orderByComparator.getOrderByFields().length * 6));
1711 }
1712 else {
1713 query = new StringBundler(3);
1714 }
1715
1716 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1717
1718 query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
1719
1720 if (orderByComparator != null) {
1721 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1722
1723 if (orderByConditionFields.length > 0) {
1724 query.append(WHERE_AND);
1725 }
1726
1727 for (int i = 0; i < orderByConditionFields.length; i++) {
1728 query.append(_ORDER_BY_ENTITY_ALIAS);
1729 query.append(orderByConditionFields[i]);
1730
1731 if ((i + 1) < orderByConditionFields.length) {
1732 if (orderByComparator.isAscending() ^ previous) {
1733 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1734 }
1735 else {
1736 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1737 }
1738 }
1739 else {
1740 if (orderByComparator.isAscending() ^ previous) {
1741 query.append(WHERE_GREATER_THAN);
1742 }
1743 else {
1744 query.append(WHERE_LESSER_THAN);
1745 }
1746 }
1747 }
1748
1749 query.append(ORDER_BY_CLAUSE);
1750
1751 String[] orderByFields = orderByComparator.getOrderByFields();
1752
1753 for (int i = 0; i < orderByFields.length; i++) {
1754 query.append(_ORDER_BY_ENTITY_ALIAS);
1755 query.append(orderByFields[i]);
1756
1757 if ((i + 1) < orderByFields.length) {
1758 if (orderByComparator.isAscending() ^ previous) {
1759 query.append(ORDER_BY_ASC_HAS_NEXT);
1760 }
1761 else {
1762 query.append(ORDER_BY_DESC_HAS_NEXT);
1763 }
1764 }
1765 else {
1766 if (orderByComparator.isAscending() ^ previous) {
1767 query.append(ORDER_BY_ASC);
1768 }
1769 else {
1770 query.append(ORDER_BY_DESC);
1771 }
1772 }
1773 }
1774 }
1775
1776 else {
1777 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1778 }
1779
1780 String sql = query.toString();
1781
1782 Query q = session.createQuery(sql);
1783
1784 q.setFirstResult(0);
1785 q.setMaxResults(2);
1786
1787 QueryPos qPos = QueryPos.getInstance(q);
1788
1789 qPos.add(fileEntryId);
1790
1791 if (orderByComparator != null) {
1792 Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
1793
1794 for (Object value : values) {
1795 qPos.add(value);
1796 }
1797 }
1798
1799 List<DLFileVersion> list = q.list();
1800
1801 if (list.size() == 2) {
1802 return list.get(1);
1803 }
1804 else {
1805 return null;
1806 }
1807 }
1808
1809
1816 public List<DLFileVersion> findByMimeType(String mimeType)
1817 throws SystemException {
1818 return findByMimeType(mimeType, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1819 null);
1820 }
1821
1822
1835 public List<DLFileVersion> findByMimeType(String mimeType, int start,
1836 int end) throws SystemException {
1837 return findByMimeType(mimeType, start, end, null);
1838 }
1839
1840
1854 public List<DLFileVersion> findByMimeType(String mimeType, int start,
1855 int end, OrderByComparator orderByComparator) throws SystemException {
1856 FinderPath finderPath = null;
1857 Object[] finderArgs = null;
1858
1859 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1860 (orderByComparator == null)) {
1861 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE;
1862 finderArgs = new Object[] { mimeType };
1863 }
1864 else {
1865 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_MIMETYPE;
1866 finderArgs = new Object[] { mimeType, start, end, orderByComparator };
1867 }
1868
1869 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
1870 finderArgs, this);
1871
1872 if ((list != null) && !list.isEmpty()) {
1873 for (DLFileVersion dlFileVersion : list) {
1874 if (!Validator.equals(mimeType, dlFileVersion.getMimeType())) {
1875 list = null;
1876
1877 break;
1878 }
1879 }
1880 }
1881
1882 if (list == null) {
1883 StringBundler query = null;
1884
1885 if (orderByComparator != null) {
1886 query = new StringBundler(3 +
1887 (orderByComparator.getOrderByFields().length * 3));
1888 }
1889 else {
1890 query = new StringBundler(3);
1891 }
1892
1893 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1894
1895 if (mimeType == null) {
1896 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_1);
1897 }
1898 else {
1899 if (mimeType.equals(StringPool.BLANK)) {
1900 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_3);
1901 }
1902 else {
1903 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_2);
1904 }
1905 }
1906
1907 if (orderByComparator != null) {
1908 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1909 orderByComparator);
1910 }
1911
1912 else {
1913 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1914 }
1915
1916 String sql = query.toString();
1917
1918 Session session = null;
1919
1920 try {
1921 session = openSession();
1922
1923 Query q = session.createQuery(sql);
1924
1925 QueryPos qPos = QueryPos.getInstance(q);
1926
1927 if (mimeType != null) {
1928 qPos.add(mimeType);
1929 }
1930
1931 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1932 start, end);
1933 }
1934 catch (Exception e) {
1935 throw processException(e);
1936 }
1937 finally {
1938 if (list == null) {
1939 FinderCacheUtil.removeResult(finderPath, finderArgs);
1940 }
1941 else {
1942 cacheResult(list);
1943
1944 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1945 }
1946
1947 closeSession(session);
1948 }
1949 }
1950
1951 return list;
1952 }
1953
1954
1963 public DLFileVersion findByMimeType_First(String mimeType,
1964 OrderByComparator orderByComparator)
1965 throws NoSuchFileVersionException, SystemException {
1966 DLFileVersion dlFileVersion = fetchByMimeType_First(mimeType,
1967 orderByComparator);
1968
1969 if (dlFileVersion != null) {
1970 return dlFileVersion;
1971 }
1972
1973 StringBundler msg = new StringBundler(4);
1974
1975 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1976
1977 msg.append("mimeType=");
1978 msg.append(mimeType);
1979
1980 msg.append(StringPool.CLOSE_CURLY_BRACE);
1981
1982 throw new NoSuchFileVersionException(msg.toString());
1983 }
1984
1985
1993 public DLFileVersion fetchByMimeType_First(String mimeType,
1994 OrderByComparator orderByComparator) throws SystemException {
1995 List<DLFileVersion> list = findByMimeType(mimeType, 0, 1,
1996 orderByComparator);
1997
1998 if (!list.isEmpty()) {
1999 return list.get(0);
2000 }
2001
2002 return null;
2003 }
2004
2005
2014 public DLFileVersion findByMimeType_Last(String mimeType,
2015 OrderByComparator orderByComparator)
2016 throws NoSuchFileVersionException, SystemException {
2017 DLFileVersion dlFileVersion = fetchByMimeType_Last(mimeType,
2018 orderByComparator);
2019
2020 if (dlFileVersion != null) {
2021 return dlFileVersion;
2022 }
2023
2024 StringBundler msg = new StringBundler(4);
2025
2026 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2027
2028 msg.append("mimeType=");
2029 msg.append(mimeType);
2030
2031 msg.append(StringPool.CLOSE_CURLY_BRACE);
2032
2033 throw new NoSuchFileVersionException(msg.toString());
2034 }
2035
2036
2044 public DLFileVersion fetchByMimeType_Last(String mimeType,
2045 OrderByComparator orderByComparator) throws SystemException {
2046 int count = countByMimeType(mimeType);
2047
2048 List<DLFileVersion> list = findByMimeType(mimeType, count - 1, count,
2049 orderByComparator);
2050
2051 if (!list.isEmpty()) {
2052 return list.get(0);
2053 }
2054
2055 return null;
2056 }
2057
2058
2068 public DLFileVersion[] findByMimeType_PrevAndNext(long fileVersionId,
2069 String mimeType, OrderByComparator orderByComparator)
2070 throws NoSuchFileVersionException, SystemException {
2071 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
2072
2073 Session session = null;
2074
2075 try {
2076 session = openSession();
2077
2078 DLFileVersion[] array = new DLFileVersionImpl[3];
2079
2080 array[0] = getByMimeType_PrevAndNext(session, dlFileVersion,
2081 mimeType, orderByComparator, true);
2082
2083 array[1] = dlFileVersion;
2084
2085 array[2] = getByMimeType_PrevAndNext(session, dlFileVersion,
2086 mimeType, orderByComparator, false);
2087
2088 return array;
2089 }
2090 catch (Exception e) {
2091 throw processException(e);
2092 }
2093 finally {
2094 closeSession(session);
2095 }
2096 }
2097
2098 protected DLFileVersion getByMimeType_PrevAndNext(Session session,
2099 DLFileVersion dlFileVersion, String mimeType,
2100 OrderByComparator orderByComparator, boolean previous) {
2101 StringBundler query = null;
2102
2103 if (orderByComparator != null) {
2104 query = new StringBundler(6 +
2105 (orderByComparator.getOrderByFields().length * 6));
2106 }
2107 else {
2108 query = new StringBundler(3);
2109 }
2110
2111 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2112
2113 if (mimeType == null) {
2114 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_1);
2115 }
2116 else {
2117 if (mimeType.equals(StringPool.BLANK)) {
2118 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_3);
2119 }
2120 else {
2121 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_2);
2122 }
2123 }
2124
2125 if (orderByComparator != null) {
2126 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2127
2128 if (orderByConditionFields.length > 0) {
2129 query.append(WHERE_AND);
2130 }
2131
2132 for (int i = 0; i < orderByConditionFields.length; i++) {
2133 query.append(_ORDER_BY_ENTITY_ALIAS);
2134 query.append(orderByConditionFields[i]);
2135
2136 if ((i + 1) < orderByConditionFields.length) {
2137 if (orderByComparator.isAscending() ^ previous) {
2138 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2139 }
2140 else {
2141 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2142 }
2143 }
2144 else {
2145 if (orderByComparator.isAscending() ^ previous) {
2146 query.append(WHERE_GREATER_THAN);
2147 }
2148 else {
2149 query.append(WHERE_LESSER_THAN);
2150 }
2151 }
2152 }
2153
2154 query.append(ORDER_BY_CLAUSE);
2155
2156 String[] orderByFields = orderByComparator.getOrderByFields();
2157
2158 for (int i = 0; i < orderByFields.length; i++) {
2159 query.append(_ORDER_BY_ENTITY_ALIAS);
2160 query.append(orderByFields[i]);
2161
2162 if ((i + 1) < orderByFields.length) {
2163 if (orderByComparator.isAscending() ^ previous) {
2164 query.append(ORDER_BY_ASC_HAS_NEXT);
2165 }
2166 else {
2167 query.append(ORDER_BY_DESC_HAS_NEXT);
2168 }
2169 }
2170 else {
2171 if (orderByComparator.isAscending() ^ previous) {
2172 query.append(ORDER_BY_ASC);
2173 }
2174 else {
2175 query.append(ORDER_BY_DESC);
2176 }
2177 }
2178 }
2179 }
2180
2181 else {
2182 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2183 }
2184
2185 String sql = query.toString();
2186
2187 Query q = session.createQuery(sql);
2188
2189 q.setFirstResult(0);
2190 q.setMaxResults(2);
2191
2192 QueryPos qPos = QueryPos.getInstance(q);
2193
2194 if (mimeType != null) {
2195 qPos.add(mimeType);
2196 }
2197
2198 if (orderByComparator != null) {
2199 Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
2200
2201 for (Object value : values) {
2202 qPos.add(value);
2203 }
2204 }
2205
2206 List<DLFileVersion> list = q.list();
2207
2208 if (list.size() == 2) {
2209 return list.get(1);
2210 }
2211 else {
2212 return null;
2213 }
2214 }
2215
2216
2225 public DLFileVersion findByF_V(long fileEntryId, String version)
2226 throws NoSuchFileVersionException, SystemException {
2227 DLFileVersion dlFileVersion = fetchByF_V(fileEntryId, version);
2228
2229 if (dlFileVersion == null) {
2230 StringBundler msg = new StringBundler(6);
2231
2232 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2233
2234 msg.append("fileEntryId=");
2235 msg.append(fileEntryId);
2236
2237 msg.append(", version=");
2238 msg.append(version);
2239
2240 msg.append(StringPool.CLOSE_CURLY_BRACE);
2241
2242 if (_log.isWarnEnabled()) {
2243 _log.warn(msg.toString());
2244 }
2245
2246 throw new NoSuchFileVersionException(msg.toString());
2247 }
2248
2249 return dlFileVersion;
2250 }
2251
2252
2260 public DLFileVersion fetchByF_V(long fileEntryId, String version)
2261 throws SystemException {
2262 return fetchByF_V(fileEntryId, version, true);
2263 }
2264
2265
2274 public DLFileVersion fetchByF_V(long fileEntryId, String version,
2275 boolean retrieveFromCache) throws SystemException {
2276 Object[] finderArgs = new Object[] { fileEntryId, version };
2277
2278 Object result = null;
2279
2280 if (retrieveFromCache) {
2281 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_F_V,
2282 finderArgs, this);
2283 }
2284
2285 if (result instanceof DLFileVersion) {
2286 DLFileVersion dlFileVersion = (DLFileVersion)result;
2287
2288 if ((fileEntryId != dlFileVersion.getFileEntryId()) ||
2289 !Validator.equals(version, dlFileVersion.getVersion())) {
2290 result = null;
2291 }
2292 }
2293
2294 if (result == null) {
2295 StringBundler query = new StringBundler(4);
2296
2297 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2298
2299 query.append(_FINDER_COLUMN_F_V_FILEENTRYID_2);
2300
2301 if (version == null) {
2302 query.append(_FINDER_COLUMN_F_V_VERSION_1);
2303 }
2304 else {
2305 if (version.equals(StringPool.BLANK)) {
2306 query.append(_FINDER_COLUMN_F_V_VERSION_3);
2307 }
2308 else {
2309 query.append(_FINDER_COLUMN_F_V_VERSION_2);
2310 }
2311 }
2312
2313 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2314
2315 String sql = query.toString();
2316
2317 Session session = null;
2318
2319 try {
2320 session = openSession();
2321
2322 Query q = session.createQuery(sql);
2323
2324 QueryPos qPos = QueryPos.getInstance(q);
2325
2326 qPos.add(fileEntryId);
2327
2328 if (version != null) {
2329 qPos.add(version);
2330 }
2331
2332 List<DLFileVersion> list = q.list();
2333
2334 result = list;
2335
2336 DLFileVersion dlFileVersion = null;
2337
2338 if (list.isEmpty()) {
2339 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_V,
2340 finderArgs, list);
2341 }
2342 else {
2343 dlFileVersion = list.get(0);
2344
2345 cacheResult(dlFileVersion);
2346
2347 if ((dlFileVersion.getFileEntryId() != fileEntryId) ||
2348 (dlFileVersion.getVersion() == null) ||
2349 !dlFileVersion.getVersion().equals(version)) {
2350 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_V,
2351 finderArgs, dlFileVersion);
2352 }
2353 }
2354
2355 return dlFileVersion;
2356 }
2357 catch (Exception e) {
2358 throw processException(e);
2359 }
2360 finally {
2361 if (result == null) {
2362 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_F_V,
2363 finderArgs);
2364 }
2365
2366 closeSession(session);
2367 }
2368 }
2369 else {
2370 if (result instanceof List<?>) {
2371 return null;
2372 }
2373 else {
2374 return (DLFileVersion)result;
2375 }
2376 }
2377 }
2378
2379
2387 public List<DLFileVersion> findByF_S(long fileEntryId, int status)
2388 throws SystemException {
2389 return findByF_S(fileEntryId, status, QueryUtil.ALL_POS,
2390 QueryUtil.ALL_POS, null);
2391 }
2392
2393
2407 public List<DLFileVersion> findByF_S(long fileEntryId, int status,
2408 int start, int end) throws SystemException {
2409 return findByF_S(fileEntryId, status, start, end, null);
2410 }
2411
2412
2427 public List<DLFileVersion> findByF_S(long fileEntryId, int status,
2428 int start, int end, OrderByComparator orderByComparator)
2429 throws SystemException {
2430 FinderPath finderPath = null;
2431 Object[] finderArgs = null;
2432
2433 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2434 (orderByComparator == null)) {
2435 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S;
2436 finderArgs = new Object[] { fileEntryId, status };
2437 }
2438 else {
2439 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_F_S;
2440 finderArgs = new Object[] {
2441 fileEntryId, status,
2442
2443 start, end, orderByComparator
2444 };
2445 }
2446
2447 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
2448 finderArgs, this);
2449
2450 if ((list != null) && !list.isEmpty()) {
2451 for (DLFileVersion dlFileVersion : list) {
2452 if ((fileEntryId != dlFileVersion.getFileEntryId()) ||
2453 (status != dlFileVersion.getStatus())) {
2454 list = null;
2455
2456 break;
2457 }
2458 }
2459 }
2460
2461 if (list == null) {
2462 StringBundler query = null;
2463
2464 if (orderByComparator != null) {
2465 query = new StringBundler(4 +
2466 (orderByComparator.getOrderByFields().length * 3));
2467 }
2468 else {
2469 query = new StringBundler(4);
2470 }
2471
2472 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2473
2474 query.append(_FINDER_COLUMN_F_S_FILEENTRYID_2);
2475
2476 query.append(_FINDER_COLUMN_F_S_STATUS_2);
2477
2478 if (orderByComparator != null) {
2479 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2480 orderByComparator);
2481 }
2482
2483 else {
2484 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2485 }
2486
2487 String sql = query.toString();
2488
2489 Session session = null;
2490
2491 try {
2492 session = openSession();
2493
2494 Query q = session.createQuery(sql);
2495
2496 QueryPos qPos = QueryPos.getInstance(q);
2497
2498 qPos.add(fileEntryId);
2499
2500 qPos.add(status);
2501
2502 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
2503 start, end);
2504 }
2505 catch (Exception e) {
2506 throw processException(e);
2507 }
2508 finally {
2509 if (list == null) {
2510 FinderCacheUtil.removeResult(finderPath, finderArgs);
2511 }
2512 else {
2513 cacheResult(list);
2514
2515 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2516 }
2517
2518 closeSession(session);
2519 }
2520 }
2521
2522 return list;
2523 }
2524
2525
2535 public DLFileVersion findByF_S_First(long fileEntryId, int status,
2536 OrderByComparator orderByComparator)
2537 throws NoSuchFileVersionException, SystemException {
2538 DLFileVersion dlFileVersion = fetchByF_S_First(fileEntryId, status,
2539 orderByComparator);
2540
2541 if (dlFileVersion != null) {
2542 return dlFileVersion;
2543 }
2544
2545 StringBundler msg = new StringBundler(6);
2546
2547 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2548
2549 msg.append("fileEntryId=");
2550 msg.append(fileEntryId);
2551
2552 msg.append(", status=");
2553 msg.append(status);
2554
2555 msg.append(StringPool.CLOSE_CURLY_BRACE);
2556
2557 throw new NoSuchFileVersionException(msg.toString());
2558 }
2559
2560
2569 public DLFileVersion fetchByF_S_First(long fileEntryId, int status,
2570 OrderByComparator orderByComparator) throws SystemException {
2571 List<DLFileVersion> list = findByF_S(fileEntryId, status, 0, 1,
2572 orderByComparator);
2573
2574 if (!list.isEmpty()) {
2575 return list.get(0);
2576 }
2577
2578 return null;
2579 }
2580
2581
2591 public DLFileVersion findByF_S_Last(long fileEntryId, int status,
2592 OrderByComparator orderByComparator)
2593 throws NoSuchFileVersionException, SystemException {
2594 DLFileVersion dlFileVersion = fetchByF_S_Last(fileEntryId, status,
2595 orderByComparator);
2596
2597 if (dlFileVersion != null) {
2598 return dlFileVersion;
2599 }
2600
2601 StringBundler msg = new StringBundler(6);
2602
2603 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2604
2605 msg.append("fileEntryId=");
2606 msg.append(fileEntryId);
2607
2608 msg.append(", status=");
2609 msg.append(status);
2610
2611 msg.append(StringPool.CLOSE_CURLY_BRACE);
2612
2613 throw new NoSuchFileVersionException(msg.toString());
2614 }
2615
2616
2625 public DLFileVersion fetchByF_S_Last(long fileEntryId, int status,
2626 OrderByComparator orderByComparator) throws SystemException {
2627 int count = countByF_S(fileEntryId, status);
2628
2629 List<DLFileVersion> list = findByF_S(fileEntryId, status, count - 1,
2630 count, orderByComparator);
2631
2632 if (!list.isEmpty()) {
2633 return list.get(0);
2634 }
2635
2636 return null;
2637 }
2638
2639
2650 public DLFileVersion[] findByF_S_PrevAndNext(long fileVersionId,
2651 long fileEntryId, int status, OrderByComparator orderByComparator)
2652 throws NoSuchFileVersionException, SystemException {
2653 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
2654
2655 Session session = null;
2656
2657 try {
2658 session = openSession();
2659
2660 DLFileVersion[] array = new DLFileVersionImpl[3];
2661
2662 array[0] = getByF_S_PrevAndNext(session, dlFileVersion,
2663 fileEntryId, status, orderByComparator, true);
2664
2665 array[1] = dlFileVersion;
2666
2667 array[2] = getByF_S_PrevAndNext(session, dlFileVersion,
2668 fileEntryId, status, orderByComparator, false);
2669
2670 return array;
2671 }
2672 catch (Exception e) {
2673 throw processException(e);
2674 }
2675 finally {
2676 closeSession(session);
2677 }
2678 }
2679
2680 protected DLFileVersion getByF_S_PrevAndNext(Session session,
2681 DLFileVersion dlFileVersion, long fileEntryId, int status,
2682 OrderByComparator orderByComparator, boolean previous) {
2683 StringBundler query = null;
2684
2685 if (orderByComparator != null) {
2686 query = new StringBundler(6 +
2687 (orderByComparator.getOrderByFields().length * 6));
2688 }
2689 else {
2690 query = new StringBundler(3);
2691 }
2692
2693 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2694
2695 query.append(_FINDER_COLUMN_F_S_FILEENTRYID_2);
2696
2697 query.append(_FINDER_COLUMN_F_S_STATUS_2);
2698
2699 if (orderByComparator != null) {
2700 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2701
2702 if (orderByConditionFields.length > 0) {
2703 query.append(WHERE_AND);
2704 }
2705
2706 for (int i = 0; i < orderByConditionFields.length; i++) {
2707 query.append(_ORDER_BY_ENTITY_ALIAS);
2708 query.append(orderByConditionFields[i]);
2709
2710 if ((i + 1) < orderByConditionFields.length) {
2711 if (orderByComparator.isAscending() ^ previous) {
2712 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2713 }
2714 else {
2715 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2716 }
2717 }
2718 else {
2719 if (orderByComparator.isAscending() ^ previous) {
2720 query.append(WHERE_GREATER_THAN);
2721 }
2722 else {
2723 query.append(WHERE_LESSER_THAN);
2724 }
2725 }
2726 }
2727
2728 query.append(ORDER_BY_CLAUSE);
2729
2730 String[] orderByFields = orderByComparator.getOrderByFields();
2731
2732 for (int i = 0; i < orderByFields.length; i++) {
2733 query.append(_ORDER_BY_ENTITY_ALIAS);
2734 query.append(orderByFields[i]);
2735
2736 if ((i + 1) < orderByFields.length) {
2737 if (orderByComparator.isAscending() ^ previous) {
2738 query.append(ORDER_BY_ASC_HAS_NEXT);
2739 }
2740 else {
2741 query.append(ORDER_BY_DESC_HAS_NEXT);
2742 }
2743 }
2744 else {
2745 if (orderByComparator.isAscending() ^ previous) {
2746 query.append(ORDER_BY_ASC);
2747 }
2748 else {
2749 query.append(ORDER_BY_DESC);
2750 }
2751 }
2752 }
2753 }
2754
2755 else {
2756 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2757 }
2758
2759 String sql = query.toString();
2760
2761 Query q = session.createQuery(sql);
2762
2763 q.setFirstResult(0);
2764 q.setMaxResults(2);
2765
2766 QueryPos qPos = QueryPos.getInstance(q);
2767
2768 qPos.add(fileEntryId);
2769
2770 qPos.add(status);
2771
2772 if (orderByComparator != null) {
2773 Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
2774
2775 for (Object value : values) {
2776 qPos.add(value);
2777 }
2778 }
2779
2780 List<DLFileVersion> list = q.list();
2781
2782 if (list.size() == 2) {
2783 return list.get(1);
2784 }
2785 else {
2786 return null;
2787 }
2788 }
2789
2790
2799 public List<DLFileVersion> findByG_F_S(long groupId, long folderId,
2800 int status) throws SystemException {
2801 return findByG_F_S(groupId, folderId, status, QueryUtil.ALL_POS,
2802 QueryUtil.ALL_POS, null);
2803 }
2804
2805
2820 public List<DLFileVersion> findByG_F_S(long groupId, long folderId,
2821 int status, int start, int end) throws SystemException {
2822 return findByG_F_S(groupId, folderId, status, start, end, null);
2823 }
2824
2825
2841 public List<DLFileVersion> findByG_F_S(long groupId, long folderId,
2842 int status, int start, int end, OrderByComparator orderByComparator)
2843 throws SystemException {
2844 FinderPath finderPath = null;
2845 Object[] finderArgs = null;
2846
2847 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2848 (orderByComparator == null)) {
2849 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S;
2850 finderArgs = new Object[] { groupId, folderId, status };
2851 }
2852 else {
2853 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_S;
2854 finderArgs = new Object[] {
2855 groupId, folderId, status,
2856
2857 start, end, orderByComparator
2858 };
2859 }
2860
2861 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
2862 finderArgs, this);
2863
2864 if ((list != null) && !list.isEmpty()) {
2865 for (DLFileVersion dlFileVersion : list) {
2866 if ((groupId != dlFileVersion.getGroupId()) ||
2867 (folderId != dlFileVersion.getFolderId()) ||
2868 (status != dlFileVersion.getStatus())) {
2869 list = null;
2870
2871 break;
2872 }
2873 }
2874 }
2875
2876 if (list == null) {
2877 StringBundler query = null;
2878
2879 if (orderByComparator != null) {
2880 query = new StringBundler(5 +
2881 (orderByComparator.getOrderByFields().length * 3));
2882 }
2883 else {
2884 query = new StringBundler(5);
2885 }
2886
2887 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2888
2889 query.append(_FINDER_COLUMN_G_F_S_GROUPID_2);
2890
2891 query.append(_FINDER_COLUMN_G_F_S_FOLDERID_2);
2892
2893 query.append(_FINDER_COLUMN_G_F_S_STATUS_2);
2894
2895 if (orderByComparator != null) {
2896 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2897 orderByComparator);
2898 }
2899
2900 else {
2901 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2902 }
2903
2904 String sql = query.toString();
2905
2906 Session session = null;
2907
2908 try {
2909 session = openSession();
2910
2911 Query q = session.createQuery(sql);
2912
2913 QueryPos qPos = QueryPos.getInstance(q);
2914
2915 qPos.add(groupId);
2916
2917 qPos.add(folderId);
2918
2919 qPos.add(status);
2920
2921 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
2922 start, end);
2923 }
2924 catch (Exception e) {
2925 throw processException(e);
2926 }
2927 finally {
2928 if (list == null) {
2929 FinderCacheUtil.removeResult(finderPath, finderArgs);
2930 }
2931 else {
2932 cacheResult(list);
2933
2934 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2935 }
2936
2937 closeSession(session);
2938 }
2939 }
2940
2941 return list;
2942 }
2943
2944
2955 public DLFileVersion findByG_F_S_First(long groupId, long folderId,
2956 int status, OrderByComparator orderByComparator)
2957 throws NoSuchFileVersionException, SystemException {
2958 DLFileVersion dlFileVersion = fetchByG_F_S_First(groupId, folderId,
2959 status, orderByComparator);
2960
2961 if (dlFileVersion != null) {
2962 return dlFileVersion;
2963 }
2964
2965 StringBundler msg = new StringBundler(8);
2966
2967 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2968
2969 msg.append("groupId=");
2970 msg.append(groupId);
2971
2972 msg.append(", folderId=");
2973 msg.append(folderId);
2974
2975 msg.append(", status=");
2976 msg.append(status);
2977
2978 msg.append(StringPool.CLOSE_CURLY_BRACE);
2979
2980 throw new NoSuchFileVersionException(msg.toString());
2981 }
2982
2983
2993 public DLFileVersion fetchByG_F_S_First(long groupId, long folderId,
2994 int status, OrderByComparator orderByComparator)
2995 throws SystemException {
2996 List<DLFileVersion> list = findByG_F_S(groupId, folderId, status, 0, 1,
2997 orderByComparator);
2998
2999 if (!list.isEmpty()) {
3000 return list.get(0);
3001 }
3002
3003 return null;
3004 }
3005
3006
3017 public DLFileVersion findByG_F_S_Last(long groupId, long folderId,
3018 int status, OrderByComparator orderByComparator)
3019 throws NoSuchFileVersionException, SystemException {
3020 DLFileVersion dlFileVersion = fetchByG_F_S_Last(groupId, folderId,
3021 status, orderByComparator);
3022
3023 if (dlFileVersion != null) {
3024 return dlFileVersion;
3025 }
3026
3027 StringBundler msg = new StringBundler(8);
3028
3029 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3030
3031 msg.append("groupId=");
3032 msg.append(groupId);
3033
3034 msg.append(", folderId=");
3035 msg.append(folderId);
3036
3037 msg.append(", status=");
3038 msg.append(status);
3039
3040 msg.append(StringPool.CLOSE_CURLY_BRACE);
3041
3042 throw new NoSuchFileVersionException(msg.toString());
3043 }
3044
3045
3055 public DLFileVersion fetchByG_F_S_Last(long groupId, long folderId,
3056 int status, OrderByComparator orderByComparator)
3057 throws SystemException {
3058 int count = countByG_F_S(groupId, folderId, status);
3059
3060 List<DLFileVersion> list = findByG_F_S(groupId, folderId, status,
3061 count - 1, count, orderByComparator);
3062
3063 if (!list.isEmpty()) {
3064 return list.get(0);
3065 }
3066
3067 return null;
3068 }
3069
3070
3082 public DLFileVersion[] findByG_F_S_PrevAndNext(long fileVersionId,
3083 long groupId, long folderId, int status,
3084 OrderByComparator orderByComparator)
3085 throws NoSuchFileVersionException, SystemException {
3086 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
3087
3088 Session session = null;
3089
3090 try {
3091 session = openSession();
3092
3093 DLFileVersion[] array = new DLFileVersionImpl[3];
3094
3095 array[0] = getByG_F_S_PrevAndNext(session, dlFileVersion, groupId,
3096 folderId, status, orderByComparator, true);
3097
3098 array[1] = dlFileVersion;
3099
3100 array[2] = getByG_F_S_PrevAndNext(session, dlFileVersion, groupId,
3101 folderId, status, orderByComparator, false);
3102
3103 return array;
3104 }
3105 catch (Exception e) {
3106 throw processException(e);
3107 }
3108 finally {
3109 closeSession(session);
3110 }
3111 }
3112
3113 protected DLFileVersion getByG_F_S_PrevAndNext(Session session,
3114 DLFileVersion dlFileVersion, long groupId, long folderId, int status,
3115 OrderByComparator orderByComparator, boolean previous) {
3116 StringBundler query = null;
3117
3118 if (orderByComparator != null) {
3119 query = new StringBundler(6 +
3120 (orderByComparator.getOrderByFields().length * 6));
3121 }
3122 else {
3123 query = new StringBundler(3);
3124 }
3125
3126 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
3127
3128 query.append(_FINDER_COLUMN_G_F_S_GROUPID_2);
3129
3130 query.append(_FINDER_COLUMN_G_F_S_FOLDERID_2);
3131
3132 query.append(_FINDER_COLUMN_G_F_S_STATUS_2);
3133
3134 if (orderByComparator != null) {
3135 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3136
3137 if (orderByConditionFields.length > 0) {
3138 query.append(WHERE_AND);
3139 }
3140
3141 for (int i = 0; i < orderByConditionFields.length; i++) {
3142 query.append(_ORDER_BY_ENTITY_ALIAS);
3143 query.append(orderByConditionFields[i]);
3144
3145 if ((i + 1) < orderByConditionFields.length) {
3146 if (orderByComparator.isAscending() ^ previous) {
3147 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3148 }
3149 else {
3150 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3151 }
3152 }
3153 else {
3154 if (orderByComparator.isAscending() ^ previous) {
3155 query.append(WHERE_GREATER_THAN);
3156 }
3157 else {
3158 query.append(WHERE_LESSER_THAN);
3159 }
3160 }
3161 }
3162
3163 query.append(ORDER_BY_CLAUSE);
3164
3165 String[] orderByFields = orderByComparator.getOrderByFields();
3166
3167 for (int i = 0; i < orderByFields.length; i++) {
3168 query.append(_ORDER_BY_ENTITY_ALIAS);
3169 query.append(orderByFields[i]);
3170
3171 if ((i + 1) < orderByFields.length) {
3172 if (orderByComparator.isAscending() ^ previous) {
3173 query.append(ORDER_BY_ASC_HAS_NEXT);
3174 }
3175 else {
3176 query.append(ORDER_BY_DESC_HAS_NEXT);
3177 }
3178 }
3179 else {
3180 if (orderByComparator.isAscending() ^ previous) {
3181 query.append(ORDER_BY_ASC);
3182 }
3183 else {
3184 query.append(ORDER_BY_DESC);
3185 }
3186 }
3187 }
3188 }
3189
3190 else {
3191 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
3192 }
3193
3194 String sql = query.toString();
3195
3196 Query q = session.createQuery(sql);
3197
3198 q.setFirstResult(0);
3199 q.setMaxResults(2);
3200
3201 QueryPos qPos = QueryPos.getInstance(q);
3202
3203 qPos.add(groupId);
3204
3205 qPos.add(folderId);
3206
3207 qPos.add(status);
3208
3209 if (orderByComparator != null) {
3210 Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
3211
3212 for (Object value : values) {
3213 qPos.add(value);
3214 }
3215 }
3216
3217 List<DLFileVersion> list = q.list();
3218
3219 if (list.size() == 2) {
3220 return list.get(1);
3221 }
3222 else {
3223 return null;
3224 }
3225 }
3226
3227
3237 public List<DLFileVersion> findByG_F_T_V(long groupId, long folderId,
3238 String title, String version) throws SystemException {
3239 return findByG_F_T_V(groupId, folderId, title, version,
3240 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3241 }
3242
3243
3259 public List<DLFileVersion> findByG_F_T_V(long groupId, long folderId,
3260 String title, String version, int start, int end)
3261 throws SystemException {
3262 return findByG_F_T_V(groupId, folderId, title, version, start, end, null);
3263 }
3264
3265
3282 public List<DLFileVersion> findByG_F_T_V(long groupId, long folderId,
3283 String title, String version, int start, int end,
3284 OrderByComparator orderByComparator) throws SystemException {
3285 FinderPath finderPath = null;
3286 Object[] finderArgs = null;
3287
3288 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3289 (orderByComparator == null)) {
3290 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V;
3291 finderArgs = new Object[] { groupId, folderId, title, version };
3292 }
3293 else {
3294 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_T_V;
3295 finderArgs = new Object[] {
3296 groupId, folderId, title, version,
3297
3298 start, end, orderByComparator
3299 };
3300 }
3301
3302 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
3303 finderArgs, this);
3304
3305 if ((list != null) && !list.isEmpty()) {
3306 for (DLFileVersion dlFileVersion : list) {
3307 if ((groupId != dlFileVersion.getGroupId()) ||
3308 (folderId != dlFileVersion.getFolderId()) ||
3309 !Validator.equals(title, dlFileVersion.getTitle()) ||
3310 !Validator.equals(version, dlFileVersion.getVersion())) {
3311 list = null;
3312
3313 break;
3314 }
3315 }
3316 }
3317
3318 if (list == null) {
3319 StringBundler query = null;
3320
3321 if (orderByComparator != null) {
3322 query = new StringBundler(6 +
3323 (orderByComparator.getOrderByFields().length * 3));
3324 }
3325 else {
3326 query = new StringBundler(6);
3327 }
3328
3329 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
3330
3331 query.append(_FINDER_COLUMN_G_F_T_V_GROUPID_2);
3332
3333 query.append(_FINDER_COLUMN_G_F_T_V_FOLDERID_2);
3334
3335 if (title == null) {
3336 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_1);
3337 }
3338 else {
3339 if (title.equals(StringPool.BLANK)) {
3340 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_3);
3341 }
3342 else {
3343 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_2);
3344 }
3345 }
3346
3347 if (version == null) {
3348 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_1);
3349 }
3350 else {
3351 if (version.equals(StringPool.BLANK)) {
3352 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_3);
3353 }
3354 else {
3355 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_2);
3356 }
3357 }
3358
3359 if (orderByComparator != null) {
3360 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3361 orderByComparator);
3362 }
3363
3364 else {
3365 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
3366 }
3367
3368 String sql = query.toString();
3369
3370 Session session = null;
3371
3372 try {
3373 session = openSession();
3374
3375 Query q = session.createQuery(sql);
3376
3377 QueryPos qPos = QueryPos.getInstance(q);
3378
3379 qPos.add(groupId);
3380
3381 qPos.add(folderId);
3382
3383 if (title != null) {
3384 qPos.add(title);
3385 }
3386
3387 if (version != null) {
3388 qPos.add(version);
3389 }
3390
3391 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
3392 start, end);
3393 }
3394 catch (Exception e) {
3395 throw processException(e);
3396 }
3397 finally {
3398 if (list == null) {
3399 FinderCacheUtil.removeResult(finderPath, finderArgs);
3400 }
3401 else {
3402 cacheResult(list);
3403
3404 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3405 }
3406
3407 closeSession(session);
3408 }
3409 }
3410
3411 return list;
3412 }
3413
3414
3426 public DLFileVersion findByG_F_T_V_First(long groupId, long folderId,
3427 String title, String version, OrderByComparator orderByComparator)
3428 throws NoSuchFileVersionException, SystemException {
3429 DLFileVersion dlFileVersion = fetchByG_F_T_V_First(groupId, folderId,
3430 title, version, orderByComparator);
3431
3432 if (dlFileVersion != null) {
3433 return dlFileVersion;
3434 }
3435
3436 StringBundler msg = new StringBundler(10);
3437
3438 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3439
3440 msg.append("groupId=");
3441 msg.append(groupId);
3442
3443 msg.append(", folderId=");
3444 msg.append(folderId);
3445
3446 msg.append(", title=");
3447 msg.append(title);
3448
3449 msg.append(", version=");
3450 msg.append(version);
3451
3452 msg.append(StringPool.CLOSE_CURLY_BRACE);
3453
3454 throw new NoSuchFileVersionException(msg.toString());
3455 }
3456
3457
3468 public DLFileVersion fetchByG_F_T_V_First(long groupId, long folderId,
3469 String title, String version, OrderByComparator orderByComparator)
3470 throws SystemException {
3471 List<DLFileVersion> list = findByG_F_T_V(groupId, folderId, title,
3472 version, 0, 1, orderByComparator);
3473
3474 if (!list.isEmpty()) {
3475 return list.get(0);
3476 }
3477
3478 return null;
3479 }
3480
3481
3493 public DLFileVersion findByG_F_T_V_Last(long groupId, long folderId,
3494 String title, String version, OrderByComparator orderByComparator)
3495 throws NoSuchFileVersionException, SystemException {
3496 DLFileVersion dlFileVersion = fetchByG_F_T_V_Last(groupId, folderId,
3497 title, version, orderByComparator);
3498
3499 if (dlFileVersion != null) {
3500 return dlFileVersion;
3501 }
3502
3503 StringBundler msg = new StringBundler(10);
3504
3505 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3506
3507 msg.append("groupId=");
3508 msg.append(groupId);
3509
3510 msg.append(", folderId=");
3511 msg.append(folderId);
3512
3513 msg.append(", title=");
3514 msg.append(title);
3515
3516 msg.append(", version=");
3517 msg.append(version);
3518
3519 msg.append(StringPool.CLOSE_CURLY_BRACE);
3520
3521 throw new NoSuchFileVersionException(msg.toString());
3522 }
3523
3524
3535 public DLFileVersion fetchByG_F_T_V_Last(long groupId, long folderId,
3536 String title, String version, OrderByComparator orderByComparator)
3537 throws SystemException {
3538 int count = countByG_F_T_V(groupId, folderId, title, version);
3539
3540 List<DLFileVersion> list = findByG_F_T_V(groupId, folderId, title,
3541 version, count - 1, count, orderByComparator);
3542
3543 if (!list.isEmpty()) {
3544 return list.get(0);
3545 }
3546
3547 return null;
3548 }
3549
3550
3563 public DLFileVersion[] findByG_F_T_V_PrevAndNext(long fileVersionId,
3564 long groupId, long folderId, String title, String version,
3565 OrderByComparator orderByComparator)
3566 throws NoSuchFileVersionException, SystemException {
3567 DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
3568
3569 Session session = null;
3570
3571 try {
3572 session = openSession();
3573
3574 DLFileVersion[] array = new DLFileVersionImpl[3];
3575
3576 array[0] = getByG_F_T_V_PrevAndNext(session, dlFileVersion,
3577 groupId, folderId, title, version, orderByComparator, true);
3578
3579 array[1] = dlFileVersion;
3580
3581 array[2] = getByG_F_T_V_PrevAndNext(session, dlFileVersion,
3582 groupId, folderId, title, version, orderByComparator, false);
3583
3584 return array;
3585 }
3586 catch (Exception e) {
3587 throw processException(e);
3588 }
3589 finally {
3590 closeSession(session);
3591 }
3592 }
3593
3594 protected DLFileVersion getByG_F_T_V_PrevAndNext(Session session,
3595 DLFileVersion dlFileVersion, long groupId, long folderId, String title,
3596 String version, OrderByComparator orderByComparator, boolean previous) {
3597 StringBundler query = null;
3598
3599 if (orderByComparator != null) {
3600 query = new StringBundler(6 +
3601 (orderByComparator.getOrderByFields().length * 6));
3602 }
3603 else {
3604 query = new StringBundler(3);
3605 }
3606
3607 query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
3608
3609 query.append(_FINDER_COLUMN_G_F_T_V_GROUPID_2);
3610
3611 query.append(_FINDER_COLUMN_G_F_T_V_FOLDERID_2);
3612
3613 if (title == null) {
3614 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_1);
3615 }
3616 else {
3617 if (title.equals(StringPool.BLANK)) {
3618 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_3);
3619 }
3620 else {
3621 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_2);
3622 }
3623 }
3624
3625 if (version == null) {
3626 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_1);
3627 }
3628 else {
3629 if (version.equals(StringPool.BLANK)) {
3630 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_3);
3631 }
3632 else {
3633 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_2);
3634 }
3635 }
3636
3637 if (orderByComparator != null) {
3638 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3639
3640 if (orderByConditionFields.length > 0) {
3641 query.append(WHERE_AND);
3642 }
3643
3644 for (int i = 0; i < orderByConditionFields.length; i++) {
3645 query.append(_ORDER_BY_ENTITY_ALIAS);
3646 query.append(orderByConditionFields[i]);
3647
3648 if ((i + 1) < orderByConditionFields.length) {
3649 if (orderByComparator.isAscending() ^ previous) {
3650 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3651 }
3652 else {
3653 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3654 }
3655 }
3656 else {
3657 if (orderByComparator.isAscending() ^ previous) {
3658 query.append(WHERE_GREATER_THAN);
3659 }
3660 else {
3661 query.append(WHERE_LESSER_THAN);
3662 }
3663 }
3664 }
3665
3666 query.append(ORDER_BY_CLAUSE);
3667
3668 String[] orderByFields = orderByComparator.getOrderByFields();
3669
3670 for (int i = 0; i < orderByFields.length; i++) {
3671 query.append(_ORDER_BY_ENTITY_ALIAS);
3672 query.append(orderByFields[i]);
3673
3674 if ((i + 1) < orderByFields.length) {
3675 if (orderByComparator.isAscending() ^ previous) {
3676 query.append(ORDER_BY_ASC_HAS_NEXT);
3677 }
3678 else {
3679 query.append(ORDER_BY_DESC_HAS_NEXT);
3680 }
3681 }
3682 else {
3683 if (orderByComparator.isAscending() ^ previous) {
3684 query.append(ORDER_BY_ASC);
3685 }
3686 else {
3687 query.append(ORDER_BY_DESC);
3688 }
3689 }
3690 }
3691 }
3692
3693 else {
3694 query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
3695 }
3696
3697 String sql = query.toString();
3698
3699 Query q = session.createQuery(sql);
3700
3701 q.setFirstResult(0);
3702 q.setMaxResults(2);
3703
3704 QueryPos qPos = QueryPos.getInstance(q);
3705
3706 qPos.add(groupId);
3707
3708 qPos.add(folderId);
3709
3710 if (title != null) {
3711 qPos.add(title);
3712 }
3713
3714 if (version != null) {
3715 qPos.add(version);
3716 }
3717
3718 if (orderByComparator != null) {
3719 Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
3720
3721 for (Object value : values) {
3722 qPos.add(value);
3723 }
3724 }
3725
3726 List<DLFileVersion> list = q.list();
3727
3728 if (list.size() == 2) {
3729 return list.get(1);
3730 }
3731 else {
3732 return null;
3733 }
3734 }
3735
3736
3742 public List<DLFileVersion> findAll() throws SystemException {
3743 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3744 }
3745
3746
3758 public List<DLFileVersion> findAll(int start, int end)
3759 throws SystemException {
3760 return findAll(start, end, null);
3761 }
3762
3763
3776 public List<DLFileVersion> findAll(int start, int end,
3777 OrderByComparator orderByComparator) throws SystemException {
3778 FinderPath finderPath = null;
3779 Object[] finderArgs = new Object[] { start, end, orderByComparator };
3780
3781 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3782 (orderByComparator == null)) {
3783 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3784 finderArgs = FINDER_ARGS_EMPTY;
3785 }
3786 else {
3787 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3788 finderArgs = new Object[] { start, end, orderByComparator };
3789 }
3790
3791 List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
3792 finderArgs, this);
3793
3794 if (list == null) {
3795 StringBundler query = null;
3796 String sql = null;
3797
3798 if (orderByComparator != null) {
3799 query = new StringBundler(2 +
3800 (orderByComparator.getOrderByFields().length * 3));
3801
3802 query.append(_SQL_SELECT_DLFILEVERSION);
3803
3804 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3805 orderByComparator);
3806
3807 sql = query.toString();
3808 }
3809 else {
3810 sql = _SQL_SELECT_DLFILEVERSION.concat(DLFileVersionModelImpl.ORDER_BY_JPQL);
3811 }
3812
3813 Session session = null;
3814
3815 try {
3816 session = openSession();
3817
3818 Query q = session.createQuery(sql);
3819
3820 if (orderByComparator == null) {
3821 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
3822 start, end, false);
3823
3824 Collections.sort(list);
3825 }
3826 else {
3827 list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
3828 start, end);
3829 }
3830 }
3831 catch (Exception e) {
3832 throw processException(e);
3833 }
3834 finally {
3835 if (list == null) {
3836 FinderCacheUtil.removeResult(finderPath, finderArgs);
3837 }
3838 else {
3839 cacheResult(list);
3840
3841 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3842 }
3843
3844 closeSession(session);
3845 }
3846 }
3847
3848 return list;
3849 }
3850
3851
3857 public void removeByUuid(String uuid) throws SystemException {
3858 for (DLFileVersion dlFileVersion : findByUuid(uuid)) {
3859 remove(dlFileVersion);
3860 }
3861 }
3862
3863
3871 public DLFileVersion removeByUUID_G(String uuid, long groupId)
3872 throws NoSuchFileVersionException, SystemException {
3873 DLFileVersion dlFileVersion = findByUUID_G(uuid, groupId);
3874
3875 return remove(dlFileVersion);
3876 }
3877
3878
3884 public void removeByFileEntryId(long fileEntryId) throws SystemException {
3885 for (DLFileVersion dlFileVersion : findByFileEntryId(fileEntryId)) {
3886 remove(dlFileVersion);
3887 }
3888 }
3889
3890
3896 public void removeByMimeType(String mimeType) throws SystemException {
3897 for (DLFileVersion dlFileVersion : findByMimeType(mimeType)) {
3898 remove(dlFileVersion);
3899 }
3900 }
3901
3902
3910 public DLFileVersion removeByF_V(long fileEntryId, String version)
3911 throws NoSuchFileVersionException, SystemException {
3912 DLFileVersion dlFileVersion = findByF_V(fileEntryId, version);
3913
3914 return remove(dlFileVersion);
3915 }
3916
3917
3924 public void removeByF_S(long fileEntryId, int status)
3925 throws SystemException {
3926 for (DLFileVersion dlFileVersion : findByF_S(fileEntryId, status)) {
3927 remove(dlFileVersion);
3928 }
3929 }
3930
3931
3939 public void removeByG_F_S(long groupId, long folderId, int status)
3940 throws SystemException {
3941 for (DLFileVersion dlFileVersion : findByG_F_S(groupId, folderId, status)) {
3942 remove(dlFileVersion);
3943 }
3944 }
3945
3946
3955 public void removeByG_F_T_V(long groupId, long folderId, String title,
3956 String version) throws SystemException {
3957 for (DLFileVersion dlFileVersion : findByG_F_T_V(groupId, folderId,
3958 title, version)) {
3959 remove(dlFileVersion);
3960 }
3961 }
3962
3963
3968 public void removeAll() throws SystemException {
3969 for (DLFileVersion dlFileVersion : findAll()) {
3970 remove(dlFileVersion);
3971 }
3972 }
3973
3974
3981 public int countByUuid(String uuid) throws SystemException {
3982 Object[] finderArgs = new Object[] { uuid };
3983
3984 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
3985 finderArgs, this);
3986
3987 if (count == null) {
3988 StringBundler query = new StringBundler(2);
3989
3990 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
3991
3992 if (uuid == null) {
3993 query.append(_FINDER_COLUMN_UUID_UUID_1);
3994 }
3995 else {
3996 if (uuid.equals(StringPool.BLANK)) {
3997 query.append(_FINDER_COLUMN_UUID_UUID_3);
3998 }
3999 else {
4000 query.append(_FINDER_COLUMN_UUID_UUID_2);
4001 }
4002 }
4003
4004 String sql = query.toString();
4005
4006 Session session = null;
4007
4008 try {
4009 session = openSession();
4010
4011 Query q = session.createQuery(sql);
4012
4013 QueryPos qPos = QueryPos.getInstance(q);
4014
4015 if (uuid != null) {
4016 qPos.add(uuid);
4017 }
4018
4019 count = (Long)q.uniqueResult();
4020 }
4021 catch (Exception e) {
4022 throw processException(e);
4023 }
4024 finally {
4025 if (count == null) {
4026 count = Long.valueOf(0);
4027 }
4028
4029 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
4030 finderArgs, count);
4031
4032 closeSession(session);
4033 }
4034 }
4035
4036 return count.intValue();
4037 }
4038
4039
4047 public int countByUUID_G(String uuid, long groupId)
4048 throws SystemException {
4049 Object[] finderArgs = new Object[] { uuid, groupId };
4050
4051 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
4052 finderArgs, this);
4053
4054 if (count == null) {
4055 StringBundler query = new StringBundler(3);
4056
4057 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
4058
4059 if (uuid == null) {
4060 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
4061 }
4062 else {
4063 if (uuid.equals(StringPool.BLANK)) {
4064 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
4065 }
4066 else {
4067 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
4068 }
4069 }
4070
4071 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
4072
4073 String sql = query.toString();
4074
4075 Session session = null;
4076
4077 try {
4078 session = openSession();
4079
4080 Query q = session.createQuery(sql);
4081
4082 QueryPos qPos = QueryPos.getInstance(q);
4083
4084 if (uuid != null) {
4085 qPos.add(uuid);
4086 }
4087
4088 qPos.add(groupId);
4089
4090 count = (Long)q.uniqueResult();
4091 }
4092 catch (Exception e) {
4093 throw processException(e);
4094 }
4095 finally {
4096 if (count == null) {
4097 count = Long.valueOf(0);
4098 }
4099
4100 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
4101 finderArgs, count);
4102
4103 closeSession(session);
4104 }
4105 }
4106
4107 return count.intValue();
4108 }
4109
4110
4117 public int countByFileEntryId(long fileEntryId) throws SystemException {
4118 Object[] finderArgs = new Object[] { fileEntryId };
4119
4120 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
4121 finderArgs, this);
4122
4123 if (count == null) {
4124 StringBundler query = new StringBundler(2);
4125
4126 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
4127
4128 query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
4129
4130 String sql = query.toString();
4131
4132 Session session = null;
4133
4134 try {
4135 session = openSession();
4136
4137 Query q = session.createQuery(sql);
4138
4139 QueryPos qPos = QueryPos.getInstance(q);
4140
4141 qPos.add(fileEntryId);
4142
4143 count = (Long)q.uniqueResult();
4144 }
4145 catch (Exception e) {
4146 throw processException(e);
4147 }
4148 finally {
4149 if (count == null) {
4150 count = Long.valueOf(0);
4151 }
4152
4153 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
4154 finderArgs, count);
4155
4156 closeSession(session);
4157 }
4158 }
4159
4160 return count.intValue();
4161 }
4162
4163
4170 public int countByMimeType(String mimeType) throws SystemException {
4171 Object[] finderArgs = new Object[] { mimeType };
4172
4173 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_MIMETYPE,
4174 finderArgs, this);
4175
4176 if (count == null) {
4177 StringBundler query = new StringBundler(2);
4178
4179 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
4180
4181 if (mimeType == null) {
4182 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_1);
4183 }
4184 else {
4185 if (mimeType.equals(StringPool.BLANK)) {
4186 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_3);
4187 }
4188 else {
4189 query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_2);
4190 }
4191 }
4192
4193 String sql = query.toString();
4194
4195 Session session = null;
4196
4197 try {
4198 session = openSession();
4199
4200 Query q = session.createQuery(sql);
4201
4202 QueryPos qPos = QueryPos.getInstance(q);
4203
4204 if (mimeType != null) {
4205 qPos.add(mimeType);
4206 }
4207
4208 count = (Long)q.uniqueResult();
4209 }
4210 catch (Exception e) {
4211 throw processException(e);
4212 }
4213 finally {
4214 if (count == null) {
4215 count = Long.valueOf(0);
4216 }
4217
4218 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MIMETYPE,
4219 finderArgs, count);
4220
4221 closeSession(session);
4222 }
4223 }
4224
4225 return count.intValue();
4226 }
4227
4228
4236 public int countByF_V(long fileEntryId, String version)
4237 throws SystemException {
4238 Object[] finderArgs = new Object[] { fileEntryId, version };
4239
4240 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_F_V,
4241 finderArgs, this);
4242
4243 if (count == null) {
4244 StringBundler query = new StringBundler(3);
4245
4246 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
4247
4248 query.append(_FINDER_COLUMN_F_V_FILEENTRYID_2);
4249
4250 if (version == null) {
4251 query.append(_FINDER_COLUMN_F_V_VERSION_1);
4252 }
4253 else {
4254 if (version.equals(StringPool.BLANK)) {
4255 query.append(_FINDER_COLUMN_F_V_VERSION_3);
4256 }
4257 else {
4258 query.append(_FINDER_COLUMN_F_V_VERSION_2);
4259 }
4260 }
4261
4262 String sql = query.toString();
4263
4264 Session session = null;
4265
4266 try {
4267 session = openSession();
4268
4269 Query q = session.createQuery(sql);
4270
4271 QueryPos qPos = QueryPos.getInstance(q);
4272
4273 qPos.add(fileEntryId);
4274
4275 if (version != null) {
4276 qPos.add(version);
4277 }
4278
4279 count = (Long)q.uniqueResult();
4280 }
4281 catch (Exception e) {
4282 throw processException(e);
4283 }
4284 finally {
4285 if (count == null) {
4286 count = Long.valueOf(0);
4287 }
4288
4289 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_V, finderArgs,
4290 count);
4291
4292 closeSession(session);
4293 }
4294 }
4295
4296 return count.intValue();
4297 }
4298
4299
4307 public int countByF_S(long fileEntryId, int status)
4308 throws SystemException {
4309 Object[] finderArgs = new Object[] { fileEntryId, status };
4310
4311 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_F_S,
4312 finderArgs, this);
4313
4314 if (count == null) {
4315 StringBundler query = new StringBundler(3);
4316
4317 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
4318
4319 query.append(_FINDER_COLUMN_F_S_FILEENTRYID_2);
4320
4321 query.append(_FINDER_COLUMN_F_S_STATUS_2);
4322
4323 String sql = query.toString();
4324
4325 Session session = null;
4326
4327 try {
4328 session = openSession();
4329
4330 Query q = session.createQuery(sql);
4331
4332 QueryPos qPos = QueryPos.getInstance(q);
4333
4334 qPos.add(fileEntryId);
4335
4336 qPos.add(status);
4337
4338 count = (Long)q.uniqueResult();
4339 }
4340 catch (Exception e) {
4341 throw processException(e);
4342 }
4343 finally {
4344 if (count == null) {
4345 count = Long.valueOf(0);
4346 }
4347
4348 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_S, finderArgs,
4349 count);
4350
4351 closeSession(session);
4352 }
4353 }
4354
4355 return count.intValue();
4356 }
4357
4358
4367 public int countByG_F_S(long groupId, long folderId, int status)
4368 throws SystemException {
4369 Object[] finderArgs = new Object[] { groupId, folderId, status };
4370
4371 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_S,
4372 finderArgs, this);
4373
4374 if (count == null) {
4375 StringBundler query = new StringBundler(4);
4376
4377 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
4378
4379 query.append(_FINDER_COLUMN_G_F_S_GROUPID_2);
4380
4381 query.append(_FINDER_COLUMN_G_F_S_FOLDERID_2);
4382
4383 query.append(_FINDER_COLUMN_G_F_S_STATUS_2);
4384
4385 String sql = query.toString();
4386
4387 Session session = null;
4388
4389 try {
4390 session = openSession();
4391
4392 Query q = session.createQuery(sql);
4393
4394 QueryPos qPos = QueryPos.getInstance(q);
4395
4396 qPos.add(groupId);
4397
4398 qPos.add(folderId);
4399
4400 qPos.add(status);
4401
4402 count = (Long)q.uniqueResult();
4403 }
4404 catch (Exception e) {
4405 throw processException(e);
4406 }
4407 finally {
4408 if (count == null) {
4409 count = Long.valueOf(0);
4410 }
4411
4412 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_S,
4413 finderArgs, count);
4414
4415 closeSession(session);
4416 }
4417 }
4418
4419 return count.intValue();
4420 }
4421
4422
4432 public int countByG_F_T_V(long groupId, long folderId, String title,
4433 String version) throws SystemException {
4434 Object[] finderArgs = new Object[] { groupId, folderId, title, version };
4435
4436 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_T_V,
4437 finderArgs, this);
4438
4439 if (count == null) {
4440 StringBundler query = new StringBundler(5);
4441
4442 query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
4443
4444 query.append(_FINDER_COLUMN_G_F_T_V_GROUPID_2);
4445
4446 query.append(_FINDER_COLUMN_G_F_T_V_FOLDERID_2);
4447
4448 if (title == null) {
4449 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_1);
4450 }
4451 else {
4452 if (title.equals(StringPool.BLANK)) {
4453 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_3);
4454 }
4455 else {
4456 query.append(_FINDER_COLUMN_G_F_T_V_TITLE_2);
4457 }
4458 }
4459
4460 if (version == null) {
4461 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_1);
4462 }
4463 else {
4464 if (version.equals(StringPool.BLANK)) {
4465 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_3);
4466 }
4467 else {
4468 query.append(_FINDER_COLUMN_G_F_T_V_VERSION_2);
4469 }
4470 }
4471
4472 String sql = query.toString();
4473
4474 Session session = null;
4475
4476 try {
4477 session = openSession();
4478
4479 Query q = session.createQuery(sql);
4480
4481 QueryPos qPos = QueryPos.getInstance(q);
4482
4483 qPos.add(groupId);
4484
4485 qPos.add(folderId);
4486
4487 if (title != null) {
4488 qPos.add(title);
4489 }
4490
4491 if (version != null) {
4492 qPos.add(version);
4493 }
4494
4495 count = (Long)q.uniqueResult();
4496 }
4497 catch (Exception e) {
4498 throw processException(e);
4499 }
4500 finally {
4501 if (count == null) {
4502 count = Long.valueOf(0);
4503 }
4504
4505 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_T_V,
4506 finderArgs, count);
4507
4508 closeSession(session);
4509 }
4510 }
4511
4512 return count.intValue();
4513 }
4514
4515
4521 public int countAll() throws SystemException {
4522 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4523 FINDER_ARGS_EMPTY, this);
4524
4525 if (count == null) {
4526 Session session = null;
4527
4528 try {
4529 session = openSession();
4530
4531 Query q = session.createQuery(_SQL_COUNT_DLFILEVERSION);
4532
4533 count = (Long)q.uniqueResult();
4534 }
4535 catch (Exception e) {
4536 throw processException(e);
4537 }
4538 finally {
4539 if (count == null) {
4540 count = Long.valueOf(0);
4541 }
4542
4543 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
4544 FINDER_ARGS_EMPTY, count);
4545
4546 closeSession(session);
4547 }
4548 }
4549
4550 return count.intValue();
4551 }
4552
4553
4556 public void afterPropertiesSet() {
4557 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4558 com.liferay.portal.util.PropsUtil.get(
4559 "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileVersion")));
4560
4561 if (listenerClassNames.length > 0) {
4562 try {
4563 List<ModelListener<DLFileVersion>> listenersList = new ArrayList<ModelListener<DLFileVersion>>();
4564
4565 for (String listenerClassName : listenerClassNames) {
4566 Class<?> clazz = getClass();
4567
4568 listenersList.add((ModelListener<DLFileVersion>)InstanceFactory.newInstance(
4569 clazz.getClassLoader(), listenerClassName));
4570 }
4571
4572 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4573 }
4574 catch (Exception e) {
4575 _log.error(e);
4576 }
4577 }
4578 }
4579
4580 public void destroy() {
4581 EntityCacheUtil.removeCache(DLFileVersionImpl.class.getName());
4582 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4583 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4584 }
4585
4586 @BeanReference(type = DLContentPersistence.class)
4587 protected DLContentPersistence dlContentPersistence;
4588 @BeanReference(type = DLFileEntryPersistence.class)
4589 protected DLFileEntryPersistence dlFileEntryPersistence;
4590 @BeanReference(type = DLFileEntryMetadataPersistence.class)
4591 protected DLFileEntryMetadataPersistence dlFileEntryMetadataPersistence;
4592 @BeanReference(type = DLFileEntryTypePersistence.class)
4593 protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
4594 @BeanReference(type = DLFileRankPersistence.class)
4595 protected DLFileRankPersistence dlFileRankPersistence;
4596 @BeanReference(type = DLFileShortcutPersistence.class)
4597 protected DLFileShortcutPersistence dlFileShortcutPersistence;
4598 @BeanReference(type = DLFileVersionPersistence.class)
4599 protected DLFileVersionPersistence dlFileVersionPersistence;
4600 @BeanReference(type = DLFolderPersistence.class)
4601 protected DLFolderPersistence dlFolderPersistence;
4602 @BeanReference(type = DLSyncPersistence.class)
4603 protected DLSyncPersistence dlSyncPersistence;
4604 @BeanReference(type = ResourcePersistence.class)
4605 protected ResourcePersistence resourcePersistence;
4606 @BeanReference(type = UserPersistence.class)
4607 protected UserPersistence userPersistence;
4608 private static final String _SQL_SELECT_DLFILEVERSION = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion";
4609 private static final String _SQL_SELECT_DLFILEVERSION_WHERE = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion WHERE ";
4610 private static final String _SQL_COUNT_DLFILEVERSION = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion";
4611 private static final String _SQL_COUNT_DLFILEVERSION_WHERE = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion WHERE ";
4612 private static final String _FINDER_COLUMN_UUID_UUID_1 = "dlFileVersion.uuid IS NULL";
4613 private static final String _FINDER_COLUMN_UUID_UUID_2 = "dlFileVersion.uuid = ?";
4614 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(dlFileVersion.uuid IS NULL OR dlFileVersion.uuid = ?)";
4615 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "dlFileVersion.uuid IS NULL AND ";
4616 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "dlFileVersion.uuid = ? AND ";
4617 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(dlFileVersion.uuid IS NULL OR dlFileVersion.uuid = ?) AND ";
4618 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "dlFileVersion.groupId = ?";
4619 private static final String _FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2 = "dlFileVersion.fileEntryId = ?";
4620 private static final String _FINDER_COLUMN_MIMETYPE_MIMETYPE_1 = "dlFileVersion.mimeType IS NULL";
4621 private static final String _FINDER_COLUMN_MIMETYPE_MIMETYPE_2 = "dlFileVersion.mimeType = ?";
4622 private static final String _FINDER_COLUMN_MIMETYPE_MIMETYPE_3 = "(dlFileVersion.mimeType IS NULL OR dlFileVersion.mimeType = ?)";
4623 private static final String _FINDER_COLUMN_F_V_FILEENTRYID_2 = "dlFileVersion.fileEntryId = ? AND ";
4624 private static final String _FINDER_COLUMN_F_V_VERSION_1 = "dlFileVersion.version IS NULL";
4625 private static final String _FINDER_COLUMN_F_V_VERSION_2 = "dlFileVersion.version = ?";
4626 private static final String _FINDER_COLUMN_F_V_VERSION_3 = "(dlFileVersion.version IS NULL OR dlFileVersion.version = ?)";
4627 private static final String _FINDER_COLUMN_F_S_FILEENTRYID_2 = "dlFileVersion.fileEntryId = ? AND ";
4628 private static final String _FINDER_COLUMN_F_S_STATUS_2 = "dlFileVersion.status = ?";
4629 private static final String _FINDER_COLUMN_G_F_S_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
4630 private static final String _FINDER_COLUMN_G_F_S_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
4631 private static final String _FINDER_COLUMN_G_F_S_STATUS_2 = "dlFileVersion.status = ?";
4632 private static final String _FINDER_COLUMN_G_F_T_V_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
4633 private static final String _FINDER_COLUMN_G_F_T_V_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
4634 private static final String _FINDER_COLUMN_G_F_T_V_TITLE_1 = "dlFileVersion.title IS NULL AND ";
4635 private static final String _FINDER_COLUMN_G_F_T_V_TITLE_2 = "dlFileVersion.title = ? AND ";
4636 private static final String _FINDER_COLUMN_G_F_T_V_TITLE_3 = "(dlFileVersion.title IS NULL OR dlFileVersion.title = ?) AND ";
4637 private static final String _FINDER_COLUMN_G_F_T_V_VERSION_1 = "dlFileVersion.version IS NULL";
4638 private static final String _FINDER_COLUMN_G_F_T_V_VERSION_2 = "dlFileVersion.version = ?";
4639 private static final String _FINDER_COLUMN_G_F_T_V_VERSION_3 = "(dlFileVersion.version IS NULL OR dlFileVersion.version = ?)";
4640 private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileVersion.";
4641 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileVersion exists with the primary key ";
4642 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileVersion exists with the key {";
4643 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
4644 private static Log _log = LogFactoryUtil.getLog(DLFileVersionPersistenceImpl.class);
4645 private static DLFileVersion _nullDLFileVersion = new DLFileVersionImpl() {
4646 @Override
4647 public Object clone() {
4648 return this;
4649 }
4650
4651 @Override
4652 public CacheModel<DLFileVersion> toCacheModel() {
4653 return _nullDLFileVersionCacheModel;
4654 }
4655 };
4656
4657 private static CacheModel<DLFileVersion> _nullDLFileVersionCacheModel = new CacheModel<DLFileVersion>() {
4658 public DLFileVersion toEntityModel() {
4659 return _nullDLFileVersion;
4660 }
4661 };
4662 }