1
22
23 package com.liferay.portal.service.persistence;
24
25 import com.liferay.portal.NoSuchLayoutSetException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.bean.InitializingBean;
28 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
29 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
30 import com.liferay.portal.kernel.dao.orm.Query;
31 import com.liferay.portal.kernel.dao.orm.QueryPos;
32 import com.liferay.portal.kernel.dao.orm.QueryUtil;
33 import com.liferay.portal.kernel.dao.orm.Session;
34 import com.liferay.portal.kernel.util.GetterUtil;
35 import com.liferay.portal.kernel.util.ListUtil;
36 import com.liferay.portal.kernel.util.OrderByComparator;
37 import com.liferay.portal.kernel.util.StringPool;
38 import com.liferay.portal.kernel.util.StringUtil;
39 import com.liferay.portal.model.LayoutSet;
40 import com.liferay.portal.model.ModelListener;
41 import com.liferay.portal.model.impl.LayoutSetImpl;
42 import com.liferay.portal.model.impl.LayoutSetModelImpl;
43 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
44
45 import org.apache.commons.logging.Log;
46 import org.apache.commons.logging.LogFactory;
47
48 import java.util.ArrayList;
49 import java.util.Collections;
50 import java.util.Iterator;
51 import java.util.List;
52
53
59 public class LayoutSetPersistenceImpl extends BasePersistenceImpl
60 implements LayoutSetPersistence, InitializingBean {
61 public LayoutSet create(long layoutSetId) {
62 LayoutSet layoutSet = new LayoutSetImpl();
63
64 layoutSet.setNew(true);
65 layoutSet.setPrimaryKey(layoutSetId);
66
67 return layoutSet;
68 }
69
70 public LayoutSet remove(long layoutSetId)
71 throws NoSuchLayoutSetException, SystemException {
72 Session session = null;
73
74 try {
75 session = openSession();
76
77 LayoutSet layoutSet = (LayoutSet)session.get(LayoutSetImpl.class,
78 new Long(layoutSetId));
79
80 if (layoutSet == null) {
81 if (_log.isWarnEnabled()) {
82 _log.warn("No LayoutSet exists with the primary key " +
83 layoutSetId);
84 }
85
86 throw new NoSuchLayoutSetException(
87 "No LayoutSet exists with the primary key " + layoutSetId);
88 }
89
90 return remove(layoutSet);
91 }
92 catch (NoSuchLayoutSetException nsee) {
93 throw nsee;
94 }
95 catch (Exception e) {
96 throw processException(e);
97 }
98 finally {
99 closeSession(session);
100 }
101 }
102
103 public LayoutSet remove(LayoutSet layoutSet) throws SystemException {
104 if (_listeners.length > 0) {
105 for (ModelListener listener : _listeners) {
106 listener.onBeforeRemove(layoutSet);
107 }
108 }
109
110 layoutSet = removeImpl(layoutSet);
111
112 if (_listeners.length > 0) {
113 for (ModelListener listener : _listeners) {
114 listener.onAfterRemove(layoutSet);
115 }
116 }
117
118 return layoutSet;
119 }
120
121 protected LayoutSet removeImpl(LayoutSet layoutSet)
122 throws SystemException {
123 Session session = null;
124
125 try {
126 session = openSession();
127
128 session.delete(layoutSet);
129
130 session.flush();
131
132 return layoutSet;
133 }
134 catch (Exception e) {
135 throw processException(e);
136 }
137 finally {
138 closeSession(session);
139
140 FinderCacheUtil.clearCache(LayoutSet.class.getName());
141 }
142 }
143
144
147 public LayoutSet update(LayoutSet layoutSet) throws SystemException {
148 if (_log.isWarnEnabled()) {
149 _log.warn(
150 "Using the deprecated update(LayoutSet layoutSet) method. Use update(LayoutSet layoutSet, boolean merge) instead.");
151 }
152
153 return update(layoutSet, false);
154 }
155
156
169 public LayoutSet update(LayoutSet layoutSet, boolean merge)
170 throws SystemException {
171 boolean isNew = layoutSet.isNew();
172
173 if (_listeners.length > 0) {
174 for (ModelListener listener : _listeners) {
175 if (isNew) {
176 listener.onBeforeCreate(layoutSet);
177 }
178 else {
179 listener.onBeforeUpdate(layoutSet);
180 }
181 }
182 }
183
184 layoutSet = updateImpl(layoutSet, merge);
185
186 if (_listeners.length > 0) {
187 for (ModelListener listener : _listeners) {
188 if (isNew) {
189 listener.onAfterCreate(layoutSet);
190 }
191 else {
192 listener.onAfterUpdate(layoutSet);
193 }
194 }
195 }
196
197 return layoutSet;
198 }
199
200 public LayoutSet updateImpl(com.liferay.portal.model.LayoutSet layoutSet,
201 boolean merge) throws SystemException {
202 Session session = null;
203
204 try {
205 session = openSession();
206
207 if (merge) {
208 session.merge(layoutSet);
209 }
210 else {
211 if (layoutSet.isNew()) {
212 session.save(layoutSet);
213 }
214 }
215
216 session.flush();
217
218 layoutSet.setNew(false);
219
220 return layoutSet;
221 }
222 catch (Exception e) {
223 throw processException(e);
224 }
225 finally {
226 closeSession(session);
227
228 FinderCacheUtil.clearCache(LayoutSet.class.getName());
229 }
230 }
231
232 public LayoutSet findByPrimaryKey(long layoutSetId)
233 throws NoSuchLayoutSetException, SystemException {
234 LayoutSet layoutSet = fetchByPrimaryKey(layoutSetId);
235
236 if (layoutSet == null) {
237 if (_log.isWarnEnabled()) {
238 _log.warn("No LayoutSet exists with the primary key " +
239 layoutSetId);
240 }
241
242 throw new NoSuchLayoutSetException(
243 "No LayoutSet exists with the primary key " + layoutSetId);
244 }
245
246 return layoutSet;
247 }
248
249 public LayoutSet fetchByPrimaryKey(long layoutSetId)
250 throws SystemException {
251 Session session = null;
252
253 try {
254 session = openSession();
255
256 return (LayoutSet)session.get(LayoutSetImpl.class,
257 new Long(layoutSetId));
258 }
259 catch (Exception e) {
260 throw processException(e);
261 }
262 finally {
263 closeSession(session);
264 }
265 }
266
267 public List<LayoutSet> findByGroupId(long groupId)
268 throws SystemException {
269 boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
270 String finderClassName = LayoutSet.class.getName();
271 String finderMethodName = "findByGroupId";
272 String[] finderParams = new String[] { Long.class.getName() };
273 Object[] finderArgs = new Object[] { new Long(groupId) };
274
275 Object result = null;
276
277 if (finderClassNameCacheEnabled) {
278 result = FinderCacheUtil.getResult(finderClassName,
279 finderMethodName, finderParams, finderArgs, this);
280 }
281
282 if (result == null) {
283 Session session = null;
284
285 try {
286 session = openSession();
287
288 StringBuilder query = new StringBuilder();
289
290 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
291
292 query.append("groupId = ?");
293
294 query.append(" ");
295
296 Query q = session.createQuery(query.toString());
297
298 QueryPos qPos = QueryPos.getInstance(q);
299
300 qPos.add(groupId);
301
302 List<LayoutSet> list = q.list();
303
304 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
305 finderClassName, finderMethodName, finderParams,
306 finderArgs, list);
307
308 return list;
309 }
310 catch (Exception e) {
311 throw processException(e);
312 }
313 finally {
314 closeSession(session);
315 }
316 }
317 else {
318 return (List<LayoutSet>)result;
319 }
320 }
321
322 public List<LayoutSet> findByGroupId(long groupId, int start, int end)
323 throws SystemException {
324 return findByGroupId(groupId, start, end, null);
325 }
326
327 public List<LayoutSet> findByGroupId(long groupId, int start, int end,
328 OrderByComparator obc) throws SystemException {
329 boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
330 String finderClassName = LayoutSet.class.getName();
331 String finderMethodName = "findByGroupId";
332 String[] finderParams = new String[] {
333 Long.class.getName(),
334
335 "java.lang.Integer", "java.lang.Integer",
336 "com.liferay.portal.kernel.util.OrderByComparator"
337 };
338 Object[] finderArgs = new Object[] {
339 new Long(groupId),
340
341 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
342 };
343
344 Object result = null;
345
346 if (finderClassNameCacheEnabled) {
347 result = FinderCacheUtil.getResult(finderClassName,
348 finderMethodName, finderParams, finderArgs, this);
349 }
350
351 if (result == null) {
352 Session session = null;
353
354 try {
355 session = openSession();
356
357 StringBuilder query = new StringBuilder();
358
359 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
360
361 query.append("groupId = ?");
362
363 query.append(" ");
364
365 if (obc != null) {
366 query.append("ORDER BY ");
367 query.append(obc.getOrderBy());
368 }
369
370 Query q = session.createQuery(query.toString());
371
372 QueryPos qPos = QueryPos.getInstance(q);
373
374 qPos.add(groupId);
375
376 List<LayoutSet> list = (List<LayoutSet>)QueryUtil.list(q,
377 getDialect(), start, end);
378
379 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
380 finderClassName, finderMethodName, finderParams,
381 finderArgs, list);
382
383 return list;
384 }
385 catch (Exception e) {
386 throw processException(e);
387 }
388 finally {
389 closeSession(session);
390 }
391 }
392 else {
393 return (List<LayoutSet>)result;
394 }
395 }
396
397 public LayoutSet findByGroupId_First(long groupId, OrderByComparator obc)
398 throws NoSuchLayoutSetException, SystemException {
399 List<LayoutSet> list = findByGroupId(groupId, 0, 1, obc);
400
401 if (list.size() == 0) {
402 StringBuilder msg = new StringBuilder();
403
404 msg.append("No LayoutSet exists with the key {");
405
406 msg.append("groupId=" + groupId);
407
408 msg.append(StringPool.CLOSE_CURLY_BRACE);
409
410 throw new NoSuchLayoutSetException(msg.toString());
411 }
412 else {
413 return list.get(0);
414 }
415 }
416
417 public LayoutSet findByGroupId_Last(long groupId, OrderByComparator obc)
418 throws NoSuchLayoutSetException, SystemException {
419 int count = countByGroupId(groupId);
420
421 List<LayoutSet> list = findByGroupId(groupId, count - 1, count, obc);
422
423 if (list.size() == 0) {
424 StringBuilder msg = new StringBuilder();
425
426 msg.append("No LayoutSet exists with the key {");
427
428 msg.append("groupId=" + groupId);
429
430 msg.append(StringPool.CLOSE_CURLY_BRACE);
431
432 throw new NoSuchLayoutSetException(msg.toString());
433 }
434 else {
435 return list.get(0);
436 }
437 }
438
439 public LayoutSet[] findByGroupId_PrevAndNext(long layoutSetId,
440 long groupId, OrderByComparator obc)
441 throws NoSuchLayoutSetException, SystemException {
442 LayoutSet layoutSet = findByPrimaryKey(layoutSetId);
443
444 int count = countByGroupId(groupId);
445
446 Session session = null;
447
448 try {
449 session = openSession();
450
451 StringBuilder query = new StringBuilder();
452
453 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
454
455 query.append("groupId = ?");
456
457 query.append(" ");
458
459 if (obc != null) {
460 query.append("ORDER BY ");
461 query.append(obc.getOrderBy());
462 }
463
464 Query q = session.createQuery(query.toString());
465
466 QueryPos qPos = QueryPos.getInstance(q);
467
468 qPos.add(groupId);
469
470 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
471 layoutSet);
472
473 LayoutSet[] array = new LayoutSetImpl[3];
474
475 array[0] = (LayoutSet)objArray[0];
476 array[1] = (LayoutSet)objArray[1];
477 array[2] = (LayoutSet)objArray[2];
478
479 return array;
480 }
481 catch (Exception e) {
482 throw processException(e);
483 }
484 finally {
485 closeSession(session);
486 }
487 }
488
489 public LayoutSet findByVirtualHost(String virtualHost)
490 throws NoSuchLayoutSetException, SystemException {
491 LayoutSet layoutSet = fetchByVirtualHost(virtualHost);
492
493 if (layoutSet == null) {
494 StringBuilder msg = new StringBuilder();
495
496 msg.append("No LayoutSet exists with the key {");
497
498 msg.append("virtualHost=" + virtualHost);
499
500 msg.append(StringPool.CLOSE_CURLY_BRACE);
501
502 if (_log.isWarnEnabled()) {
503 _log.warn(msg.toString());
504 }
505
506 throw new NoSuchLayoutSetException(msg.toString());
507 }
508
509 return layoutSet;
510 }
511
512 public LayoutSet fetchByVirtualHost(String virtualHost)
513 throws SystemException {
514 boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
515 String finderClassName = LayoutSet.class.getName();
516 String finderMethodName = "fetchByVirtualHost";
517 String[] finderParams = new String[] { String.class.getName() };
518 Object[] finderArgs = new Object[] { virtualHost };
519
520 Object result = null;
521
522 if (finderClassNameCacheEnabled) {
523 result = FinderCacheUtil.getResult(finderClassName,
524 finderMethodName, finderParams, finderArgs, this);
525 }
526
527 if (result == null) {
528 Session session = null;
529
530 try {
531 session = openSession();
532
533 StringBuilder query = new StringBuilder();
534
535 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
536
537 if (virtualHost == null) {
538 query.append("virtualHost IS NULL");
539 }
540 else {
541 query.append("virtualHost = ?");
542 }
543
544 query.append(" ");
545
546 Query q = session.createQuery(query.toString());
547
548 QueryPos qPos = QueryPos.getInstance(q);
549
550 if (virtualHost != null) {
551 qPos.add(virtualHost);
552 }
553
554 List<LayoutSet> list = q.list();
555
556 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
557 finderClassName, finderMethodName, finderParams,
558 finderArgs, list);
559
560 if (list.size() == 0) {
561 return null;
562 }
563 else {
564 return list.get(0);
565 }
566 }
567 catch (Exception e) {
568 throw processException(e);
569 }
570 finally {
571 closeSession(session);
572 }
573 }
574 else {
575 List<LayoutSet> list = (List<LayoutSet>)result;
576
577 if (list.size() == 0) {
578 return null;
579 }
580 else {
581 return list.get(0);
582 }
583 }
584 }
585
586 public LayoutSet findByG_P(long groupId, boolean privateLayout)
587 throws NoSuchLayoutSetException, SystemException {
588 LayoutSet layoutSet = fetchByG_P(groupId, privateLayout);
589
590 if (layoutSet == null) {
591 StringBuilder msg = new StringBuilder();
592
593 msg.append("No LayoutSet exists with the key {");
594
595 msg.append("groupId=" + groupId);
596
597 msg.append(", ");
598 msg.append("privateLayout=" + privateLayout);
599
600 msg.append(StringPool.CLOSE_CURLY_BRACE);
601
602 if (_log.isWarnEnabled()) {
603 _log.warn(msg.toString());
604 }
605
606 throw new NoSuchLayoutSetException(msg.toString());
607 }
608
609 return layoutSet;
610 }
611
612 public LayoutSet fetchByG_P(long groupId, boolean privateLayout)
613 throws SystemException {
614 boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
615 String finderClassName = LayoutSet.class.getName();
616 String finderMethodName = "fetchByG_P";
617 String[] finderParams = new String[] {
618 Long.class.getName(), Boolean.class.getName()
619 };
620 Object[] finderArgs = new Object[] {
621 new Long(groupId), Boolean.valueOf(privateLayout)
622 };
623
624 Object result = null;
625
626 if (finderClassNameCacheEnabled) {
627 result = FinderCacheUtil.getResult(finderClassName,
628 finderMethodName, finderParams, finderArgs, this);
629 }
630
631 if (result == null) {
632 Session session = null;
633
634 try {
635 session = openSession();
636
637 StringBuilder query = new StringBuilder();
638
639 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
640
641 query.append("groupId = ?");
642
643 query.append(" AND ");
644
645 query.append("privateLayout = ?");
646
647 query.append(" ");
648
649 Query q = session.createQuery(query.toString());
650
651 QueryPos qPos = QueryPos.getInstance(q);
652
653 qPos.add(groupId);
654
655 qPos.add(privateLayout);
656
657 List<LayoutSet> list = q.list();
658
659 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
660 finderClassName, finderMethodName, finderParams,
661 finderArgs, list);
662
663 if (list.size() == 0) {
664 return null;
665 }
666 else {
667 return list.get(0);
668 }
669 }
670 catch (Exception e) {
671 throw processException(e);
672 }
673 finally {
674 closeSession(session);
675 }
676 }
677 else {
678 List<LayoutSet> list = (List<LayoutSet>)result;
679
680 if (list.size() == 0) {
681 return null;
682 }
683 else {
684 return list.get(0);
685 }
686 }
687 }
688
689 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
690 throws SystemException {
691 Session session = null;
692
693 try {
694 session = openSession();
695
696 dynamicQuery.compile(session);
697
698 return dynamicQuery.list();
699 }
700 catch (Exception e) {
701 throw processException(e);
702 }
703 finally {
704 closeSession(session);
705 }
706 }
707
708 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
709 int start, int end) throws SystemException {
710 Session session = null;
711
712 try {
713 session = openSession();
714
715 dynamicQuery.setLimit(start, end);
716
717 dynamicQuery.compile(session);
718
719 return dynamicQuery.list();
720 }
721 catch (Exception e) {
722 throw processException(e);
723 }
724 finally {
725 closeSession(session);
726 }
727 }
728
729 public List<LayoutSet> findAll() throws SystemException {
730 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
731 }
732
733 public List<LayoutSet> findAll(int start, int end)
734 throws SystemException {
735 return findAll(start, end, null);
736 }
737
738 public List<LayoutSet> findAll(int start, int end, OrderByComparator obc)
739 throws SystemException {
740 boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
741 String finderClassName = LayoutSet.class.getName();
742 String finderMethodName = "findAll";
743 String[] finderParams = new String[] {
744 "java.lang.Integer", "java.lang.Integer",
745 "com.liferay.portal.kernel.util.OrderByComparator"
746 };
747 Object[] finderArgs = new Object[] {
748 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
749 };
750
751 Object result = null;
752
753 if (finderClassNameCacheEnabled) {
754 result = FinderCacheUtil.getResult(finderClassName,
755 finderMethodName, finderParams, finderArgs, this);
756 }
757
758 if (result == null) {
759 Session session = null;
760
761 try {
762 session = openSession();
763
764 StringBuilder query = new StringBuilder();
765
766 query.append("FROM com.liferay.portal.model.LayoutSet ");
767
768 if (obc != null) {
769 query.append("ORDER BY ");
770 query.append(obc.getOrderBy());
771 }
772
773 Query q = session.createQuery(query.toString());
774
775 List<LayoutSet> list = (List<LayoutSet>)QueryUtil.list(q,
776 getDialect(), start, end);
777
778 if (obc == null) {
779 Collections.sort(list);
780 }
781
782 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
783 finderClassName, finderMethodName, finderParams,
784 finderArgs, list);
785
786 return list;
787 }
788 catch (Exception e) {
789 throw processException(e);
790 }
791 finally {
792 closeSession(session);
793 }
794 }
795 else {
796 return (List<LayoutSet>)result;
797 }
798 }
799
800 public void removeByGroupId(long groupId) throws SystemException {
801 for (LayoutSet layoutSet : findByGroupId(groupId)) {
802 remove(layoutSet);
803 }
804 }
805
806 public void removeByVirtualHost(String virtualHost)
807 throws NoSuchLayoutSetException, SystemException {
808 LayoutSet layoutSet = findByVirtualHost(virtualHost);
809
810 remove(layoutSet);
811 }
812
813 public void removeByG_P(long groupId, boolean privateLayout)
814 throws NoSuchLayoutSetException, SystemException {
815 LayoutSet layoutSet = findByG_P(groupId, privateLayout);
816
817 remove(layoutSet);
818 }
819
820 public void removeAll() throws SystemException {
821 for (LayoutSet layoutSet : findAll()) {
822 remove(layoutSet);
823 }
824 }
825
826 public int countByGroupId(long groupId) throws SystemException {
827 boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
828 String finderClassName = LayoutSet.class.getName();
829 String finderMethodName = "countByGroupId";
830 String[] finderParams = new String[] { Long.class.getName() };
831 Object[] finderArgs = new Object[] { new Long(groupId) };
832
833 Object result = null;
834
835 if (finderClassNameCacheEnabled) {
836 result = FinderCacheUtil.getResult(finderClassName,
837 finderMethodName, finderParams, finderArgs, this);
838 }
839
840 if (result == null) {
841 Session session = null;
842
843 try {
844 session = openSession();
845
846 StringBuilder query = new StringBuilder();
847
848 query.append("SELECT COUNT(*) ");
849 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
850
851 query.append("groupId = ?");
852
853 query.append(" ");
854
855 Query q = session.createQuery(query.toString());
856
857 QueryPos qPos = QueryPos.getInstance(q);
858
859 qPos.add(groupId);
860
861 Long count = null;
862
863 Iterator<Long> itr = q.list().iterator();
864
865 if (itr.hasNext()) {
866 count = itr.next();
867 }
868
869 if (count == null) {
870 count = new Long(0);
871 }
872
873 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
874 finderClassName, finderMethodName, finderParams,
875 finderArgs, count);
876
877 return count.intValue();
878 }
879 catch (Exception e) {
880 throw processException(e);
881 }
882 finally {
883 closeSession(session);
884 }
885 }
886 else {
887 return ((Long)result).intValue();
888 }
889 }
890
891 public int countByVirtualHost(String virtualHost) throws SystemException {
892 boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
893 String finderClassName = LayoutSet.class.getName();
894 String finderMethodName = "countByVirtualHost";
895 String[] finderParams = new String[] { String.class.getName() };
896 Object[] finderArgs = new Object[] { virtualHost };
897
898 Object result = null;
899
900 if (finderClassNameCacheEnabled) {
901 result = FinderCacheUtil.getResult(finderClassName,
902 finderMethodName, finderParams, finderArgs, this);
903 }
904
905 if (result == null) {
906 Session session = null;
907
908 try {
909 session = openSession();
910
911 StringBuilder query = new StringBuilder();
912
913 query.append("SELECT COUNT(*) ");
914 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
915
916 if (virtualHost == null) {
917 query.append("virtualHost IS NULL");
918 }
919 else {
920 query.append("virtualHost = ?");
921 }
922
923 query.append(" ");
924
925 Query q = session.createQuery(query.toString());
926
927 QueryPos qPos = QueryPos.getInstance(q);
928
929 if (virtualHost != null) {
930 qPos.add(virtualHost);
931 }
932
933 Long count = null;
934
935 Iterator<Long> itr = q.list().iterator();
936
937 if (itr.hasNext()) {
938 count = itr.next();
939 }
940
941 if (count == null) {
942 count = new Long(0);
943 }
944
945 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
946 finderClassName, finderMethodName, finderParams,
947 finderArgs, count);
948
949 return count.intValue();
950 }
951 catch (Exception e) {
952 throw processException(e);
953 }
954 finally {
955 closeSession(session);
956 }
957 }
958 else {
959 return ((Long)result).intValue();
960 }
961 }
962
963 public int countByG_P(long groupId, boolean privateLayout)
964 throws SystemException {
965 boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
966 String finderClassName = LayoutSet.class.getName();
967 String finderMethodName = "countByG_P";
968 String[] finderParams = new String[] {
969 Long.class.getName(), Boolean.class.getName()
970 };
971 Object[] finderArgs = new Object[] {
972 new Long(groupId), Boolean.valueOf(privateLayout)
973 };
974
975 Object result = null;
976
977 if (finderClassNameCacheEnabled) {
978 result = FinderCacheUtil.getResult(finderClassName,
979 finderMethodName, finderParams, finderArgs, this);
980 }
981
982 if (result == null) {
983 Session session = null;
984
985 try {
986 session = openSession();
987
988 StringBuilder query = new StringBuilder();
989
990 query.append("SELECT COUNT(*) ");
991 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
992
993 query.append("groupId = ?");
994
995 query.append(" AND ");
996
997 query.append("privateLayout = ?");
998
999 query.append(" ");
1000
1001 Query q = session.createQuery(query.toString());
1002
1003 QueryPos qPos = QueryPos.getInstance(q);
1004
1005 qPos.add(groupId);
1006
1007 qPos.add(privateLayout);
1008
1009 Long count = null;
1010
1011 Iterator<Long> itr = q.list().iterator();
1012
1013 if (itr.hasNext()) {
1014 count = itr.next();
1015 }
1016
1017 if (count == null) {
1018 count = new Long(0);
1019 }
1020
1021 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1022 finderClassName, finderMethodName, finderParams,
1023 finderArgs, count);
1024
1025 return count.intValue();
1026 }
1027 catch (Exception e) {
1028 throw processException(e);
1029 }
1030 finally {
1031 closeSession(session);
1032 }
1033 }
1034 else {
1035 return ((Long)result).intValue();
1036 }
1037 }
1038
1039 public int countAll() throws SystemException {
1040 boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
1041 String finderClassName = LayoutSet.class.getName();
1042 String finderMethodName = "countAll";
1043 String[] finderParams = new String[] { };
1044 Object[] finderArgs = new Object[] { };
1045
1046 Object result = null;
1047
1048 if (finderClassNameCacheEnabled) {
1049 result = FinderCacheUtil.getResult(finderClassName,
1050 finderMethodName, finderParams, finderArgs, this);
1051 }
1052
1053 if (result == null) {
1054 Session session = null;
1055
1056 try {
1057 session = openSession();
1058
1059 Query q = session.createQuery(
1060 "SELECT COUNT(*) FROM com.liferay.portal.model.LayoutSet");
1061
1062 Long count = null;
1063
1064 Iterator<Long> itr = q.list().iterator();
1065
1066 if (itr.hasNext()) {
1067 count = itr.next();
1068 }
1069
1070 if (count == null) {
1071 count = new Long(0);
1072 }
1073
1074 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1075 finderClassName, finderMethodName, finderParams,
1076 finderArgs, count);
1077
1078 return count.intValue();
1079 }
1080 catch (Exception e) {
1081 throw processException(e);
1082 }
1083 finally {
1084 closeSession(session);
1085 }
1086 }
1087 else {
1088 return ((Long)result).intValue();
1089 }
1090 }
1091
1092 public void registerListener(ModelListener listener) {
1093 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1094
1095 listeners.add(listener);
1096
1097 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1098 }
1099
1100 public void unregisterListener(ModelListener listener) {
1101 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1102
1103 listeners.remove(listener);
1104
1105 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1106 }
1107
1108 public void afterPropertiesSet() {
1109 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1110 com.liferay.portal.util.PropsUtil.get(
1111 "value.object.listener.com.liferay.portal.model.LayoutSet")));
1112
1113 if (listenerClassNames.length > 0) {
1114 try {
1115 List<ModelListener> listeners = new ArrayList<ModelListener>();
1116
1117 for (String listenerClassName : listenerClassNames) {
1118 listeners.add((ModelListener)Class.forName(
1119 listenerClassName).newInstance());
1120 }
1121
1122 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1123 }
1124 catch (Exception e) {
1125 _log.error(e);
1126 }
1127 }
1128 }
1129
1130 private static Log _log = LogFactory.getLog(LayoutSetPersistenceImpl.class);
1131 private ModelListener[] _listeners = new ModelListener[0];
1132}