1
22
23 package com.liferay.portlet.imagegallery.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
27 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
28 import com.liferay.portal.kernel.dao.orm.Query;
29 import com.liferay.portal.kernel.dao.orm.QueryPos;
30 import com.liferay.portal.kernel.dao.orm.QueryUtil;
31 import com.liferay.portal.kernel.dao.orm.Session;
32 import com.liferay.portal.kernel.util.GetterUtil;
33 import com.liferay.portal.kernel.util.ListUtil;
34 import com.liferay.portal.kernel.util.OrderByComparator;
35 import com.liferay.portal.kernel.util.StringPool;
36 import com.liferay.portal.kernel.util.StringUtil;
37 import com.liferay.portal.kernel.util.Validator;
38 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
39 import com.liferay.portal.model.ModelListener;
40 import com.liferay.portal.service.persistence.BatchSessionUtil;
41 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
42
43 import com.liferay.portlet.imagegallery.NoSuchFolderException;
44 import com.liferay.portlet.imagegallery.model.IGFolder;
45 import com.liferay.portlet.imagegallery.model.impl.IGFolderImpl;
46 import com.liferay.portlet.imagegallery.model.impl.IGFolderModelImpl;
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 IGFolderPersistenceImpl extends BasePersistenceImpl
63 implements IGFolderPersistence {
64 public IGFolder create(long folderId) {
65 IGFolder igFolder = new IGFolderImpl();
66
67 igFolder.setNew(true);
68 igFolder.setPrimaryKey(folderId);
69
70 String uuid = PortalUUIDUtil.generate();
71
72 igFolder.setUuid(uuid);
73
74 return igFolder;
75 }
76
77 public IGFolder remove(long folderId)
78 throws NoSuchFolderException, SystemException {
79 Session session = null;
80
81 try {
82 session = openSession();
83
84 IGFolder igFolder = (IGFolder)session.get(IGFolderImpl.class,
85 new Long(folderId));
86
87 if (igFolder == null) {
88 if (_log.isWarnEnabled()) {
89 _log.warn("No IGFolder exists with the primary key " +
90 folderId);
91 }
92
93 throw new NoSuchFolderException(
94 "No IGFolder exists with the primary key " + folderId);
95 }
96
97 return remove(igFolder);
98 }
99 catch (NoSuchFolderException nsee) {
100 throw nsee;
101 }
102 catch (Exception e) {
103 throw processException(e);
104 }
105 finally {
106 closeSession(session);
107 }
108 }
109
110 public IGFolder remove(IGFolder igFolder) throws SystemException {
111 if (_listeners.length > 0) {
112 for (ModelListener listener : _listeners) {
113 listener.onBeforeRemove(igFolder);
114 }
115 }
116
117 igFolder = removeImpl(igFolder);
118
119 if (_listeners.length > 0) {
120 for (ModelListener listener : _listeners) {
121 listener.onAfterRemove(igFolder);
122 }
123 }
124
125 return igFolder;
126 }
127
128 protected IGFolder removeImpl(IGFolder igFolder) throws SystemException {
129 Session session = null;
130
131 try {
132 session = openSession();
133
134 if (BatchSessionUtil.isEnabled()) {
135 Object staleObject = session.get(IGFolderImpl.class,
136 igFolder.getPrimaryKeyObj());
137
138 if (staleObject != null) {
139 session.evict(staleObject);
140 }
141 }
142
143 session.delete(igFolder);
144
145 session.flush();
146
147 return igFolder;
148 }
149 catch (Exception e) {
150 throw processException(e);
151 }
152 finally {
153 closeSession(session);
154
155 FinderCacheUtil.clearCache(IGFolder.class.getName());
156 }
157 }
158
159
162 public IGFolder update(IGFolder igFolder) throws SystemException {
163 if (_log.isWarnEnabled()) {
164 _log.warn(
165 "Using the deprecated update(IGFolder igFolder) method. Use update(IGFolder igFolder, boolean merge) instead.");
166 }
167
168 return update(igFolder, false);
169 }
170
171
184 public IGFolder update(IGFolder igFolder, boolean merge)
185 throws SystemException {
186 boolean isNew = igFolder.isNew();
187
188 if (_listeners.length > 0) {
189 for (ModelListener listener : _listeners) {
190 if (isNew) {
191 listener.onBeforeCreate(igFolder);
192 }
193 else {
194 listener.onBeforeUpdate(igFolder);
195 }
196 }
197 }
198
199 igFolder = updateImpl(igFolder, merge);
200
201 if (_listeners.length > 0) {
202 for (ModelListener listener : _listeners) {
203 if (isNew) {
204 listener.onAfterCreate(igFolder);
205 }
206 else {
207 listener.onAfterUpdate(igFolder);
208 }
209 }
210 }
211
212 return igFolder;
213 }
214
215 public IGFolder updateImpl(
216 com.liferay.portlet.imagegallery.model.IGFolder igFolder, boolean merge)
217 throws SystemException {
218 if (Validator.isNull(igFolder.getUuid())) {
219 String uuid = PortalUUIDUtil.generate();
220
221 igFolder.setUuid(uuid);
222 }
223
224 Session session = null;
225
226 try {
227 session = openSession();
228
229 BatchSessionUtil.update(session, igFolder, merge);
230
231 igFolder.setNew(false);
232
233 return igFolder;
234 }
235 catch (Exception e) {
236 throw processException(e);
237 }
238 finally {
239 closeSession(session);
240
241 FinderCacheUtil.clearCache(IGFolder.class.getName());
242 }
243 }
244
245 public IGFolder findByPrimaryKey(long folderId)
246 throws NoSuchFolderException, SystemException {
247 IGFolder igFolder = fetchByPrimaryKey(folderId);
248
249 if (igFolder == null) {
250 if (_log.isWarnEnabled()) {
251 _log.warn("No IGFolder exists with the primary key " +
252 folderId);
253 }
254
255 throw new NoSuchFolderException(
256 "No IGFolder exists with the primary key " + folderId);
257 }
258
259 return igFolder;
260 }
261
262 public IGFolder fetchByPrimaryKey(long folderId) throws SystemException {
263 Session session = null;
264
265 try {
266 session = openSession();
267
268 return (IGFolder)session.get(IGFolderImpl.class, new Long(folderId));
269 }
270 catch (Exception e) {
271 throw processException(e);
272 }
273 finally {
274 closeSession(session);
275 }
276 }
277
278 public List<IGFolder> findByUuid(String uuid) throws SystemException {
279 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
280 String finderClassName = IGFolder.class.getName();
281 String finderMethodName = "findByUuid";
282 String[] finderParams = new String[] { String.class.getName() };
283 Object[] finderArgs = new Object[] { uuid };
284
285 Object result = null;
286
287 if (finderClassNameCacheEnabled) {
288 result = FinderCacheUtil.getResult(finderClassName,
289 finderMethodName, finderParams, finderArgs, this);
290 }
291
292 if (result == null) {
293 Session session = null;
294
295 try {
296 session = openSession();
297
298 StringBuilder query = new StringBuilder();
299
300 query.append(
301 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
302
303 if (uuid == null) {
304 query.append("uuid_ IS NULL");
305 }
306 else {
307 query.append("uuid_ = ?");
308 }
309
310 query.append(" ");
311
312 query.append("ORDER BY ");
313
314 query.append("folderId ASC, ");
315 query.append("name ASC");
316
317 Query q = session.createQuery(query.toString());
318
319 QueryPos qPos = QueryPos.getInstance(q);
320
321 if (uuid != null) {
322 qPos.add(uuid);
323 }
324
325 List<IGFolder> list = q.list();
326
327 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
328 finderClassName, finderMethodName, finderParams,
329 finderArgs, list);
330
331 return list;
332 }
333 catch (Exception e) {
334 throw processException(e);
335 }
336 finally {
337 closeSession(session);
338 }
339 }
340 else {
341 return (List<IGFolder>)result;
342 }
343 }
344
345 public List<IGFolder> findByUuid(String uuid, int start, int end)
346 throws SystemException {
347 return findByUuid(uuid, start, end, null);
348 }
349
350 public List<IGFolder> findByUuid(String uuid, int start, int end,
351 OrderByComparator obc) throws SystemException {
352 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
353 String finderClassName = IGFolder.class.getName();
354 String finderMethodName = "findByUuid";
355 String[] finderParams = new String[] {
356 String.class.getName(),
357
358 "java.lang.Integer", "java.lang.Integer",
359 "com.liferay.portal.kernel.util.OrderByComparator"
360 };
361 Object[] finderArgs = new Object[] {
362 uuid,
363
364 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
365 };
366
367 Object result = null;
368
369 if (finderClassNameCacheEnabled) {
370 result = FinderCacheUtil.getResult(finderClassName,
371 finderMethodName, finderParams, finderArgs, this);
372 }
373
374 if (result == null) {
375 Session session = null;
376
377 try {
378 session = openSession();
379
380 StringBuilder query = new StringBuilder();
381
382 query.append(
383 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
384
385 if (uuid == null) {
386 query.append("uuid_ IS NULL");
387 }
388 else {
389 query.append("uuid_ = ?");
390 }
391
392 query.append(" ");
393
394 if (obc != null) {
395 query.append("ORDER BY ");
396 query.append(obc.getOrderBy());
397 }
398
399 else {
400 query.append("ORDER BY ");
401
402 query.append("folderId ASC, ");
403 query.append("name ASC");
404 }
405
406 Query q = session.createQuery(query.toString());
407
408 QueryPos qPos = QueryPos.getInstance(q);
409
410 if (uuid != null) {
411 qPos.add(uuid);
412 }
413
414 List<IGFolder> list = (List<IGFolder>)QueryUtil.list(q,
415 getDialect(), start, end);
416
417 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
418 finderClassName, finderMethodName, finderParams,
419 finderArgs, list);
420
421 return list;
422 }
423 catch (Exception e) {
424 throw processException(e);
425 }
426 finally {
427 closeSession(session);
428 }
429 }
430 else {
431 return (List<IGFolder>)result;
432 }
433 }
434
435 public IGFolder findByUuid_First(String uuid, OrderByComparator obc)
436 throws NoSuchFolderException, SystemException {
437 List<IGFolder> list = findByUuid(uuid, 0, 1, obc);
438
439 if (list.size() == 0) {
440 StringBuilder msg = new StringBuilder();
441
442 msg.append("No IGFolder exists with the key {");
443
444 msg.append("uuid=" + uuid);
445
446 msg.append(StringPool.CLOSE_CURLY_BRACE);
447
448 throw new NoSuchFolderException(msg.toString());
449 }
450 else {
451 return list.get(0);
452 }
453 }
454
455 public IGFolder findByUuid_Last(String uuid, OrderByComparator obc)
456 throws NoSuchFolderException, SystemException {
457 int count = countByUuid(uuid);
458
459 List<IGFolder> list = findByUuid(uuid, count - 1, count, obc);
460
461 if (list.size() == 0) {
462 StringBuilder msg = new StringBuilder();
463
464 msg.append("No IGFolder exists with the key {");
465
466 msg.append("uuid=" + uuid);
467
468 msg.append(StringPool.CLOSE_CURLY_BRACE);
469
470 throw new NoSuchFolderException(msg.toString());
471 }
472 else {
473 return list.get(0);
474 }
475 }
476
477 public IGFolder[] findByUuid_PrevAndNext(long folderId, String uuid,
478 OrderByComparator obc) throws NoSuchFolderException, SystemException {
479 IGFolder igFolder = findByPrimaryKey(folderId);
480
481 int count = countByUuid(uuid);
482
483 Session session = null;
484
485 try {
486 session = openSession();
487
488 StringBuilder query = new StringBuilder();
489
490 query.append(
491 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
492
493 if (uuid == null) {
494 query.append("uuid_ IS NULL");
495 }
496 else {
497 query.append("uuid_ = ?");
498 }
499
500 query.append(" ");
501
502 if (obc != null) {
503 query.append("ORDER BY ");
504 query.append(obc.getOrderBy());
505 }
506
507 else {
508 query.append("ORDER BY ");
509
510 query.append("folderId ASC, ");
511 query.append("name ASC");
512 }
513
514 Query q = session.createQuery(query.toString());
515
516 QueryPos qPos = QueryPos.getInstance(q);
517
518 if (uuid != null) {
519 qPos.add(uuid);
520 }
521
522 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igFolder);
523
524 IGFolder[] array = new IGFolderImpl[3];
525
526 array[0] = (IGFolder)objArray[0];
527 array[1] = (IGFolder)objArray[1];
528 array[2] = (IGFolder)objArray[2];
529
530 return array;
531 }
532 catch (Exception e) {
533 throw processException(e);
534 }
535 finally {
536 closeSession(session);
537 }
538 }
539
540 public IGFolder findByUUID_G(String uuid, long groupId)
541 throws NoSuchFolderException, SystemException {
542 IGFolder igFolder = fetchByUUID_G(uuid, groupId);
543
544 if (igFolder == null) {
545 StringBuilder msg = new StringBuilder();
546
547 msg.append("No IGFolder exists with the key {");
548
549 msg.append("uuid=" + uuid);
550
551 msg.append(", ");
552 msg.append("groupId=" + groupId);
553
554 msg.append(StringPool.CLOSE_CURLY_BRACE);
555
556 if (_log.isWarnEnabled()) {
557 _log.warn(msg.toString());
558 }
559
560 throw new NoSuchFolderException(msg.toString());
561 }
562
563 return igFolder;
564 }
565
566 public IGFolder fetchByUUID_G(String uuid, long groupId)
567 throws SystemException {
568 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
569 String finderClassName = IGFolder.class.getName();
570 String finderMethodName = "fetchByUUID_G";
571 String[] finderParams = new String[] {
572 String.class.getName(), Long.class.getName()
573 };
574 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
575
576 Object result = null;
577
578 if (finderClassNameCacheEnabled) {
579 result = FinderCacheUtil.getResult(finderClassName,
580 finderMethodName, finderParams, finderArgs, this);
581 }
582
583 if (result == null) {
584 Session session = null;
585
586 try {
587 session = openSession();
588
589 StringBuilder query = new StringBuilder();
590
591 query.append(
592 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
593
594 if (uuid == null) {
595 query.append("uuid_ IS NULL");
596 }
597 else {
598 query.append("uuid_ = ?");
599 }
600
601 query.append(" AND ");
602
603 query.append("groupId = ?");
604
605 query.append(" ");
606
607 query.append("ORDER BY ");
608
609 query.append("folderId ASC, ");
610 query.append("name ASC");
611
612 Query q = session.createQuery(query.toString());
613
614 QueryPos qPos = QueryPos.getInstance(q);
615
616 if (uuid != null) {
617 qPos.add(uuid);
618 }
619
620 qPos.add(groupId);
621
622 List<IGFolder> list = q.list();
623
624 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
625 finderClassName, finderMethodName, finderParams,
626 finderArgs, list);
627
628 if (list.size() == 0) {
629 return null;
630 }
631 else {
632 return list.get(0);
633 }
634 }
635 catch (Exception e) {
636 throw processException(e);
637 }
638 finally {
639 closeSession(session);
640 }
641 }
642 else {
643 List<IGFolder> list = (List<IGFolder>)result;
644
645 if (list.size() == 0) {
646 return null;
647 }
648 else {
649 return list.get(0);
650 }
651 }
652 }
653
654 public List<IGFolder> findByGroupId(long groupId) throws SystemException {
655 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
656 String finderClassName = IGFolder.class.getName();
657 String finderMethodName = "findByGroupId";
658 String[] finderParams = new String[] { Long.class.getName() };
659 Object[] finderArgs = new Object[] { new Long(groupId) };
660
661 Object result = null;
662
663 if (finderClassNameCacheEnabled) {
664 result = FinderCacheUtil.getResult(finderClassName,
665 finderMethodName, finderParams, finderArgs, this);
666 }
667
668 if (result == null) {
669 Session session = null;
670
671 try {
672 session = openSession();
673
674 StringBuilder query = new StringBuilder();
675
676 query.append(
677 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
678
679 query.append("groupId = ?");
680
681 query.append(" ");
682
683 query.append("ORDER BY ");
684
685 query.append("folderId ASC, ");
686 query.append("name ASC");
687
688 Query q = session.createQuery(query.toString());
689
690 QueryPos qPos = QueryPos.getInstance(q);
691
692 qPos.add(groupId);
693
694 List<IGFolder> list = q.list();
695
696 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
697 finderClassName, finderMethodName, finderParams,
698 finderArgs, list);
699
700 return list;
701 }
702 catch (Exception e) {
703 throw processException(e);
704 }
705 finally {
706 closeSession(session);
707 }
708 }
709 else {
710 return (List<IGFolder>)result;
711 }
712 }
713
714 public List<IGFolder> findByGroupId(long groupId, int start, int end)
715 throws SystemException {
716 return findByGroupId(groupId, start, end, null);
717 }
718
719 public List<IGFolder> findByGroupId(long groupId, int start, int end,
720 OrderByComparator obc) throws SystemException {
721 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
722 String finderClassName = IGFolder.class.getName();
723 String finderMethodName = "findByGroupId";
724 String[] finderParams = new String[] {
725 Long.class.getName(),
726
727 "java.lang.Integer", "java.lang.Integer",
728 "com.liferay.portal.kernel.util.OrderByComparator"
729 };
730 Object[] finderArgs = new Object[] {
731 new Long(groupId),
732
733 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
734 };
735
736 Object result = null;
737
738 if (finderClassNameCacheEnabled) {
739 result = FinderCacheUtil.getResult(finderClassName,
740 finderMethodName, finderParams, finderArgs, this);
741 }
742
743 if (result == null) {
744 Session session = null;
745
746 try {
747 session = openSession();
748
749 StringBuilder query = new StringBuilder();
750
751 query.append(
752 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
753
754 query.append("groupId = ?");
755
756 query.append(" ");
757
758 if (obc != null) {
759 query.append("ORDER BY ");
760 query.append(obc.getOrderBy());
761 }
762
763 else {
764 query.append("ORDER BY ");
765
766 query.append("folderId ASC, ");
767 query.append("name ASC");
768 }
769
770 Query q = session.createQuery(query.toString());
771
772 QueryPos qPos = QueryPos.getInstance(q);
773
774 qPos.add(groupId);
775
776 List<IGFolder> list = (List<IGFolder>)QueryUtil.list(q,
777 getDialect(), start, end);
778
779 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
780 finderClassName, finderMethodName, finderParams,
781 finderArgs, list);
782
783 return list;
784 }
785 catch (Exception e) {
786 throw processException(e);
787 }
788 finally {
789 closeSession(session);
790 }
791 }
792 else {
793 return (List<IGFolder>)result;
794 }
795 }
796
797 public IGFolder findByGroupId_First(long groupId, OrderByComparator obc)
798 throws NoSuchFolderException, SystemException {
799 List<IGFolder> list = findByGroupId(groupId, 0, 1, obc);
800
801 if (list.size() == 0) {
802 StringBuilder msg = new StringBuilder();
803
804 msg.append("No IGFolder exists with the key {");
805
806 msg.append("groupId=" + groupId);
807
808 msg.append(StringPool.CLOSE_CURLY_BRACE);
809
810 throw new NoSuchFolderException(msg.toString());
811 }
812 else {
813 return list.get(0);
814 }
815 }
816
817 public IGFolder findByGroupId_Last(long groupId, OrderByComparator obc)
818 throws NoSuchFolderException, SystemException {
819 int count = countByGroupId(groupId);
820
821 List<IGFolder> list = findByGroupId(groupId, count - 1, count, obc);
822
823 if (list.size() == 0) {
824 StringBuilder msg = new StringBuilder();
825
826 msg.append("No IGFolder exists with the key {");
827
828 msg.append("groupId=" + groupId);
829
830 msg.append(StringPool.CLOSE_CURLY_BRACE);
831
832 throw new NoSuchFolderException(msg.toString());
833 }
834 else {
835 return list.get(0);
836 }
837 }
838
839 public IGFolder[] findByGroupId_PrevAndNext(long folderId, long groupId,
840 OrderByComparator obc) throws NoSuchFolderException, SystemException {
841 IGFolder igFolder = findByPrimaryKey(folderId);
842
843 int count = countByGroupId(groupId);
844
845 Session session = null;
846
847 try {
848 session = openSession();
849
850 StringBuilder query = new StringBuilder();
851
852 query.append(
853 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
854
855 query.append("groupId = ?");
856
857 query.append(" ");
858
859 if (obc != null) {
860 query.append("ORDER BY ");
861 query.append(obc.getOrderBy());
862 }
863
864 else {
865 query.append("ORDER BY ");
866
867 query.append("folderId ASC, ");
868 query.append("name ASC");
869 }
870
871 Query q = session.createQuery(query.toString());
872
873 QueryPos qPos = QueryPos.getInstance(q);
874
875 qPos.add(groupId);
876
877 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igFolder);
878
879 IGFolder[] array = new IGFolderImpl[3];
880
881 array[0] = (IGFolder)objArray[0];
882 array[1] = (IGFolder)objArray[1];
883 array[2] = (IGFolder)objArray[2];
884
885 return array;
886 }
887 catch (Exception e) {
888 throw processException(e);
889 }
890 finally {
891 closeSession(session);
892 }
893 }
894
895 public List<IGFolder> findByCompanyId(long companyId)
896 throws SystemException {
897 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
898 String finderClassName = IGFolder.class.getName();
899 String finderMethodName = "findByCompanyId";
900 String[] finderParams = new String[] { Long.class.getName() };
901 Object[] finderArgs = new Object[] { new Long(companyId) };
902
903 Object result = null;
904
905 if (finderClassNameCacheEnabled) {
906 result = FinderCacheUtil.getResult(finderClassName,
907 finderMethodName, finderParams, finderArgs, this);
908 }
909
910 if (result == null) {
911 Session session = null;
912
913 try {
914 session = openSession();
915
916 StringBuilder query = new StringBuilder();
917
918 query.append(
919 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
920
921 query.append("companyId = ?");
922
923 query.append(" ");
924
925 query.append("ORDER BY ");
926
927 query.append("folderId ASC, ");
928 query.append("name ASC");
929
930 Query q = session.createQuery(query.toString());
931
932 QueryPos qPos = QueryPos.getInstance(q);
933
934 qPos.add(companyId);
935
936 List<IGFolder> list = q.list();
937
938 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
939 finderClassName, finderMethodName, finderParams,
940 finderArgs, list);
941
942 return list;
943 }
944 catch (Exception e) {
945 throw processException(e);
946 }
947 finally {
948 closeSession(session);
949 }
950 }
951 else {
952 return (List<IGFolder>)result;
953 }
954 }
955
956 public List<IGFolder> findByCompanyId(long companyId, int start, int end)
957 throws SystemException {
958 return findByCompanyId(companyId, start, end, null);
959 }
960
961 public List<IGFolder> findByCompanyId(long companyId, int start, int end,
962 OrderByComparator obc) throws SystemException {
963 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
964 String finderClassName = IGFolder.class.getName();
965 String finderMethodName = "findByCompanyId";
966 String[] finderParams = new String[] {
967 Long.class.getName(),
968
969 "java.lang.Integer", "java.lang.Integer",
970 "com.liferay.portal.kernel.util.OrderByComparator"
971 };
972 Object[] finderArgs = new Object[] {
973 new Long(companyId),
974
975 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
976 };
977
978 Object result = null;
979
980 if (finderClassNameCacheEnabled) {
981 result = FinderCacheUtil.getResult(finderClassName,
982 finderMethodName, finderParams, finderArgs, this);
983 }
984
985 if (result == null) {
986 Session session = null;
987
988 try {
989 session = openSession();
990
991 StringBuilder query = new StringBuilder();
992
993 query.append(
994 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
995
996 query.append("companyId = ?");
997
998 query.append(" ");
999
1000 if (obc != null) {
1001 query.append("ORDER BY ");
1002 query.append(obc.getOrderBy());
1003 }
1004
1005 else {
1006 query.append("ORDER BY ");
1007
1008 query.append("folderId ASC, ");
1009 query.append("name ASC");
1010 }
1011
1012 Query q = session.createQuery(query.toString());
1013
1014 QueryPos qPos = QueryPos.getInstance(q);
1015
1016 qPos.add(companyId);
1017
1018 List<IGFolder> list = (List<IGFolder>)QueryUtil.list(q,
1019 getDialect(), start, end);
1020
1021 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1022 finderClassName, finderMethodName, finderParams,
1023 finderArgs, list);
1024
1025 return list;
1026 }
1027 catch (Exception e) {
1028 throw processException(e);
1029 }
1030 finally {
1031 closeSession(session);
1032 }
1033 }
1034 else {
1035 return (List<IGFolder>)result;
1036 }
1037 }
1038
1039 public IGFolder findByCompanyId_First(long companyId, OrderByComparator obc)
1040 throws NoSuchFolderException, SystemException {
1041 List<IGFolder> list = findByCompanyId(companyId, 0, 1, obc);
1042
1043 if (list.size() == 0) {
1044 StringBuilder msg = new StringBuilder();
1045
1046 msg.append("No IGFolder exists with the key {");
1047
1048 msg.append("companyId=" + companyId);
1049
1050 msg.append(StringPool.CLOSE_CURLY_BRACE);
1051
1052 throw new NoSuchFolderException(msg.toString());
1053 }
1054 else {
1055 return list.get(0);
1056 }
1057 }
1058
1059 public IGFolder findByCompanyId_Last(long companyId, OrderByComparator obc)
1060 throws NoSuchFolderException, SystemException {
1061 int count = countByCompanyId(companyId);
1062
1063 List<IGFolder> list = findByCompanyId(companyId, count - 1, count, obc);
1064
1065 if (list.size() == 0) {
1066 StringBuilder msg = new StringBuilder();
1067
1068 msg.append("No IGFolder exists with the key {");
1069
1070 msg.append("companyId=" + companyId);
1071
1072 msg.append(StringPool.CLOSE_CURLY_BRACE);
1073
1074 throw new NoSuchFolderException(msg.toString());
1075 }
1076 else {
1077 return list.get(0);
1078 }
1079 }
1080
1081 public IGFolder[] findByCompanyId_PrevAndNext(long folderId,
1082 long companyId, OrderByComparator obc)
1083 throws NoSuchFolderException, SystemException {
1084 IGFolder igFolder = findByPrimaryKey(folderId);
1085
1086 int count = countByCompanyId(companyId);
1087
1088 Session session = null;
1089
1090 try {
1091 session = openSession();
1092
1093 StringBuilder query = new StringBuilder();
1094
1095 query.append(
1096 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1097
1098 query.append("companyId = ?");
1099
1100 query.append(" ");
1101
1102 if (obc != null) {
1103 query.append("ORDER BY ");
1104 query.append(obc.getOrderBy());
1105 }
1106
1107 else {
1108 query.append("ORDER BY ");
1109
1110 query.append("folderId ASC, ");
1111 query.append("name ASC");
1112 }
1113
1114 Query q = session.createQuery(query.toString());
1115
1116 QueryPos qPos = QueryPos.getInstance(q);
1117
1118 qPos.add(companyId);
1119
1120 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igFolder);
1121
1122 IGFolder[] array = new IGFolderImpl[3];
1123
1124 array[0] = (IGFolder)objArray[0];
1125 array[1] = (IGFolder)objArray[1];
1126 array[2] = (IGFolder)objArray[2];
1127
1128 return array;
1129 }
1130 catch (Exception e) {
1131 throw processException(e);
1132 }
1133 finally {
1134 closeSession(session);
1135 }
1136 }
1137
1138 public List<IGFolder> findByG_P(long groupId, long parentFolderId)
1139 throws SystemException {
1140 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
1141 String finderClassName = IGFolder.class.getName();
1142 String finderMethodName = "findByG_P";
1143 String[] finderParams = new String[] {
1144 Long.class.getName(), Long.class.getName()
1145 };
1146 Object[] finderArgs = new Object[] {
1147 new Long(groupId), new Long(parentFolderId)
1148 };
1149
1150 Object result = null;
1151
1152 if (finderClassNameCacheEnabled) {
1153 result = FinderCacheUtil.getResult(finderClassName,
1154 finderMethodName, finderParams, finderArgs, this);
1155 }
1156
1157 if (result == null) {
1158 Session session = null;
1159
1160 try {
1161 session = openSession();
1162
1163 StringBuilder query = new StringBuilder();
1164
1165 query.append(
1166 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1167
1168 query.append("groupId = ?");
1169
1170 query.append(" AND ");
1171
1172 query.append("parentFolderId = ?");
1173
1174 query.append(" ");
1175
1176 query.append("ORDER BY ");
1177
1178 query.append("folderId ASC, ");
1179 query.append("name ASC");
1180
1181 Query q = session.createQuery(query.toString());
1182
1183 QueryPos qPos = QueryPos.getInstance(q);
1184
1185 qPos.add(groupId);
1186
1187 qPos.add(parentFolderId);
1188
1189 List<IGFolder> list = q.list();
1190
1191 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1192 finderClassName, finderMethodName, finderParams,
1193 finderArgs, list);
1194
1195 return list;
1196 }
1197 catch (Exception e) {
1198 throw processException(e);
1199 }
1200 finally {
1201 closeSession(session);
1202 }
1203 }
1204 else {
1205 return (List<IGFolder>)result;
1206 }
1207 }
1208
1209 public List<IGFolder> findByG_P(long groupId, long parentFolderId,
1210 int start, int end) throws SystemException {
1211 return findByG_P(groupId, parentFolderId, start, end, null);
1212 }
1213
1214 public List<IGFolder> findByG_P(long groupId, long parentFolderId,
1215 int start, int end, OrderByComparator obc) throws SystemException {
1216 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
1217 String finderClassName = IGFolder.class.getName();
1218 String finderMethodName = "findByG_P";
1219 String[] finderParams = new String[] {
1220 Long.class.getName(), Long.class.getName(),
1221
1222 "java.lang.Integer", "java.lang.Integer",
1223 "com.liferay.portal.kernel.util.OrderByComparator"
1224 };
1225 Object[] finderArgs = new Object[] {
1226 new Long(groupId), new Long(parentFolderId),
1227
1228 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1229 };
1230
1231 Object result = null;
1232
1233 if (finderClassNameCacheEnabled) {
1234 result = FinderCacheUtil.getResult(finderClassName,
1235 finderMethodName, finderParams, finderArgs, this);
1236 }
1237
1238 if (result == null) {
1239 Session session = null;
1240
1241 try {
1242 session = openSession();
1243
1244 StringBuilder query = new StringBuilder();
1245
1246 query.append(
1247 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1248
1249 query.append("groupId = ?");
1250
1251 query.append(" AND ");
1252
1253 query.append("parentFolderId = ?");
1254
1255 query.append(" ");
1256
1257 if (obc != null) {
1258 query.append("ORDER BY ");
1259 query.append(obc.getOrderBy());
1260 }
1261
1262 else {
1263 query.append("ORDER BY ");
1264
1265 query.append("folderId ASC, ");
1266 query.append("name ASC");
1267 }
1268
1269 Query q = session.createQuery(query.toString());
1270
1271 QueryPos qPos = QueryPos.getInstance(q);
1272
1273 qPos.add(groupId);
1274
1275 qPos.add(parentFolderId);
1276
1277 List<IGFolder> list = (List<IGFolder>)QueryUtil.list(q,
1278 getDialect(), start, end);
1279
1280 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1281 finderClassName, finderMethodName, finderParams,
1282 finderArgs, list);
1283
1284 return list;
1285 }
1286 catch (Exception e) {
1287 throw processException(e);
1288 }
1289 finally {
1290 closeSession(session);
1291 }
1292 }
1293 else {
1294 return (List<IGFolder>)result;
1295 }
1296 }
1297
1298 public IGFolder findByG_P_First(long groupId, long parentFolderId,
1299 OrderByComparator obc) throws NoSuchFolderException, SystemException {
1300 List<IGFolder> list = findByG_P(groupId, parentFolderId, 0, 1, obc);
1301
1302 if (list.size() == 0) {
1303 StringBuilder msg = new StringBuilder();
1304
1305 msg.append("No IGFolder exists with the key {");
1306
1307 msg.append("groupId=" + groupId);
1308
1309 msg.append(", ");
1310 msg.append("parentFolderId=" + parentFolderId);
1311
1312 msg.append(StringPool.CLOSE_CURLY_BRACE);
1313
1314 throw new NoSuchFolderException(msg.toString());
1315 }
1316 else {
1317 return list.get(0);
1318 }
1319 }
1320
1321 public IGFolder findByG_P_Last(long groupId, long parentFolderId,
1322 OrderByComparator obc) throws NoSuchFolderException, SystemException {
1323 int count = countByG_P(groupId, parentFolderId);
1324
1325 List<IGFolder> list = findByG_P(groupId, parentFolderId, count - 1,
1326 count, obc);
1327
1328 if (list.size() == 0) {
1329 StringBuilder msg = new StringBuilder();
1330
1331 msg.append("No IGFolder exists with the key {");
1332
1333 msg.append("groupId=" + groupId);
1334
1335 msg.append(", ");
1336 msg.append("parentFolderId=" + parentFolderId);
1337
1338 msg.append(StringPool.CLOSE_CURLY_BRACE);
1339
1340 throw new NoSuchFolderException(msg.toString());
1341 }
1342 else {
1343 return list.get(0);
1344 }
1345 }
1346
1347 public IGFolder[] findByG_P_PrevAndNext(long folderId, long groupId,
1348 long parentFolderId, OrderByComparator obc)
1349 throws NoSuchFolderException, SystemException {
1350 IGFolder igFolder = findByPrimaryKey(folderId);
1351
1352 int count = countByG_P(groupId, parentFolderId);
1353
1354 Session session = null;
1355
1356 try {
1357 session = openSession();
1358
1359 StringBuilder query = new StringBuilder();
1360
1361 query.append(
1362 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1363
1364 query.append("groupId = ?");
1365
1366 query.append(" AND ");
1367
1368 query.append("parentFolderId = ?");
1369
1370 query.append(" ");
1371
1372 if (obc != null) {
1373 query.append("ORDER BY ");
1374 query.append(obc.getOrderBy());
1375 }
1376
1377 else {
1378 query.append("ORDER BY ");
1379
1380 query.append("folderId ASC, ");
1381 query.append("name ASC");
1382 }
1383
1384 Query q = session.createQuery(query.toString());
1385
1386 QueryPos qPos = QueryPos.getInstance(q);
1387
1388 qPos.add(groupId);
1389
1390 qPos.add(parentFolderId);
1391
1392 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igFolder);
1393
1394 IGFolder[] array = new IGFolderImpl[3];
1395
1396 array[0] = (IGFolder)objArray[0];
1397 array[1] = (IGFolder)objArray[1];
1398 array[2] = (IGFolder)objArray[2];
1399
1400 return array;
1401 }
1402 catch (Exception e) {
1403 throw processException(e);
1404 }
1405 finally {
1406 closeSession(session);
1407 }
1408 }
1409
1410 public IGFolder findByG_P_N(long groupId, long parentFolderId, String name)
1411 throws NoSuchFolderException, SystemException {
1412 IGFolder igFolder = fetchByG_P_N(groupId, parentFolderId, name);
1413
1414 if (igFolder == null) {
1415 StringBuilder msg = new StringBuilder();
1416
1417 msg.append("No IGFolder exists with the key {");
1418
1419 msg.append("groupId=" + groupId);
1420
1421 msg.append(", ");
1422 msg.append("parentFolderId=" + parentFolderId);
1423
1424 msg.append(", ");
1425 msg.append("name=" + name);
1426
1427 msg.append(StringPool.CLOSE_CURLY_BRACE);
1428
1429 if (_log.isWarnEnabled()) {
1430 _log.warn(msg.toString());
1431 }
1432
1433 throw new NoSuchFolderException(msg.toString());
1434 }
1435
1436 return igFolder;
1437 }
1438
1439 public IGFolder fetchByG_P_N(long groupId, long parentFolderId, String name)
1440 throws SystemException {
1441 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
1442 String finderClassName = IGFolder.class.getName();
1443 String finderMethodName = "fetchByG_P_N";
1444 String[] finderParams = new String[] {
1445 Long.class.getName(), Long.class.getName(),
1446 String.class.getName()
1447 };
1448 Object[] finderArgs = new Object[] {
1449 new Long(groupId), new Long(parentFolderId),
1450
1451 name
1452 };
1453
1454 Object result = null;
1455
1456 if (finderClassNameCacheEnabled) {
1457 result = FinderCacheUtil.getResult(finderClassName,
1458 finderMethodName, finderParams, finderArgs, this);
1459 }
1460
1461 if (result == null) {
1462 Session session = null;
1463
1464 try {
1465 session = openSession();
1466
1467 StringBuilder query = new StringBuilder();
1468
1469 query.append(
1470 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1471
1472 query.append("groupId = ?");
1473
1474 query.append(" AND ");
1475
1476 query.append("parentFolderId = ?");
1477
1478 query.append(" AND ");
1479
1480 if (name == null) {
1481 query.append("name IS NULL");
1482 }
1483 else {
1484 query.append("name = ?");
1485 }
1486
1487 query.append(" ");
1488
1489 query.append("ORDER BY ");
1490
1491 query.append("folderId ASC, ");
1492 query.append("name ASC");
1493
1494 Query q = session.createQuery(query.toString());
1495
1496 QueryPos qPos = QueryPos.getInstance(q);
1497
1498 qPos.add(groupId);
1499
1500 qPos.add(parentFolderId);
1501
1502 if (name != null) {
1503 qPos.add(name);
1504 }
1505
1506 List<IGFolder> list = q.list();
1507
1508 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1509 finderClassName, finderMethodName, finderParams,
1510 finderArgs, list);
1511
1512 if (list.size() == 0) {
1513 return null;
1514 }
1515 else {
1516 return list.get(0);
1517 }
1518 }
1519 catch (Exception e) {
1520 throw processException(e);
1521 }
1522 finally {
1523 closeSession(session);
1524 }
1525 }
1526 else {
1527 List<IGFolder> list = (List<IGFolder>)result;
1528
1529 if (list.size() == 0) {
1530 return null;
1531 }
1532 else {
1533 return list.get(0);
1534 }
1535 }
1536 }
1537
1538 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1539 throws SystemException {
1540 Session session = null;
1541
1542 try {
1543 session = openSession();
1544
1545 dynamicQuery.compile(session);
1546
1547 return dynamicQuery.list();
1548 }
1549 catch (Exception e) {
1550 throw processException(e);
1551 }
1552 finally {
1553 closeSession(session);
1554 }
1555 }
1556
1557 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1558 int start, int end) throws SystemException {
1559 Session session = null;
1560
1561 try {
1562 session = openSession();
1563
1564 dynamicQuery.setLimit(start, end);
1565
1566 dynamicQuery.compile(session);
1567
1568 return dynamicQuery.list();
1569 }
1570 catch (Exception e) {
1571 throw processException(e);
1572 }
1573 finally {
1574 closeSession(session);
1575 }
1576 }
1577
1578 public List<IGFolder> findAll() throws SystemException {
1579 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1580 }
1581
1582 public List<IGFolder> findAll(int start, int end) throws SystemException {
1583 return findAll(start, end, null);
1584 }
1585
1586 public List<IGFolder> findAll(int start, int end, OrderByComparator obc)
1587 throws SystemException {
1588 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
1589 String finderClassName = IGFolder.class.getName();
1590 String finderMethodName = "findAll";
1591 String[] finderParams = new String[] {
1592 "java.lang.Integer", "java.lang.Integer",
1593 "com.liferay.portal.kernel.util.OrderByComparator"
1594 };
1595 Object[] finderArgs = new Object[] {
1596 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1597 };
1598
1599 Object result = null;
1600
1601 if (finderClassNameCacheEnabled) {
1602 result = FinderCacheUtil.getResult(finderClassName,
1603 finderMethodName, finderParams, finderArgs, this);
1604 }
1605
1606 if (result == null) {
1607 Session session = null;
1608
1609 try {
1610 session = openSession();
1611
1612 StringBuilder query = new StringBuilder();
1613
1614 query.append(
1615 "FROM com.liferay.portlet.imagegallery.model.IGFolder ");
1616
1617 if (obc != null) {
1618 query.append("ORDER BY ");
1619 query.append(obc.getOrderBy());
1620 }
1621
1622 else {
1623 query.append("ORDER BY ");
1624
1625 query.append("folderId ASC, ");
1626 query.append("name ASC");
1627 }
1628
1629 Query q = session.createQuery(query.toString());
1630
1631 List<IGFolder> list = null;
1632
1633 if (obc == null) {
1634 list = (List<IGFolder>)QueryUtil.list(q, getDialect(),
1635 start, end, false);
1636
1637 Collections.sort(list);
1638 }
1639 else {
1640 list = (List<IGFolder>)QueryUtil.list(q, getDialect(),
1641 start, end);
1642 }
1643
1644 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1645 finderClassName, finderMethodName, finderParams,
1646 finderArgs, list);
1647
1648 return list;
1649 }
1650 catch (Exception e) {
1651 throw processException(e);
1652 }
1653 finally {
1654 closeSession(session);
1655 }
1656 }
1657 else {
1658 return (List<IGFolder>)result;
1659 }
1660 }
1661
1662 public void removeByUuid(String uuid) throws SystemException {
1663 for (IGFolder igFolder : findByUuid(uuid)) {
1664 remove(igFolder);
1665 }
1666 }
1667
1668 public void removeByUUID_G(String uuid, long groupId)
1669 throws NoSuchFolderException, SystemException {
1670 IGFolder igFolder = findByUUID_G(uuid, groupId);
1671
1672 remove(igFolder);
1673 }
1674
1675 public void removeByGroupId(long groupId) throws SystemException {
1676 for (IGFolder igFolder : findByGroupId(groupId)) {
1677 remove(igFolder);
1678 }
1679 }
1680
1681 public void removeByCompanyId(long companyId) throws SystemException {
1682 for (IGFolder igFolder : findByCompanyId(companyId)) {
1683 remove(igFolder);
1684 }
1685 }
1686
1687 public void removeByG_P(long groupId, long parentFolderId)
1688 throws SystemException {
1689 for (IGFolder igFolder : findByG_P(groupId, parentFolderId)) {
1690 remove(igFolder);
1691 }
1692 }
1693
1694 public void removeByG_P_N(long groupId, long parentFolderId, String name)
1695 throws NoSuchFolderException, SystemException {
1696 IGFolder igFolder = findByG_P_N(groupId, parentFolderId, name);
1697
1698 remove(igFolder);
1699 }
1700
1701 public void removeAll() throws SystemException {
1702 for (IGFolder igFolder : findAll()) {
1703 remove(igFolder);
1704 }
1705 }
1706
1707 public int countByUuid(String uuid) throws SystemException {
1708 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
1709 String finderClassName = IGFolder.class.getName();
1710 String finderMethodName = "countByUuid";
1711 String[] finderParams = new String[] { String.class.getName() };
1712 Object[] finderArgs = new Object[] { uuid };
1713
1714 Object result = null;
1715
1716 if (finderClassNameCacheEnabled) {
1717 result = FinderCacheUtil.getResult(finderClassName,
1718 finderMethodName, finderParams, finderArgs, this);
1719 }
1720
1721 if (result == null) {
1722 Session session = null;
1723
1724 try {
1725 session = openSession();
1726
1727 StringBuilder query = new StringBuilder();
1728
1729 query.append("SELECT COUNT(*) ");
1730 query.append(
1731 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1732
1733 if (uuid == null) {
1734 query.append("uuid_ IS NULL");
1735 }
1736 else {
1737 query.append("uuid_ = ?");
1738 }
1739
1740 query.append(" ");
1741
1742 Query q = session.createQuery(query.toString());
1743
1744 QueryPos qPos = QueryPos.getInstance(q);
1745
1746 if (uuid != null) {
1747 qPos.add(uuid);
1748 }
1749
1750 Long count = null;
1751
1752 Iterator<Long> itr = q.list().iterator();
1753
1754 if (itr.hasNext()) {
1755 count = itr.next();
1756 }
1757
1758 if (count == null) {
1759 count = new Long(0);
1760 }
1761
1762 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1763 finderClassName, finderMethodName, finderParams,
1764 finderArgs, count);
1765
1766 return count.intValue();
1767 }
1768 catch (Exception e) {
1769 throw processException(e);
1770 }
1771 finally {
1772 closeSession(session);
1773 }
1774 }
1775 else {
1776 return ((Long)result).intValue();
1777 }
1778 }
1779
1780 public int countByUUID_G(String uuid, long groupId)
1781 throws SystemException {
1782 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
1783 String finderClassName = IGFolder.class.getName();
1784 String finderMethodName = "countByUUID_G";
1785 String[] finderParams = new String[] {
1786 String.class.getName(), Long.class.getName()
1787 };
1788 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1789
1790 Object result = null;
1791
1792 if (finderClassNameCacheEnabled) {
1793 result = FinderCacheUtil.getResult(finderClassName,
1794 finderMethodName, finderParams, finderArgs, this);
1795 }
1796
1797 if (result == null) {
1798 Session session = null;
1799
1800 try {
1801 session = openSession();
1802
1803 StringBuilder query = new StringBuilder();
1804
1805 query.append("SELECT COUNT(*) ");
1806 query.append(
1807 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1808
1809 if (uuid == null) {
1810 query.append("uuid_ IS NULL");
1811 }
1812 else {
1813 query.append("uuid_ = ?");
1814 }
1815
1816 query.append(" AND ");
1817
1818 query.append("groupId = ?");
1819
1820 query.append(" ");
1821
1822 Query q = session.createQuery(query.toString());
1823
1824 QueryPos qPos = QueryPos.getInstance(q);
1825
1826 if (uuid != null) {
1827 qPos.add(uuid);
1828 }
1829
1830 qPos.add(groupId);
1831
1832 Long count = null;
1833
1834 Iterator<Long> itr = q.list().iterator();
1835
1836 if (itr.hasNext()) {
1837 count = itr.next();
1838 }
1839
1840 if (count == null) {
1841 count = new Long(0);
1842 }
1843
1844 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1845 finderClassName, finderMethodName, finderParams,
1846 finderArgs, count);
1847
1848 return count.intValue();
1849 }
1850 catch (Exception e) {
1851 throw processException(e);
1852 }
1853 finally {
1854 closeSession(session);
1855 }
1856 }
1857 else {
1858 return ((Long)result).intValue();
1859 }
1860 }
1861
1862 public int countByGroupId(long groupId) throws SystemException {
1863 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
1864 String finderClassName = IGFolder.class.getName();
1865 String finderMethodName = "countByGroupId";
1866 String[] finderParams = new String[] { Long.class.getName() };
1867 Object[] finderArgs = new Object[] { new Long(groupId) };
1868
1869 Object result = null;
1870
1871 if (finderClassNameCacheEnabled) {
1872 result = FinderCacheUtil.getResult(finderClassName,
1873 finderMethodName, finderParams, finderArgs, this);
1874 }
1875
1876 if (result == null) {
1877 Session session = null;
1878
1879 try {
1880 session = openSession();
1881
1882 StringBuilder query = new StringBuilder();
1883
1884 query.append("SELECT COUNT(*) ");
1885 query.append(
1886 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1887
1888 query.append("groupId = ?");
1889
1890 query.append(" ");
1891
1892 Query q = session.createQuery(query.toString());
1893
1894 QueryPos qPos = QueryPos.getInstance(q);
1895
1896 qPos.add(groupId);
1897
1898 Long count = null;
1899
1900 Iterator<Long> itr = q.list().iterator();
1901
1902 if (itr.hasNext()) {
1903 count = itr.next();
1904 }
1905
1906 if (count == null) {
1907 count = new Long(0);
1908 }
1909
1910 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1911 finderClassName, finderMethodName, finderParams,
1912 finderArgs, count);
1913
1914 return count.intValue();
1915 }
1916 catch (Exception e) {
1917 throw processException(e);
1918 }
1919 finally {
1920 closeSession(session);
1921 }
1922 }
1923 else {
1924 return ((Long)result).intValue();
1925 }
1926 }
1927
1928 public int countByCompanyId(long companyId) throws SystemException {
1929 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
1930 String finderClassName = IGFolder.class.getName();
1931 String finderMethodName = "countByCompanyId";
1932 String[] finderParams = new String[] { Long.class.getName() };
1933 Object[] finderArgs = new Object[] { new Long(companyId) };
1934
1935 Object result = null;
1936
1937 if (finderClassNameCacheEnabled) {
1938 result = FinderCacheUtil.getResult(finderClassName,
1939 finderMethodName, finderParams, finderArgs, this);
1940 }
1941
1942 if (result == null) {
1943 Session session = null;
1944
1945 try {
1946 session = openSession();
1947
1948 StringBuilder query = new StringBuilder();
1949
1950 query.append("SELECT COUNT(*) ");
1951 query.append(
1952 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
1953
1954 query.append("companyId = ?");
1955
1956 query.append(" ");
1957
1958 Query q = session.createQuery(query.toString());
1959
1960 QueryPos qPos = QueryPos.getInstance(q);
1961
1962 qPos.add(companyId);
1963
1964 Long count = null;
1965
1966 Iterator<Long> itr = q.list().iterator();
1967
1968 if (itr.hasNext()) {
1969 count = itr.next();
1970 }
1971
1972 if (count == null) {
1973 count = new Long(0);
1974 }
1975
1976 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1977 finderClassName, finderMethodName, finderParams,
1978 finderArgs, count);
1979
1980 return count.intValue();
1981 }
1982 catch (Exception e) {
1983 throw processException(e);
1984 }
1985 finally {
1986 closeSession(session);
1987 }
1988 }
1989 else {
1990 return ((Long)result).intValue();
1991 }
1992 }
1993
1994 public int countByG_P(long groupId, long parentFolderId)
1995 throws SystemException {
1996 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
1997 String finderClassName = IGFolder.class.getName();
1998 String finderMethodName = "countByG_P";
1999 String[] finderParams = new String[] {
2000 Long.class.getName(), Long.class.getName()
2001 };
2002 Object[] finderArgs = new Object[] {
2003 new Long(groupId), new Long(parentFolderId)
2004 };
2005
2006 Object result = null;
2007
2008 if (finderClassNameCacheEnabled) {
2009 result = FinderCacheUtil.getResult(finderClassName,
2010 finderMethodName, finderParams, finderArgs, this);
2011 }
2012
2013 if (result == null) {
2014 Session session = null;
2015
2016 try {
2017 session = openSession();
2018
2019 StringBuilder query = new StringBuilder();
2020
2021 query.append("SELECT COUNT(*) ");
2022 query.append(
2023 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
2024
2025 query.append("groupId = ?");
2026
2027 query.append(" AND ");
2028
2029 query.append("parentFolderId = ?");
2030
2031 query.append(" ");
2032
2033 Query q = session.createQuery(query.toString());
2034
2035 QueryPos qPos = QueryPos.getInstance(q);
2036
2037 qPos.add(groupId);
2038
2039 qPos.add(parentFolderId);
2040
2041 Long count = null;
2042
2043 Iterator<Long> itr = q.list().iterator();
2044
2045 if (itr.hasNext()) {
2046 count = itr.next();
2047 }
2048
2049 if (count == null) {
2050 count = new Long(0);
2051 }
2052
2053 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2054 finderClassName, finderMethodName, finderParams,
2055 finderArgs, count);
2056
2057 return count.intValue();
2058 }
2059 catch (Exception e) {
2060 throw processException(e);
2061 }
2062 finally {
2063 closeSession(session);
2064 }
2065 }
2066 else {
2067 return ((Long)result).intValue();
2068 }
2069 }
2070
2071 public int countByG_P_N(long groupId, long parentFolderId, String name)
2072 throws SystemException {
2073 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
2074 String finderClassName = IGFolder.class.getName();
2075 String finderMethodName = "countByG_P_N";
2076 String[] finderParams = new String[] {
2077 Long.class.getName(), Long.class.getName(),
2078 String.class.getName()
2079 };
2080 Object[] finderArgs = new Object[] {
2081 new Long(groupId), new Long(parentFolderId),
2082
2083 name
2084 };
2085
2086 Object result = null;
2087
2088 if (finderClassNameCacheEnabled) {
2089 result = FinderCacheUtil.getResult(finderClassName,
2090 finderMethodName, finderParams, finderArgs, this);
2091 }
2092
2093 if (result == null) {
2094 Session session = null;
2095
2096 try {
2097 session = openSession();
2098
2099 StringBuilder query = new StringBuilder();
2100
2101 query.append("SELECT COUNT(*) ");
2102 query.append(
2103 "FROM com.liferay.portlet.imagegallery.model.IGFolder WHERE ");
2104
2105 query.append("groupId = ?");
2106
2107 query.append(" AND ");
2108
2109 query.append("parentFolderId = ?");
2110
2111 query.append(" AND ");
2112
2113 if (name == null) {
2114 query.append("name IS NULL");
2115 }
2116 else {
2117 query.append("name = ?");
2118 }
2119
2120 query.append(" ");
2121
2122 Query q = session.createQuery(query.toString());
2123
2124 QueryPos qPos = QueryPos.getInstance(q);
2125
2126 qPos.add(groupId);
2127
2128 qPos.add(parentFolderId);
2129
2130 if (name != null) {
2131 qPos.add(name);
2132 }
2133
2134 Long count = null;
2135
2136 Iterator<Long> itr = q.list().iterator();
2137
2138 if (itr.hasNext()) {
2139 count = itr.next();
2140 }
2141
2142 if (count == null) {
2143 count = new Long(0);
2144 }
2145
2146 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2147 finderClassName, finderMethodName, finderParams,
2148 finderArgs, count);
2149
2150 return count.intValue();
2151 }
2152 catch (Exception e) {
2153 throw processException(e);
2154 }
2155 finally {
2156 closeSession(session);
2157 }
2158 }
2159 else {
2160 return ((Long)result).intValue();
2161 }
2162 }
2163
2164 public int countAll() throws SystemException {
2165 boolean finderClassNameCacheEnabled = IGFolderModelImpl.CACHE_ENABLED;
2166 String finderClassName = IGFolder.class.getName();
2167 String finderMethodName = "countAll";
2168 String[] finderParams = new String[] { };
2169 Object[] finderArgs = new Object[] { };
2170
2171 Object result = null;
2172
2173 if (finderClassNameCacheEnabled) {
2174 result = FinderCacheUtil.getResult(finderClassName,
2175 finderMethodName, finderParams, finderArgs, this);
2176 }
2177
2178 if (result == null) {
2179 Session session = null;
2180
2181 try {
2182 session = openSession();
2183
2184 Query q = session.createQuery(
2185 "SELECT COUNT(*) FROM com.liferay.portlet.imagegallery.model.IGFolder");
2186
2187 Long count = null;
2188
2189 Iterator<Long> itr = q.list().iterator();
2190
2191 if (itr.hasNext()) {
2192 count = itr.next();
2193 }
2194
2195 if (count == null) {
2196 count = new Long(0);
2197 }
2198
2199 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2200 finderClassName, finderMethodName, finderParams,
2201 finderArgs, count);
2202
2203 return count.intValue();
2204 }
2205 catch (Exception e) {
2206 throw processException(e);
2207 }
2208 finally {
2209 closeSession(session);
2210 }
2211 }
2212 else {
2213 return ((Long)result).intValue();
2214 }
2215 }
2216
2217 public void registerListener(ModelListener listener) {
2218 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2219
2220 listeners.add(listener);
2221
2222 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2223 }
2224
2225 public void unregisterListener(ModelListener listener) {
2226 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2227
2228 listeners.remove(listener);
2229
2230 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2231 }
2232
2233 public void afterPropertiesSet() {
2234 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2235 com.liferay.portal.util.PropsUtil.get(
2236 "value.object.listener.com.liferay.portlet.imagegallery.model.IGFolder")));
2237
2238 if (listenerClassNames.length > 0) {
2239 try {
2240 List<ModelListener> listeners = new ArrayList<ModelListener>();
2241
2242 for (String listenerClassName : listenerClassNames) {
2243 listeners.add((ModelListener)Class.forName(
2244 listenerClassName).newInstance());
2245 }
2246
2247 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2248 }
2249 catch (Exception e) {
2250 _log.error(e);
2251 }
2252 }
2253 }
2254
2255 private static Log _log = LogFactory.getLog(IGFolderPersistenceImpl.class);
2256 private ModelListener[] _listeners = new ModelListener[0];
2257}