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