1
22
23 package com.liferay.portlet.documentlibrary.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.bean.InitializingBean;
27 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
28 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
29 import com.liferay.portal.kernel.dao.orm.Query;
30 import com.liferay.portal.kernel.dao.orm.QueryPos;
31 import com.liferay.portal.kernel.dao.orm.QueryUtil;
32 import com.liferay.portal.kernel.dao.orm.Session;
33 import com.liferay.portal.kernel.util.GetterUtil;
34 import com.liferay.portal.kernel.util.ListUtil;
35 import com.liferay.portal.kernel.util.OrderByComparator;
36 import com.liferay.portal.kernel.util.StringPool;
37 import com.liferay.portal.kernel.util.StringUtil;
38 import com.liferay.portal.kernel.util.Validator;
39 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
40 import com.liferay.portal.model.ModelListener;
41 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
42
43 import com.liferay.portlet.documentlibrary.NoSuchFileShortcutException;
44 import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
45 import com.liferay.portlet.documentlibrary.model.impl.DLFileShortcutImpl;
46 import com.liferay.portlet.documentlibrary.model.impl.DLFileShortcutModelImpl;
47
48 import org.apache.commons.logging.Log;
49 import org.apache.commons.logging.LogFactory;
50
51 import java.util.ArrayList;
52 import java.util.Collections;
53 import java.util.Iterator;
54 import java.util.List;
55
56
62 public class DLFileShortcutPersistenceImpl extends BasePersistenceImpl
63 implements DLFileShortcutPersistence, InitializingBean {
64 public DLFileShortcut create(long fileShortcutId) {
65 DLFileShortcut dlFileShortcut = new DLFileShortcutImpl();
66
67 dlFileShortcut.setNew(true);
68 dlFileShortcut.setPrimaryKey(fileShortcutId);
69
70 String uuid = PortalUUIDUtil.generate();
71
72 dlFileShortcut.setUuid(uuid);
73
74 return dlFileShortcut;
75 }
76
77 public DLFileShortcut remove(long fileShortcutId)
78 throws NoSuchFileShortcutException, SystemException {
79 Session session = null;
80
81 try {
82 session = openSession();
83
84 DLFileShortcut dlFileShortcut = (DLFileShortcut)session.get(DLFileShortcutImpl.class,
85 new Long(fileShortcutId));
86
87 if (dlFileShortcut == null) {
88 if (_log.isWarnEnabled()) {
89 _log.warn("No DLFileShortcut exists with the primary key " +
90 fileShortcutId);
91 }
92
93 throw new NoSuchFileShortcutException(
94 "No DLFileShortcut exists with the primary key " +
95 fileShortcutId);
96 }
97
98 return remove(dlFileShortcut);
99 }
100 catch (NoSuchFileShortcutException nsee) {
101 throw nsee;
102 }
103 catch (Exception e) {
104 throw processException(e);
105 }
106 finally {
107 closeSession(session);
108 }
109 }
110
111 public DLFileShortcut remove(DLFileShortcut dlFileShortcut)
112 throws SystemException {
113 if (_listeners.length > 0) {
114 for (ModelListener listener : _listeners) {
115 listener.onBeforeRemove(dlFileShortcut);
116 }
117 }
118
119 dlFileShortcut = removeImpl(dlFileShortcut);
120
121 if (_listeners.length > 0) {
122 for (ModelListener listener : _listeners) {
123 listener.onAfterRemove(dlFileShortcut);
124 }
125 }
126
127 return dlFileShortcut;
128 }
129
130 protected DLFileShortcut removeImpl(DLFileShortcut dlFileShortcut)
131 throws SystemException {
132 Session session = null;
133
134 try {
135 session = openSession();
136
137 session.delete(dlFileShortcut);
138
139 session.flush();
140
141 return dlFileShortcut;
142 }
143 catch (Exception e) {
144 throw processException(e);
145 }
146 finally {
147 closeSession(session);
148
149 FinderCacheUtil.clearCache(DLFileShortcut.class.getName());
150 }
151 }
152
153
156 public DLFileShortcut update(DLFileShortcut dlFileShortcut)
157 throws SystemException {
158 if (_log.isWarnEnabled()) {
159 _log.warn(
160 "Using the deprecated update(DLFileShortcut dlFileShortcut) method. Use update(DLFileShortcut dlFileShortcut, boolean merge) instead.");
161 }
162
163 return update(dlFileShortcut, false);
164 }
165
166
179 public DLFileShortcut update(DLFileShortcut dlFileShortcut, boolean merge)
180 throws SystemException {
181 boolean isNew = dlFileShortcut.isNew();
182
183 if (_listeners.length > 0) {
184 for (ModelListener listener : _listeners) {
185 if (isNew) {
186 listener.onBeforeCreate(dlFileShortcut);
187 }
188 else {
189 listener.onBeforeUpdate(dlFileShortcut);
190 }
191 }
192 }
193
194 dlFileShortcut = updateImpl(dlFileShortcut, merge);
195
196 if (_listeners.length > 0) {
197 for (ModelListener listener : _listeners) {
198 if (isNew) {
199 listener.onAfterCreate(dlFileShortcut);
200 }
201 else {
202 listener.onAfterUpdate(dlFileShortcut);
203 }
204 }
205 }
206
207 return dlFileShortcut;
208 }
209
210 public DLFileShortcut updateImpl(
211 com.liferay.portlet.documentlibrary.model.DLFileShortcut dlFileShortcut,
212 boolean merge) throws SystemException {
213 if (Validator.isNull(dlFileShortcut.getUuid())) {
214 String uuid = PortalUUIDUtil.generate();
215
216 dlFileShortcut.setUuid(uuid);
217 }
218
219 Session session = null;
220
221 try {
222 session = openSession();
223
224 if (merge) {
225 session.merge(dlFileShortcut);
226 }
227 else {
228 if (dlFileShortcut.isNew()) {
229 session.save(dlFileShortcut);
230 }
231 }
232
233 session.flush();
234
235 dlFileShortcut.setNew(false);
236
237 return dlFileShortcut;
238 }
239 catch (Exception e) {
240 throw processException(e);
241 }
242 finally {
243 closeSession(session);
244
245 FinderCacheUtil.clearCache(DLFileShortcut.class.getName());
246 }
247 }
248
249 public DLFileShortcut findByPrimaryKey(long fileShortcutId)
250 throws NoSuchFileShortcutException, SystemException {
251 DLFileShortcut dlFileShortcut = fetchByPrimaryKey(fileShortcutId);
252
253 if (dlFileShortcut == null) {
254 if (_log.isWarnEnabled()) {
255 _log.warn("No DLFileShortcut exists with the primary key " +
256 fileShortcutId);
257 }
258
259 throw new NoSuchFileShortcutException(
260 "No DLFileShortcut exists with the primary key " +
261 fileShortcutId);
262 }
263
264 return dlFileShortcut;
265 }
266
267 public DLFileShortcut fetchByPrimaryKey(long fileShortcutId)
268 throws SystemException {
269 Session session = null;
270
271 try {
272 session = openSession();
273
274 return (DLFileShortcut)session.get(DLFileShortcutImpl.class,
275 new Long(fileShortcutId));
276 }
277 catch (Exception e) {
278 throw processException(e);
279 }
280 finally {
281 closeSession(session);
282 }
283 }
284
285 public List<DLFileShortcut> findByUuid(String uuid)
286 throws SystemException {
287 boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
288 String finderClassName = DLFileShortcut.class.getName();
289 String finderMethodName = "findByUuid";
290 String[] finderParams = new String[] { String.class.getName() };
291 Object[] finderArgs = new Object[] { uuid };
292
293 Object result = null;
294
295 if (finderClassNameCacheEnabled) {
296 result = FinderCacheUtil.getResult(finderClassName,
297 finderMethodName, finderParams, finderArgs, this);
298 }
299
300 if (result == null) {
301 Session session = null;
302
303 try {
304 session = openSession();
305
306 StringBuilder query = new StringBuilder();
307
308 query.append(
309 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
310
311 if (uuid == null) {
312 query.append("uuid_ IS NULL");
313 }
314 else {
315 query.append("uuid_ = ?");
316 }
317
318 query.append(" ");
319
320 Query q = session.createQuery(query.toString());
321
322 QueryPos qPos = QueryPos.getInstance(q);
323
324 if (uuid != null) {
325 qPos.add(uuid);
326 }
327
328 List<DLFileShortcut> list = q.list();
329
330 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
331 finderClassName, finderMethodName, finderParams,
332 finderArgs, list);
333
334 return list;
335 }
336 catch (Exception e) {
337 throw processException(e);
338 }
339 finally {
340 closeSession(session);
341 }
342 }
343 else {
344 return (List<DLFileShortcut>)result;
345 }
346 }
347
348 public List<DLFileShortcut> findByUuid(String uuid, int start, int end)
349 throws SystemException {
350 return findByUuid(uuid, start, end, null);
351 }
352
353 public List<DLFileShortcut> findByUuid(String uuid, int start, int end,
354 OrderByComparator obc) throws SystemException {
355 boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
356 String finderClassName = DLFileShortcut.class.getName();
357 String finderMethodName = "findByUuid";
358 String[] finderParams = new String[] {
359 String.class.getName(),
360
361 "java.lang.Integer", "java.lang.Integer",
362 "com.liferay.portal.kernel.util.OrderByComparator"
363 };
364 Object[] finderArgs = new Object[] {
365 uuid,
366
367 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
368 };
369
370 Object result = null;
371
372 if (finderClassNameCacheEnabled) {
373 result = FinderCacheUtil.getResult(finderClassName,
374 finderMethodName, finderParams, finderArgs, this);
375 }
376
377 if (result == null) {
378 Session session = null;
379
380 try {
381 session = openSession();
382
383 StringBuilder query = new StringBuilder();
384
385 query.append(
386 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
387
388 if (uuid == null) {
389 query.append("uuid_ IS NULL");
390 }
391 else {
392 query.append("uuid_ = ?");
393 }
394
395 query.append(" ");
396
397 if (obc != null) {
398 query.append("ORDER BY ");
399 query.append(obc.getOrderBy());
400 }
401
402 Query q = session.createQuery(query.toString());
403
404 QueryPos qPos = QueryPos.getInstance(q);
405
406 if (uuid != null) {
407 qPos.add(uuid);
408 }
409
410 List<DLFileShortcut> list = (List<DLFileShortcut>)QueryUtil.list(q,
411 getDialect(), start, end);
412
413 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
414 finderClassName, finderMethodName, finderParams,
415 finderArgs, list);
416
417 return list;
418 }
419 catch (Exception e) {
420 throw processException(e);
421 }
422 finally {
423 closeSession(session);
424 }
425 }
426 else {
427 return (List<DLFileShortcut>)result;
428 }
429 }
430
431 public DLFileShortcut findByUuid_First(String uuid, OrderByComparator obc)
432 throws NoSuchFileShortcutException, SystemException {
433 List<DLFileShortcut> list = findByUuid(uuid, 0, 1, obc);
434
435 if (list.size() == 0) {
436 StringBuilder msg = new StringBuilder();
437
438 msg.append("No DLFileShortcut exists with the key {");
439
440 msg.append("uuid=" + uuid);
441
442 msg.append(StringPool.CLOSE_CURLY_BRACE);
443
444 throw new NoSuchFileShortcutException(msg.toString());
445 }
446 else {
447 return list.get(0);
448 }
449 }
450
451 public DLFileShortcut findByUuid_Last(String uuid, OrderByComparator obc)
452 throws NoSuchFileShortcutException, SystemException {
453 int count = countByUuid(uuid);
454
455 List<DLFileShortcut> list = findByUuid(uuid, count - 1, count, obc);
456
457 if (list.size() == 0) {
458 StringBuilder msg = new StringBuilder();
459
460 msg.append("No DLFileShortcut exists with the key {");
461
462 msg.append("uuid=" + uuid);
463
464 msg.append(StringPool.CLOSE_CURLY_BRACE);
465
466 throw new NoSuchFileShortcutException(msg.toString());
467 }
468 else {
469 return list.get(0);
470 }
471 }
472
473 public DLFileShortcut[] findByUuid_PrevAndNext(long fileShortcutId,
474 String uuid, OrderByComparator obc)
475 throws NoSuchFileShortcutException, SystemException {
476 DLFileShortcut dlFileShortcut = findByPrimaryKey(fileShortcutId);
477
478 int count = countByUuid(uuid);
479
480 Session session = null;
481
482 try {
483 session = openSession();
484
485 StringBuilder query = new StringBuilder();
486
487 query.append(
488 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
489
490 if (uuid == null) {
491 query.append("uuid_ IS NULL");
492 }
493 else {
494 query.append("uuid_ = ?");
495 }
496
497 query.append(" ");
498
499 if (obc != null) {
500 query.append("ORDER BY ");
501 query.append(obc.getOrderBy());
502 }
503
504 Query q = session.createQuery(query.toString());
505
506 QueryPos qPos = QueryPos.getInstance(q);
507
508 if (uuid != null) {
509 qPos.add(uuid);
510 }
511
512 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
513 dlFileShortcut);
514
515 DLFileShortcut[] array = new DLFileShortcutImpl[3];
516
517 array[0] = (DLFileShortcut)objArray[0];
518 array[1] = (DLFileShortcut)objArray[1];
519 array[2] = (DLFileShortcut)objArray[2];
520
521 return array;
522 }
523 catch (Exception e) {
524 throw processException(e);
525 }
526 finally {
527 closeSession(session);
528 }
529 }
530
531 public List<DLFileShortcut> findByFolderId(long folderId)
532 throws SystemException {
533 boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
534 String finderClassName = DLFileShortcut.class.getName();
535 String finderMethodName = "findByFolderId";
536 String[] finderParams = new String[] { Long.class.getName() };
537 Object[] finderArgs = new Object[] { new Long(folderId) };
538
539 Object result = null;
540
541 if (finderClassNameCacheEnabled) {
542 result = FinderCacheUtil.getResult(finderClassName,
543 finderMethodName, finderParams, finderArgs, this);
544 }
545
546 if (result == null) {
547 Session session = null;
548
549 try {
550 session = openSession();
551
552 StringBuilder query = new StringBuilder();
553
554 query.append(
555 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
556
557 query.append("folderId = ?");
558
559 query.append(" ");
560
561 Query q = session.createQuery(query.toString());
562
563 QueryPos qPos = QueryPos.getInstance(q);
564
565 qPos.add(folderId);
566
567 List<DLFileShortcut> list = q.list();
568
569 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
570 finderClassName, finderMethodName, finderParams,
571 finderArgs, list);
572
573 return list;
574 }
575 catch (Exception e) {
576 throw processException(e);
577 }
578 finally {
579 closeSession(session);
580 }
581 }
582 else {
583 return (List<DLFileShortcut>)result;
584 }
585 }
586
587 public List<DLFileShortcut> findByFolderId(long folderId, int start, int end)
588 throws SystemException {
589 return findByFolderId(folderId, start, end, null);
590 }
591
592 public List<DLFileShortcut> findByFolderId(long folderId, int start,
593 int end, OrderByComparator obc) throws SystemException {
594 boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
595 String finderClassName = DLFileShortcut.class.getName();
596 String finderMethodName = "findByFolderId";
597 String[] finderParams = new String[] {
598 Long.class.getName(),
599
600 "java.lang.Integer", "java.lang.Integer",
601 "com.liferay.portal.kernel.util.OrderByComparator"
602 };
603 Object[] finderArgs = new Object[] {
604 new Long(folderId),
605
606 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
607 };
608
609 Object result = null;
610
611 if (finderClassNameCacheEnabled) {
612 result = FinderCacheUtil.getResult(finderClassName,
613 finderMethodName, finderParams, finderArgs, this);
614 }
615
616 if (result == null) {
617 Session session = null;
618
619 try {
620 session = openSession();
621
622 StringBuilder query = new StringBuilder();
623
624 query.append(
625 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
626
627 query.append("folderId = ?");
628
629 query.append(" ");
630
631 if (obc != null) {
632 query.append("ORDER BY ");
633 query.append(obc.getOrderBy());
634 }
635
636 Query q = session.createQuery(query.toString());
637
638 QueryPos qPos = QueryPos.getInstance(q);
639
640 qPos.add(folderId);
641
642 List<DLFileShortcut> list = (List<DLFileShortcut>)QueryUtil.list(q,
643 getDialect(), start, end);
644
645 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
646 finderClassName, finderMethodName, finderParams,
647 finderArgs, list);
648
649 return list;
650 }
651 catch (Exception e) {
652 throw processException(e);
653 }
654 finally {
655 closeSession(session);
656 }
657 }
658 else {
659 return (List<DLFileShortcut>)result;
660 }
661 }
662
663 public DLFileShortcut findByFolderId_First(long folderId,
664 OrderByComparator obc)
665 throws NoSuchFileShortcutException, SystemException {
666 List<DLFileShortcut> list = findByFolderId(folderId, 0, 1, obc);
667
668 if (list.size() == 0) {
669 StringBuilder msg = new StringBuilder();
670
671 msg.append("No DLFileShortcut exists with the key {");
672
673 msg.append("folderId=" + folderId);
674
675 msg.append(StringPool.CLOSE_CURLY_BRACE);
676
677 throw new NoSuchFileShortcutException(msg.toString());
678 }
679 else {
680 return list.get(0);
681 }
682 }
683
684 public DLFileShortcut findByFolderId_Last(long folderId,
685 OrderByComparator obc)
686 throws NoSuchFileShortcutException, SystemException {
687 int count = countByFolderId(folderId);
688
689 List<DLFileShortcut> list = findByFolderId(folderId, count - 1, count,
690 obc);
691
692 if (list.size() == 0) {
693 StringBuilder msg = new StringBuilder();
694
695 msg.append("No DLFileShortcut exists with the key {");
696
697 msg.append("folderId=" + folderId);
698
699 msg.append(StringPool.CLOSE_CURLY_BRACE);
700
701 throw new NoSuchFileShortcutException(msg.toString());
702 }
703 else {
704 return list.get(0);
705 }
706 }
707
708 public DLFileShortcut[] findByFolderId_PrevAndNext(long fileShortcutId,
709 long folderId, OrderByComparator obc)
710 throws NoSuchFileShortcutException, SystemException {
711 DLFileShortcut dlFileShortcut = findByPrimaryKey(fileShortcutId);
712
713 int count = countByFolderId(folderId);
714
715 Session session = null;
716
717 try {
718 session = openSession();
719
720 StringBuilder query = new StringBuilder();
721
722 query.append(
723 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
724
725 query.append("folderId = ?");
726
727 query.append(" ");
728
729 if (obc != null) {
730 query.append("ORDER BY ");
731 query.append(obc.getOrderBy());
732 }
733
734 Query q = session.createQuery(query.toString());
735
736 QueryPos qPos = QueryPos.getInstance(q);
737
738 qPos.add(folderId);
739
740 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
741 dlFileShortcut);
742
743 DLFileShortcut[] array = new DLFileShortcutImpl[3];
744
745 array[0] = (DLFileShortcut)objArray[0];
746 array[1] = (DLFileShortcut)objArray[1];
747 array[2] = (DLFileShortcut)objArray[2];
748
749 return array;
750 }
751 catch (Exception e) {
752 throw processException(e);
753 }
754 finally {
755 closeSession(session);
756 }
757 }
758
759 public List<DLFileShortcut> findByTF_TN(long toFolderId, String toName)
760 throws SystemException {
761 boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
762 String finderClassName = DLFileShortcut.class.getName();
763 String finderMethodName = "findByTF_TN";
764 String[] finderParams = new String[] {
765 Long.class.getName(), String.class.getName()
766 };
767 Object[] finderArgs = new Object[] { new Long(toFolderId), toName };
768
769 Object result = null;
770
771 if (finderClassNameCacheEnabled) {
772 result = FinderCacheUtil.getResult(finderClassName,
773 finderMethodName, finderParams, finderArgs, this);
774 }
775
776 if (result == null) {
777 Session session = null;
778
779 try {
780 session = openSession();
781
782 StringBuilder query = new StringBuilder();
783
784 query.append(
785 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
786
787 query.append("toFolderId = ?");
788
789 query.append(" AND ");
790
791 if (toName == null) {
792 query.append("toName IS NULL");
793 }
794 else {
795 query.append("toName = ?");
796 }
797
798 query.append(" ");
799
800 Query q = session.createQuery(query.toString());
801
802 QueryPos qPos = QueryPos.getInstance(q);
803
804 qPos.add(toFolderId);
805
806 if (toName != null) {
807 qPos.add(toName);
808 }
809
810 List<DLFileShortcut> list = q.list();
811
812 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
813 finderClassName, finderMethodName, finderParams,
814 finderArgs, list);
815
816 return list;
817 }
818 catch (Exception e) {
819 throw processException(e);
820 }
821 finally {
822 closeSession(session);
823 }
824 }
825 else {
826 return (List<DLFileShortcut>)result;
827 }
828 }
829
830 public List<DLFileShortcut> findByTF_TN(long toFolderId, String toName,
831 int start, int end) throws SystemException {
832 return findByTF_TN(toFolderId, toName, start, end, null);
833 }
834
835 public List<DLFileShortcut> findByTF_TN(long toFolderId, String toName,
836 int start, int end, OrderByComparator obc) throws SystemException {
837 boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
838 String finderClassName = DLFileShortcut.class.getName();
839 String finderMethodName = "findByTF_TN";
840 String[] finderParams = new String[] {
841 Long.class.getName(), String.class.getName(),
842
843 "java.lang.Integer", "java.lang.Integer",
844 "com.liferay.portal.kernel.util.OrderByComparator"
845 };
846 Object[] finderArgs = new Object[] {
847 new Long(toFolderId),
848
849 toName,
850
851 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
852 };
853
854 Object result = null;
855
856 if (finderClassNameCacheEnabled) {
857 result = FinderCacheUtil.getResult(finderClassName,
858 finderMethodName, finderParams, finderArgs, this);
859 }
860
861 if (result == null) {
862 Session session = null;
863
864 try {
865 session = openSession();
866
867 StringBuilder query = new StringBuilder();
868
869 query.append(
870 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
871
872 query.append("toFolderId = ?");
873
874 query.append(" AND ");
875
876 if (toName == null) {
877 query.append("toName IS NULL");
878 }
879 else {
880 query.append("toName = ?");
881 }
882
883 query.append(" ");
884
885 if (obc != null) {
886 query.append("ORDER BY ");
887 query.append(obc.getOrderBy());
888 }
889
890 Query q = session.createQuery(query.toString());
891
892 QueryPos qPos = QueryPos.getInstance(q);
893
894 qPos.add(toFolderId);
895
896 if (toName != null) {
897 qPos.add(toName);
898 }
899
900 List<DLFileShortcut> list = (List<DLFileShortcut>)QueryUtil.list(q,
901 getDialect(), start, end);
902
903 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
904 finderClassName, finderMethodName, finderParams,
905 finderArgs, list);
906
907 return list;
908 }
909 catch (Exception e) {
910 throw processException(e);
911 }
912 finally {
913 closeSession(session);
914 }
915 }
916 else {
917 return (List<DLFileShortcut>)result;
918 }
919 }
920
921 public DLFileShortcut findByTF_TN_First(long toFolderId, String toName,
922 OrderByComparator obc)
923 throws NoSuchFileShortcutException, SystemException {
924 List<DLFileShortcut> list = findByTF_TN(toFolderId, toName, 0, 1, obc);
925
926 if (list.size() == 0) {
927 StringBuilder msg = new StringBuilder();
928
929 msg.append("No DLFileShortcut exists with the key {");
930
931 msg.append("toFolderId=" + toFolderId);
932
933 msg.append(", ");
934 msg.append("toName=" + toName);
935
936 msg.append(StringPool.CLOSE_CURLY_BRACE);
937
938 throw new NoSuchFileShortcutException(msg.toString());
939 }
940 else {
941 return list.get(0);
942 }
943 }
944
945 public DLFileShortcut findByTF_TN_Last(long toFolderId, String toName,
946 OrderByComparator obc)
947 throws NoSuchFileShortcutException, SystemException {
948 int count = countByTF_TN(toFolderId, toName);
949
950 List<DLFileShortcut> list = findByTF_TN(toFolderId, toName, count - 1,
951 count, obc);
952
953 if (list.size() == 0) {
954 StringBuilder msg = new StringBuilder();
955
956 msg.append("No DLFileShortcut exists with the key {");
957
958 msg.append("toFolderId=" + toFolderId);
959
960 msg.append(", ");
961 msg.append("toName=" + toName);
962
963 msg.append(StringPool.CLOSE_CURLY_BRACE);
964
965 throw new NoSuchFileShortcutException(msg.toString());
966 }
967 else {
968 return list.get(0);
969 }
970 }
971
972 public DLFileShortcut[] findByTF_TN_PrevAndNext(long fileShortcutId,
973 long toFolderId, String toName, OrderByComparator obc)
974 throws NoSuchFileShortcutException, SystemException {
975 DLFileShortcut dlFileShortcut = findByPrimaryKey(fileShortcutId);
976
977 int count = countByTF_TN(toFolderId, toName);
978
979 Session session = null;
980
981 try {
982 session = openSession();
983
984 StringBuilder query = new StringBuilder();
985
986 query.append(
987 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
988
989 query.append("toFolderId = ?");
990
991 query.append(" AND ");
992
993 if (toName == null) {
994 query.append("toName IS NULL");
995 }
996 else {
997 query.append("toName = ?");
998 }
999
1000 query.append(" ");
1001
1002 if (obc != null) {
1003 query.append("ORDER BY ");
1004 query.append(obc.getOrderBy());
1005 }
1006
1007 Query q = session.createQuery(query.toString());
1008
1009 QueryPos qPos = QueryPos.getInstance(q);
1010
1011 qPos.add(toFolderId);
1012
1013 if (toName != null) {
1014 qPos.add(toName);
1015 }
1016
1017 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1018 dlFileShortcut);
1019
1020 DLFileShortcut[] array = new DLFileShortcutImpl[3];
1021
1022 array[0] = (DLFileShortcut)objArray[0];
1023 array[1] = (DLFileShortcut)objArray[1];
1024 array[2] = (DLFileShortcut)objArray[2];
1025
1026 return array;
1027 }
1028 catch (Exception e) {
1029 throw processException(e);
1030 }
1031 finally {
1032 closeSession(session);
1033 }
1034 }
1035
1036 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1037 throws SystemException {
1038 Session session = null;
1039
1040 try {
1041 session = openSession();
1042
1043 dynamicQuery.compile(session);
1044
1045 return dynamicQuery.list();
1046 }
1047 catch (Exception e) {
1048 throw processException(e);
1049 }
1050 finally {
1051 closeSession(session);
1052 }
1053 }
1054
1055 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1056 int start, int end) throws SystemException {
1057 Session session = null;
1058
1059 try {
1060 session = openSession();
1061
1062 dynamicQuery.setLimit(start, end);
1063
1064 dynamicQuery.compile(session);
1065
1066 return dynamicQuery.list();
1067 }
1068 catch (Exception e) {
1069 throw processException(e);
1070 }
1071 finally {
1072 closeSession(session);
1073 }
1074 }
1075
1076 public List<DLFileShortcut> findAll() throws SystemException {
1077 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1078 }
1079
1080 public List<DLFileShortcut> findAll(int start, int end)
1081 throws SystemException {
1082 return findAll(start, end, null);
1083 }
1084
1085 public List<DLFileShortcut> findAll(int start, int end,
1086 OrderByComparator obc) throws SystemException {
1087 boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
1088 String finderClassName = DLFileShortcut.class.getName();
1089 String finderMethodName = "findAll";
1090 String[] finderParams = new String[] {
1091 "java.lang.Integer", "java.lang.Integer",
1092 "com.liferay.portal.kernel.util.OrderByComparator"
1093 };
1094 Object[] finderArgs = new Object[] {
1095 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1096 };
1097
1098 Object result = null;
1099
1100 if (finderClassNameCacheEnabled) {
1101 result = FinderCacheUtil.getResult(finderClassName,
1102 finderMethodName, finderParams, finderArgs, this);
1103 }
1104
1105 if (result == null) {
1106 Session session = null;
1107
1108 try {
1109 session = openSession();
1110
1111 StringBuilder query = new StringBuilder();
1112
1113 query.append(
1114 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut ");
1115
1116 if (obc != null) {
1117 query.append("ORDER BY ");
1118 query.append(obc.getOrderBy());
1119 }
1120
1121 Query q = session.createQuery(query.toString());
1122
1123 List<DLFileShortcut> list = (List<DLFileShortcut>)QueryUtil.list(q,
1124 getDialect(), start, end);
1125
1126 if (obc == null) {
1127 Collections.sort(list);
1128 }
1129
1130 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1131 finderClassName, finderMethodName, finderParams,
1132 finderArgs, list);
1133
1134 return list;
1135 }
1136 catch (Exception e) {
1137 throw processException(e);
1138 }
1139 finally {
1140 closeSession(session);
1141 }
1142 }
1143 else {
1144 return (List<DLFileShortcut>)result;
1145 }
1146 }
1147
1148 public void removeByUuid(String uuid) throws SystemException {
1149 for (DLFileShortcut dlFileShortcut : findByUuid(uuid)) {
1150 remove(dlFileShortcut);
1151 }
1152 }
1153
1154 public void removeByFolderId(long folderId) throws SystemException {
1155 for (DLFileShortcut dlFileShortcut : findByFolderId(folderId)) {
1156 remove(dlFileShortcut);
1157 }
1158 }
1159
1160 public void removeByTF_TN(long toFolderId, String toName)
1161 throws SystemException {
1162 for (DLFileShortcut dlFileShortcut : findByTF_TN(toFolderId, toName)) {
1163 remove(dlFileShortcut);
1164 }
1165 }
1166
1167 public void removeAll() throws SystemException {
1168 for (DLFileShortcut dlFileShortcut : findAll()) {
1169 remove(dlFileShortcut);
1170 }
1171 }
1172
1173 public int countByUuid(String uuid) throws SystemException {
1174 boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
1175 String finderClassName = DLFileShortcut.class.getName();
1176 String finderMethodName = "countByUuid";
1177 String[] finderParams = new String[] { String.class.getName() };
1178 Object[] finderArgs = new Object[] { uuid };
1179
1180 Object result = null;
1181
1182 if (finderClassNameCacheEnabled) {
1183 result = FinderCacheUtil.getResult(finderClassName,
1184 finderMethodName, finderParams, finderArgs, this);
1185 }
1186
1187 if (result == null) {
1188 Session session = null;
1189
1190 try {
1191 session = openSession();
1192
1193 StringBuilder query = new StringBuilder();
1194
1195 query.append("SELECT COUNT(*) ");
1196 query.append(
1197 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
1198
1199 if (uuid == null) {
1200 query.append("uuid_ IS NULL");
1201 }
1202 else {
1203 query.append("uuid_ = ?");
1204 }
1205
1206 query.append(" ");
1207
1208 Query q = session.createQuery(query.toString());
1209
1210 QueryPos qPos = QueryPos.getInstance(q);
1211
1212 if (uuid != null) {
1213 qPos.add(uuid);
1214 }
1215
1216 Long count = null;
1217
1218 Iterator<Long> itr = q.list().iterator();
1219
1220 if (itr.hasNext()) {
1221 count = itr.next();
1222 }
1223
1224 if (count == null) {
1225 count = new Long(0);
1226 }
1227
1228 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1229 finderClassName, finderMethodName, finderParams,
1230 finderArgs, count);
1231
1232 return count.intValue();
1233 }
1234 catch (Exception e) {
1235 throw processException(e);
1236 }
1237 finally {
1238 closeSession(session);
1239 }
1240 }
1241 else {
1242 return ((Long)result).intValue();
1243 }
1244 }
1245
1246 public int countByFolderId(long folderId) throws SystemException {
1247 boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
1248 String finderClassName = DLFileShortcut.class.getName();
1249 String finderMethodName = "countByFolderId";
1250 String[] finderParams = new String[] { Long.class.getName() };
1251 Object[] finderArgs = new Object[] { new Long(folderId) };
1252
1253 Object result = null;
1254
1255 if (finderClassNameCacheEnabled) {
1256 result = FinderCacheUtil.getResult(finderClassName,
1257 finderMethodName, finderParams, finderArgs, this);
1258 }
1259
1260 if (result == null) {
1261 Session session = null;
1262
1263 try {
1264 session = openSession();
1265
1266 StringBuilder query = new StringBuilder();
1267
1268 query.append("SELECT COUNT(*) ");
1269 query.append(
1270 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
1271
1272 query.append("folderId = ?");
1273
1274 query.append(" ");
1275
1276 Query q = session.createQuery(query.toString());
1277
1278 QueryPos qPos = QueryPos.getInstance(q);
1279
1280 qPos.add(folderId);
1281
1282 Long count = null;
1283
1284 Iterator<Long> itr = q.list().iterator();
1285
1286 if (itr.hasNext()) {
1287 count = itr.next();
1288 }
1289
1290 if (count == null) {
1291 count = new Long(0);
1292 }
1293
1294 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1295 finderClassName, finderMethodName, finderParams,
1296 finderArgs, count);
1297
1298 return count.intValue();
1299 }
1300 catch (Exception e) {
1301 throw processException(e);
1302 }
1303 finally {
1304 closeSession(session);
1305 }
1306 }
1307 else {
1308 return ((Long)result).intValue();
1309 }
1310 }
1311
1312 public int countByTF_TN(long toFolderId, String toName)
1313 throws SystemException {
1314 boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
1315 String finderClassName = DLFileShortcut.class.getName();
1316 String finderMethodName = "countByTF_TN";
1317 String[] finderParams = new String[] {
1318 Long.class.getName(), String.class.getName()
1319 };
1320 Object[] finderArgs = new Object[] { new Long(toFolderId), toName };
1321
1322 Object result = null;
1323
1324 if (finderClassNameCacheEnabled) {
1325 result = FinderCacheUtil.getResult(finderClassName,
1326 finderMethodName, finderParams, finderArgs, this);
1327 }
1328
1329 if (result == null) {
1330 Session session = null;
1331
1332 try {
1333 session = openSession();
1334
1335 StringBuilder query = new StringBuilder();
1336
1337 query.append("SELECT COUNT(*) ");
1338 query.append(
1339 "FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut WHERE ");
1340
1341 query.append("toFolderId = ?");
1342
1343 query.append(" AND ");
1344
1345 if (toName == null) {
1346 query.append("toName IS NULL");
1347 }
1348 else {
1349 query.append("toName = ?");
1350 }
1351
1352 query.append(" ");
1353
1354 Query q = session.createQuery(query.toString());
1355
1356 QueryPos qPos = QueryPos.getInstance(q);
1357
1358 qPos.add(toFolderId);
1359
1360 if (toName != null) {
1361 qPos.add(toName);
1362 }
1363
1364 Long count = null;
1365
1366 Iterator<Long> itr = q.list().iterator();
1367
1368 if (itr.hasNext()) {
1369 count = itr.next();
1370 }
1371
1372 if (count == null) {
1373 count = new Long(0);
1374 }
1375
1376 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1377 finderClassName, finderMethodName, finderParams,
1378 finderArgs, count);
1379
1380 return count.intValue();
1381 }
1382 catch (Exception e) {
1383 throw processException(e);
1384 }
1385 finally {
1386 closeSession(session);
1387 }
1388 }
1389 else {
1390 return ((Long)result).intValue();
1391 }
1392 }
1393
1394 public int countAll() throws SystemException {
1395 boolean finderClassNameCacheEnabled = DLFileShortcutModelImpl.CACHE_ENABLED;
1396 String finderClassName = DLFileShortcut.class.getName();
1397 String finderMethodName = "countAll";
1398 String[] finderParams = new String[] { };
1399 Object[] finderArgs = new Object[] { };
1400
1401 Object result = null;
1402
1403 if (finderClassNameCacheEnabled) {
1404 result = FinderCacheUtil.getResult(finderClassName,
1405 finderMethodName, finderParams, finderArgs, this);
1406 }
1407
1408 if (result == null) {
1409 Session session = null;
1410
1411 try {
1412 session = openSession();
1413
1414 Query q = session.createQuery(
1415 "SELECT COUNT(*) FROM com.liferay.portlet.documentlibrary.model.DLFileShortcut");
1416
1417 Long count = null;
1418
1419 Iterator<Long> itr = q.list().iterator();
1420
1421 if (itr.hasNext()) {
1422 count = itr.next();
1423 }
1424
1425 if (count == null) {
1426 count = new Long(0);
1427 }
1428
1429 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1430 finderClassName, finderMethodName, finderParams,
1431 finderArgs, count);
1432
1433 return count.intValue();
1434 }
1435 catch (Exception e) {
1436 throw processException(e);
1437 }
1438 finally {
1439 closeSession(session);
1440 }
1441 }
1442 else {
1443 return ((Long)result).intValue();
1444 }
1445 }
1446
1447 public void registerListener(ModelListener listener) {
1448 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1449
1450 listeners.add(listener);
1451
1452 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1453 }
1454
1455 public void unregisterListener(ModelListener listener) {
1456 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1457
1458 listeners.remove(listener);
1459
1460 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1461 }
1462
1463 public void afterPropertiesSet() {
1464 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1465 com.liferay.portal.util.PropsUtil.get(
1466 "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileShortcut")));
1467
1468 if (listenerClassNames.length > 0) {
1469 try {
1470 List<ModelListener> listeners = new ArrayList<ModelListener>();
1471
1472 for (String listenerClassName : listenerClassNames) {
1473 listeners.add((ModelListener)Class.forName(
1474 listenerClassName).newInstance());
1475 }
1476
1477 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1478 }
1479 catch (Exception e) {
1480 _log.error(e);
1481 }
1482 }
1483 }
1484
1485 private static Log _log = LogFactory.getLog(DLFileShortcutPersistenceImpl.class);
1486 private ModelListener[] _listeners = new ModelListener[0];
1487}