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