001
014
015 package com.liferay.portlet.documentlibrary.service.persistence.impl;
016
017 import com.liferay.portal.kernel.dao.orm.QueryDefinition;
018 import com.liferay.portal.kernel.dao.orm.QueryPos;
019 import com.liferay.portal.kernel.dao.orm.QueryUtil;
020 import com.liferay.portal.kernel.dao.orm.SQLQuery;
021 import com.liferay.portal.kernel.dao.orm.Session;
022 import com.liferay.portal.kernel.dao.orm.Type;
023 import com.liferay.portal.kernel.exception.SystemException;
024 import com.liferay.portal.kernel.util.ArrayUtil;
025 import com.liferay.portal.kernel.util.DateRange;
026 import com.liferay.portal.kernel.util.ListUtil;
027 import com.liferay.portal.kernel.util.StringBundler;
028 import com.liferay.portal.kernel.util.StringPool;
029 import com.liferay.portal.kernel.util.StringUtil;
030 import com.liferay.portal.kernel.workflow.WorkflowConstants;
031 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
032 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
033 import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
034 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
035 import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryImpl;
036 import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionImpl;
037 import com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryFinder;
038 import com.liferay.util.dao.orm.CustomSQLUtil;
039
040 import java.util.Collections;
041 import java.util.Iterator;
042 import java.util.List;
043
044
048 public class DLFileEntryFinderImpl
049 extends BasePersistenceImpl<DLFileEntry> implements DLFileEntryFinder {
050
051 public static final String COUNT_BY_EXTRA_SETTINGS =
052 DLFileEntryFinder.class.getName() + ".countByExtraSettings";
053
054 public static final String COUNT_BY_G_F =
055 DLFileEntryFinder.class.getName() + ".countByG_F";
056
057 public static final String COUNT_BY_G_M_R =
058 DLFileEntryFinder.class.getName() + ".countByG_M_R";
059
060 public static final String COUNT_BY_G_U_F =
061 DLFileEntryFinder.class.getName() + ".countByG_U_F";
062
063 public static final String FIND_BY_ANY_IMAGE_ID =
064 DLFileEntryFinder.class.getName() + ".findByAnyImageId";
065
066 public static final String FIND_BY_COMPANY_ID =
067 DLFileEntryFinder.class.getName() + ".findByCompanyId";
068
069 public static final String FIND_BY_EXTRA_SETTINGS =
070 DLFileEntryFinder.class.getName() + ".findByExtraSettings";
071
072 public static final String FIND_BY_DDM_STRUCTURE_IDS =
073 DLFileEntryFinder.class.getName() + ".findByDDMStructureIds";
074
075 public static final String FIND_BY_MISVERSIONED =
076 DLFileEntryFinder.class.getName() + ".findByMisversioned";
077
078 public static final String FIND_BY_NO_ASSETS =
079 DLFileEntryFinder.class.getName() + ".findByNoAssets";
080
081 public static final String FIND_BY_ORPHANED_FILE_ENTRIES =
082 DLFileEntryFinder.class.getName() + ".findByOrphanedFileEntries";
083
084 public static final String FIND_BY_G_F =
085 DLFileEntryFinder.class.getName() + ".findByG_F";
086
087 public static final String FIND_BY_G_U_F =
088 DLFileEntryFinder.class.getName() + ".findByG_U_F";
089
090 @Override
091 public int countByExtraSettings() {
092 Session session = null;
093
094 try {
095 session = openSession();
096
097 String sql = CustomSQLUtil.get(COUNT_BY_EXTRA_SETTINGS);
098
099 SQLQuery q = session.createSynchronizedSQLQuery(sql);
100
101 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
102
103 Iterator<Long> itr = q.iterate();
104
105 if (itr.hasNext()) {
106 Long count = itr.next();
107
108 if (count != null) {
109 return count.intValue();
110 }
111 }
112
113 return 0;
114 }
115 catch (Exception e) {
116 throw new SystemException(e);
117 }
118 finally {
119 closeSession(session);
120 }
121 }
122
123 @Override
124 public int countByG_F(
125 long groupId, List<Long> folderIds,
126 QueryDefinition<DLFileEntry> queryDefinition) {
127
128 List<Long> repositoryIds = Collections.emptyList();
129
130 return doCountByG_U_R_F_M(
131 groupId, 0, repositoryIds, folderIds, null, queryDefinition, false);
132 }
133
134 @Override
135 public int countByG_M_R(
136 long groupId, DateRange dateRange, long repositoryId,
137 QueryDefinition<DLFileEntry> queryDefinition) {
138
139 Session session = null;
140
141 try {
142 session = openSession();
143
144 String sql = getFileEntriesSQL(
145 COUNT_BY_G_M_R, groupId, null, null, null, queryDefinition,
146 false);
147
148 if ((dateRange == null) || (dateRange.getStartDate() == null)) {
149 sql = StringUtil.replace(
150 sql, "(DLFileEntry.modifiedDate >= ?) AND",
151 StringPool.BLANK);
152 }
153
154 if ((dateRange == null) || (dateRange.getEndDate() == null)) {
155 sql = StringUtil.replace(
156 sql, "(DLFileEntry.modifiedDate <= ?) AND",
157 StringPool.BLANK);
158 }
159
160 SQLQuery q = session.createSynchronizedSQLQuery(sql);
161
162 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
163
164 QueryPos qPos = QueryPos.getInstance(q);
165
166 qPos.add(groupId);
167
168 if ((dateRange != null) && (dateRange.getStartDate() != null)) {
169 qPos.add(dateRange.getStartDate());
170 }
171
172 if ((dateRange != null) && (dateRange.getEndDate() != null)) {
173 qPos.add(dateRange.getEndDate());
174 }
175
176 qPos.add(repositoryId);
177 qPos.add(queryDefinition.getStatus());
178
179 Iterator<Long> itr = q.iterate();
180
181 if (itr.hasNext()) {
182 Long count = itr.next();
183
184 if (count != null) {
185 return count.intValue();
186 }
187 }
188
189 return 0;
190 }
191 catch (Exception e) {
192 throw new SystemException(e);
193 }
194 finally {
195 closeSession(session);
196 }
197 }
198
199 @Override
200 public int countByG_R_F(
201 long groupId, List<Long> repositoryIds, List<Long> folderIds,
202 QueryDefinition<DLFileEntry> queryDefinition) {
203
204 return doCountByG_U_R_F_M(
205 groupId, 0, repositoryIds, folderIds, null, queryDefinition, false);
206 }
207
208 @Override
209 public int countByG_U_F_M(
210 long groupId, long userId, List<Long> folderIds, String[] mimeTypes,
211 QueryDefinition<DLFileEntry> queryDefinition) {
212
213 List<Long> repositoryIds = Collections.emptyList();
214
215 return doCountByG_U_R_F_M(
216 groupId, userId, repositoryIds, folderIds, mimeTypes,
217 queryDefinition, false);
218 }
219
220 @Override
221 public int countByG_U_R_F_M(
222 long groupId, long userId, List<Long> repositoryIds,
223 List<Long> folderIds, String[] mimeTypes,
224 QueryDefinition<DLFileEntry> queryDefinition) {
225
226 return doCountByG_U_R_F_M(
227 groupId, userId, repositoryIds, folderIds, mimeTypes,
228 queryDefinition, false);
229 }
230
231 @Override
232 public int filterCountByG_U_F_M(
233 long groupId, long userId, List<Long> folderIds, String[] mimeTypes,
234 QueryDefinition<DLFileEntry> queryDefinition) {
235
236 List<Long> repositoryIds = Collections.emptyList();
237
238 return doCountByG_U_R_F_M(
239 groupId, userId, repositoryIds, folderIds, mimeTypes,
240 queryDefinition, true);
241 }
242
243 @Override
244 public int filterCountByG_U_R_F_M(
245 long groupId, long userId, List<Long> repositoryIds,
246 List<Long> folderIds, String[] mimeTypes,
247 QueryDefinition<DLFileEntry> queryDefinition) {
248
249 return doCountByG_U_R_F_M(
250 groupId, userId, repositoryIds, folderIds, mimeTypes,
251 queryDefinition, true);
252 }
253
254 @Override
255 public DLFileEntry fetchByAnyImageId(long imageId) {
256 Session session = null;
257
258 try {
259 session = openSession();
260
261 String sql = CustomSQLUtil.get(FIND_BY_ANY_IMAGE_ID);
262
263 SQLQuery q = session.createSynchronizedSQLQuery(sql);
264
265 q.addEntity(DLFileEntryImpl.TABLE_NAME, DLFileEntryImpl.class);
266
267 q.setMaxResults(1);
268
269 QueryPos qPos = QueryPos.getInstance(q);
270
271 qPos.add(imageId);
272 qPos.add(imageId);
273 qPos.add(imageId);
274 qPos.add(imageId);
275
276 List<DLFileEntry> dlFileEntries = q.list();
277
278 if (!dlFileEntries.isEmpty()) {
279 return dlFileEntries.get(0);
280 }
281
282 return null;
283 }
284 catch (Exception e) {
285 throw new SystemException(e);
286 }
287 finally {
288 closeSession(session);
289 }
290 }
291
292 @Override
293 public int filterCountByG_F(
294 long groupId, List<Long> folderIds,
295 QueryDefinition<DLFileEntry> queryDefinition) {
296
297 List<Long> repositoryIds = Collections.emptyList();
298
299 return doCountByG_U_R_F_M(
300 groupId, 0, repositoryIds, folderIds, null, queryDefinition, true);
301 }
302
303 @Override
304 public int filterCountByG_R_F(
305 long groupId, List<Long> repositoryIds, List<Long> folderIds,
306 QueryDefinition<DLFileEntry> queryDefinition) {
307
308 return doCountByG_U_R_F_M(
309 groupId, 0, repositoryIds, folderIds, null, queryDefinition, true);
310 }
311
312 @Override
313 public List<DLFileEntry> filterFindByG_F(
314 long groupId, List<Long> folderIds,
315 QueryDefinition<DLFileEntry> queryDefinition) {
316
317 List<Long> repositoryIds = Collections.emptyList();
318
319 return doFindByG_U_R_F_M(
320 groupId, 0, repositoryIds, folderIds, null, queryDefinition, true);
321 }
322
323 @Override
324 public List<DLFileEntry> filterFindByG_R_F(
325 long groupId, List<Long> repositoryIds, List<Long> folderIds,
326 QueryDefinition<DLFileEntry> queryDefinition) {
327
328 return doFindByG_U_R_F_M(
329 groupId, 0, repositoryIds, folderIds, null, queryDefinition, true);
330 }
331
332 @Override
333 public List<DLFileEntry> filterFindByG_U_F_M(
334 long groupId, long userId, List<Long> folderIds, String[] mimeTypes,
335 QueryDefinition<DLFileEntry> queryDefinition) {
336
337 List<Long> repositoryIds = Collections.emptyList();
338
339 return doFindByG_U_R_F_M(
340 groupId, userId, repositoryIds, folderIds, mimeTypes,
341 queryDefinition, true);
342 }
343
344 @Override
345 public List<DLFileEntry> filterFindByG_U_R_F_M(
346 long groupId, long userId, List<Long> repositoryIds,
347 List<Long> folderIds, String[] mimeTypes,
348 QueryDefinition<DLFileEntry> queryDefinition) {
349
350 return doFindByG_U_R_F_M(
351 groupId, userId, repositoryIds, folderIds, mimeTypes,
352 queryDefinition, true);
353 }
354
355 @Override
356 public DLFileEntry findByAnyImageId(long imageId)
357 throws NoSuchFileEntryException {
358
359 DLFileEntry dlFileEntry = fetchByAnyImageId(imageId);
360
361 if (dlFileEntry != null) {
362 return dlFileEntry;
363 }
364
365 throw new NoSuchFileEntryException(
366 "No DLFileEntry exists with the imageId " + imageId);
367 }
368
369 @Override
370 public List<DLFileEntry> findByCompanyId(
371 long companyId, QueryDefinition<DLFileEntry> queryDefinition) {
372
373 Session session = null;
374
375 try {
376 session = openSession();
377
378 String sql = CustomSQLUtil.get(
379 FIND_BY_COMPANY_ID, queryDefinition,
380 DLFileVersionImpl.TABLE_NAME);
381
382 sql = CustomSQLUtil.replaceOrderBy(
383 sql, queryDefinition.getOrderByComparator());
384
385 SQLQuery q = session.createSynchronizedSQLQuery(sql);
386
387 q.addEntity(DLFileEntryImpl.TABLE_NAME, DLFileEntryImpl.class);
388
389 QueryPos qPos = QueryPos.getInstance(q);
390
391 qPos.add(companyId);
392 qPos.add(queryDefinition.getStatus());
393
394 return (List<DLFileEntry>)QueryUtil.list(
395 q, getDialect(), queryDefinition.getStart(),
396 queryDefinition.getEnd());
397 }
398 catch (Exception e) {
399 throw new SystemException(e);
400 }
401 finally {
402 closeSession(session);
403 }
404 }
405
406 @Override
407 public List<DLFileEntry> findByDDMStructureIds(
408 long[] ddmStructureIds, int start, int end) {
409
410 Session session = null;
411
412 try {
413 session = openSession();
414
415 String sql = CustomSQLUtil.get(FIND_BY_DDM_STRUCTURE_IDS);
416
417 if ((ddmStructureIds == null) || (ddmStructureIds.length <= 0)) {
418 return Collections.emptyList();
419 }
420
421 sql = StringUtil.replace(
422 sql, "[$DDM_STRUCTURE_ID$]",
423 getDDMStructureIds(ddmStructureIds));
424
425 SQLQuery q = session.createSynchronizedSQLQuery(sql);
426
427 q.addEntity(DLFileEntryImpl.TABLE_NAME, DLFileEntryImpl.class);
428
429 QueryPos qPos = QueryPos.getInstance(q);
430
431 qPos.add(ddmStructureIds);
432
433 return (List<DLFileEntry>)QueryUtil.list(
434 q, getDialect(), start, end);
435 }
436 catch (Exception e) {
437 throw new SystemException(e);
438 }
439 finally {
440 closeSession(session);
441 }
442 }
443
444 @Override
445 public List<DLFileEntry> findByExtraSettings(int start, int end) {
446 Session session = null;
447
448 try {
449 session = openSession();
450
451 String sql = CustomSQLUtil.get(FIND_BY_EXTRA_SETTINGS);
452
453 SQLQuery q = session.createSynchronizedSQLQuery(sql);
454
455 q.addEntity(DLFileEntryImpl.TABLE_NAME, DLFileEntryImpl.class);
456
457 return (List<DLFileEntry>)QueryUtil.list(
458 q, getDialect(), start, end);
459 }
460 catch (Exception e) {
461 throw new SystemException(e);
462 }
463 finally {
464 closeSession(session);
465 }
466 }
467
468 @Override
469 public List<DLFileEntry> findByMisversioned() {
470 Session session = null;
471
472 try {
473 session = openSession();
474
475 String sql = CustomSQLUtil.get(FIND_BY_MISVERSIONED);
476
477 SQLQuery q = session.createSynchronizedSQLQuery(sql);
478
479 q.addEntity(DLFileEntryImpl.TABLE_NAME, DLFileEntryImpl.class);
480
481 return q.list(true);
482 }
483 catch (Exception e) {
484 throw new SystemException(e);
485 }
486 finally {
487 closeSession(session);
488 }
489 }
490
491 @Override
492 public List<DLFileEntry> findByNoAssets() {
493 Session session = null;
494
495 try {
496 session = openSession();
497
498 String sql = CustomSQLUtil.get(FIND_BY_NO_ASSETS);
499
500 SQLQuery q = session.createSynchronizedSQLQuery(sql);
501
502 q.addEntity(DLFileEntryImpl.TABLE_NAME, DLFileEntryImpl.class);
503
504 return q.list(true);
505 }
506 catch (Exception e) {
507 throw new SystemException(e);
508 }
509 finally {
510 closeSession(session);
511 }
512 }
513
514 @Override
515 public List<DLFileEntry> findByOrphanedFileEntries() {
516 Session session = null;
517
518 try {
519 session = openSession();
520
521 String sql = CustomSQLUtil.get(FIND_BY_ORPHANED_FILE_ENTRIES);
522
523 SQLQuery q = session.createSynchronizedSQLQuery(sql);
524
525 q.addEntity(DLFileEntryImpl.TABLE_NAME, DLFileEntryImpl.class);
526
527 return q.list(true);
528 }
529 catch (Exception e) {
530 throw new SystemException(e);
531 }
532 finally {
533 closeSession(session);
534 }
535 }
536
537 @Override
538 public List<DLFileEntry> findByG_F(
539 long groupId, List<Long> folderIds,
540 QueryDefinition<DLFileEntry> queryDefinition) {
541
542 List<Long> repositoryIds = Collections.emptyList();
543
544 return doFindByG_U_R_F_M(
545 groupId, 0, repositoryIds, folderIds, null, queryDefinition, false);
546 }
547
548 @Override
549 public List<DLFileEntry> findByG_R_F(
550 long groupId, List<Long> repositoryIds, List<Long> folderIds,
551 QueryDefinition<DLFileEntry> queryDefinition) {
552
553 return doFindByG_U_R_F_M(
554 groupId, 0, repositoryIds, folderIds, null, queryDefinition, false);
555 }
556
557 @Override
558 public List<DLFileEntry> findByG_U_F(
559 long groupId, long userId, List<Long> folderIds,
560 QueryDefinition<DLFileEntry> queryDefinition) {
561
562 List<Long> repositoryIds = Collections.emptyList();
563
564 return doFindByG_U_R_F_M(
565 groupId, userId, repositoryIds, folderIds, null, queryDefinition,
566 false);
567 }
568
569 @Override
570 public List<DLFileEntry> findByG_U_R_F(
571 long groupId, long userId, List<Long> repositoryIds,
572 List<Long> folderIds, QueryDefinition<DLFileEntry> queryDefinition) {
573
574 return doFindByG_U_R_F_M(
575 groupId, userId, repositoryIds, folderIds, null, queryDefinition,
576 false);
577 }
578
579 @Override
580 public List<DLFileEntry> findByG_U_F_M(
581 long groupId, long userId, List<Long> folderIds, String[] mimeTypes,
582 QueryDefinition<DLFileEntry> queryDefinition) {
583
584 List<Long> repositoryIds = Collections.emptyList();
585
586 return doFindByG_U_R_F_M(
587 groupId, userId, repositoryIds, folderIds, mimeTypes,
588 queryDefinition, false);
589 }
590
591 @Override
592 public List<DLFileEntry> findByG_U_R_F_M(
593 long groupId, long userId, List<Long> repositoryIds,
594 List<Long> folderIds, String[] mimeTypes,
595 QueryDefinition<DLFileEntry> queryDefinition) {
596
597 return doFindByG_U_R_F_M(
598 groupId, userId, repositoryIds, folderIds, mimeTypes,
599 queryDefinition, false);
600 }
601
602 protected int doCountByG_U_R_F_M(
603 long groupId, long userId, List<Long> repositoryIds,
604 List<Long> folderIds, String[] mimeTypes,
605 QueryDefinition<DLFileEntry> queryDefinition, boolean inlineSQLHelper) {
606
607 Session session = null;
608
609 try {
610 session = openSession();
611
612 String id = null;
613
614 if (userId <= 0) {
615 id = COUNT_BY_G_F;
616 }
617 else {
618 id = COUNT_BY_G_U_F;
619 }
620
621 String sql = getFileEntriesSQL(
622 id, groupId, repositoryIds, folderIds, mimeTypes,
623 queryDefinition, inlineSQLHelper);
624
625 SQLQuery q = session.createSynchronizedSQLQuery(sql);
626
627 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
628
629 QueryPos qPos = QueryPos.getInstance(q);
630
631 qPos.add(groupId);
632
633 if (userId > 0) {
634 qPos.add(userId);
635 }
636
637 qPos.add(queryDefinition.getStatus());
638
639 for (Long repositoryId : repositoryIds) {
640 qPos.add(repositoryId);
641 }
642
643 for (Long folderId : folderIds) {
644 qPos.add(folderId);
645 }
646
647 if (mimeTypes != null) {
648 qPos.add(mimeTypes);
649 }
650
651 Iterator<Long> itr = q.iterate();
652
653 if (itr.hasNext()) {
654 Long count = itr.next();
655
656 if (count != null) {
657 return count.intValue();
658 }
659 }
660
661 return 0;
662 }
663 catch (Exception e) {
664 throw new SystemException(e);
665 }
666 finally {
667 closeSession(session);
668 }
669 }
670
671 protected List<DLFileEntry> doFindByG_U_R_F_M(
672 long groupId, long userId, List<Long> repositoryIds,
673 List<Long> folderIds, String[] mimeTypes,
674 QueryDefinition<DLFileEntry> queryDefinition, boolean inlineSQLHelper) {
675
676 Session session = null;
677
678 try {
679 session = openSession();
680
681 String id = null;
682
683 if (userId <= 0) {
684 id = FIND_BY_G_F;
685 }
686 else {
687 id = FIND_BY_G_U_F;
688 }
689
690 String sql = getFileEntriesSQL(
691 id, groupId, repositoryIds, folderIds, mimeTypes,
692 queryDefinition, inlineSQLHelper);
693
694 sql = CustomSQLUtil.replaceOrderBy(
695 sql, queryDefinition.getOrderByComparator());
696
697 SQLQuery q = session.createSynchronizedSQLQuery(sql);
698
699 q.addEntity(DLFileEntryImpl.TABLE_NAME, DLFileEntryImpl.class);
700
701 QueryPos qPos = QueryPos.getInstance(q);
702
703 qPos.add(groupId);
704
705 if (userId > 0) {
706 qPos.add(userId);
707 }
708
709 qPos.add(queryDefinition.getStatus());
710
711 for (Long repositoryId : repositoryIds) {
712 qPos.add(repositoryId);
713 }
714
715 for (Long folderId : folderIds) {
716 qPos.add(folderId);
717 }
718
719 if (mimeTypes != null) {
720 qPos.add(mimeTypes);
721 }
722
723 return (List<DLFileEntry>)QueryUtil.list(
724 q, getDialect(), queryDefinition.getStart(),
725 queryDefinition.getEnd());
726 }
727 catch (Exception e) {
728 throw new SystemException(e);
729 }
730 finally {
731 closeSession(session);
732 }
733 }
734
735 protected String getDDMStructureIds(long[] ddmStructureIds) {
736 StringBundler sb = new StringBundler(
737 (ddmStructureIds.length * 2 - 1) + 2);
738
739 sb.append(StringPool.OPEN_PARENTHESIS);
740
741 for (int i = 0; i < ddmStructureIds.length; i++) {
742 sb.append("DLFileEntryTypes_DDMStructures.structureId = ?");
743
744 if ((i + 1) != ddmStructureIds.length) {
745 sb.append(WHERE_OR);
746 }
747 }
748
749 sb.append(StringPool.CLOSE_PARENTHESIS);
750
751 return sb.toString();
752 }
753
754 protected String getFileEntriesSQL(
755 String id, long groupId, List<Long> repositoryIds, List<Long> folderIds,
756 String[] mimeTypes, QueryDefinition<DLFileEntry> queryDefinition,
757 boolean inlineSQLHelper) {
758
759 String tableName = DLFileVersionImpl.TABLE_NAME;
760
761 String sql = CustomSQLUtil.get(id, queryDefinition, tableName);
762
763 if (queryDefinition.getStatus() == WorkflowConstants.STATUS_ANY) {
764 sql = StringUtil.replace(sql, "[$JOIN$]", StringPool.BLANK);
765
766 tableName = DLFileEntryImpl.TABLE_NAME;
767 }
768 else {
769 sql = StringUtil.replace(
770 sql, "[$JOIN$]",
771 CustomSQLUtil.get(
772 DLFolderFinderImpl.JOIN_FE_BY_DL_FILE_VERSION));
773 }
774
775 if (inlineSQLHelper && InlineSQLHelperUtil.isEnabled()) {
776 sql = InlineSQLHelperUtil.replacePermissionCheck(
777 sql, DLFileEntry.class.getName(), "DLFileEntry.fileEntryId",
778 groupId);
779 }
780
781 StringBundler sb = new StringBundler(7);
782
783 if (ListUtil.isNotEmpty(repositoryIds) ||
784 ListUtil.isNotEmpty(folderIds) ||
785 ArrayUtil.isNotEmpty(mimeTypes)) {
786
787 if (ListUtil.isNotEmpty(repositoryIds)) {
788 sb.append(WHERE_AND);
789 sb.append(StringPool.OPEN_PARENTHESIS);
790 sb.append(getRepositoryIds(repositoryIds, tableName));
791 sb.append(StringPool.CLOSE_PARENTHESIS);
792 }
793
794 if (ListUtil.isNotEmpty(folderIds)) {
795 sb.append(WHERE_AND);
796 sb.append(StringPool.OPEN_PARENTHESIS);
797 sb.append(getFolderIds(folderIds, tableName));
798 sb.append(StringPool.CLOSE_PARENTHESIS);
799 }
800
801 if (ArrayUtil.isNotEmpty(mimeTypes)) {
802 sb.append(WHERE_AND);
803 sb.append(StringPool.OPEN_PARENTHESIS);
804 sb.append(getMimeTypes(mimeTypes, tableName));
805 sb.append(StringPool.CLOSE_PARENTHESIS);
806 }
807
808 return StringUtil.replace(sql, "[$FOLDER_ID$]", sb.toString());
809 }
810 else {
811 return StringUtil.replace(sql, "[$FOLDER_ID$]", StringPool.BLANK);
812 }
813 }
814
815 protected String getFolderIds(List<Long> folderIds, String tableName) {
816 if (folderIds.isEmpty()) {
817 return StringPool.BLANK;
818 }
819
820 StringBundler sb = new StringBundler(folderIds.size() * 3 + 1);
821
822 sb.append(StringPool.OPEN_PARENTHESIS);
823
824 for (int i = 0; i < folderIds.size(); i++) {
825 sb.append(tableName);
826 sb.append(".folderId = ? ");
827
828 if ((i + 1) != folderIds.size()) {
829 sb.append(WHERE_OR);
830 }
831 }
832
833 sb.append(StringPool.CLOSE_PARENTHESIS);
834
835 return sb.toString();
836 }
837
838 protected String getMimeTypes(String[] mimeTypes, String tableName) {
839 if (mimeTypes.length == 0) {
840 return StringPool.BLANK;
841 }
842
843 StringBundler sb = new StringBundler(mimeTypes.length * 2 - 1);
844
845 for (int i = 0; i < mimeTypes.length; i++) {
846 sb.append(tableName);
847 sb.append(".mimeType = ?");
848
849 if ((i + 1) != mimeTypes.length) {
850 sb.append(WHERE_OR);
851 }
852 }
853
854 return sb.toString();
855 }
856
857 protected String getRepositoryIds(
858 List<Long> repositoryIds, String tableName) {
859
860 if (repositoryIds.isEmpty()) {
861 return StringPool.BLANK;
862 }
863
864 StringBundler sb = new StringBundler(repositoryIds.size() * 3 + 1);
865
866 sb.append(StringPool.OPEN_PARENTHESIS);
867
868 for (int i = 0; i < repositoryIds.size(); i++) {
869 sb.append(tableName);
870 sb.append(".repositoryId = ? ");
871
872 if ((i + 1) != repositoryIds.size()) {
873 sb.append(WHERE_OR);
874 }
875 }
876
877 sb.append(StringPool.CLOSE_PARENTHESIS);
878
879 return sb.toString();
880 }
881
882 }