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