1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
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.annotation.BeanReference;
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.log.Log;
35  import com.liferay.portal.kernel.log.LogFactoryUtil;
36  import com.liferay.portal.kernel.util.GetterUtil;
37  import com.liferay.portal.kernel.util.OrderByComparator;
38  import com.liferay.portal.kernel.util.StringPool;
39  import com.liferay.portal.kernel.util.StringUtil;
40  import com.liferay.portal.model.LayoutSet;
41  import com.liferay.portal.model.ModelListener;
42  import com.liferay.portal.model.impl.LayoutSetImpl;
43  import com.liferay.portal.model.impl.LayoutSetModelImpl;
44  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
45  
46  import java.util.ArrayList;
47  import java.util.Collections;
48  import java.util.Iterator;
49  import java.util.List;
50  
51  /**
52   * <a href="LayoutSetPersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   */
57  public class LayoutSetPersistenceImpl extends BasePersistenceImpl
58      implements LayoutSetPersistence {
59      public LayoutSet create(long layoutSetId) {
60          LayoutSet layoutSet = new LayoutSetImpl();
61  
62          layoutSet.setNew(true);
63          layoutSet.setPrimaryKey(layoutSetId);
64  
65          return layoutSet;
66      }
67  
68      public LayoutSet remove(long layoutSetId)
69          throws NoSuchLayoutSetException, SystemException {
70          Session session = null;
71  
72          try {
73              session = openSession();
74  
75              LayoutSet layoutSet = (LayoutSet)session.get(LayoutSetImpl.class,
76                      new Long(layoutSetId));
77  
78              if (layoutSet == null) {
79                  if (_log.isWarnEnabled()) {
80                      _log.warn("No LayoutSet exists with the primary key " +
81                          layoutSetId);
82                  }
83  
84                  throw new NoSuchLayoutSetException(
85                      "No LayoutSet exists with the primary key " + layoutSetId);
86              }
87  
88              return remove(layoutSet);
89          }
90          catch (NoSuchLayoutSetException nsee) {
91              throw nsee;
92          }
93          catch (Exception e) {
94              throw processException(e);
95          }
96          finally {
97              closeSession(session);
98          }
99      }
100 
101     public LayoutSet remove(LayoutSet layoutSet) throws SystemException {
102         for (ModelListener listener : listeners) {
103             listener.onBeforeRemove(layoutSet);
104         }
105 
106         layoutSet = removeImpl(layoutSet);
107 
108         for (ModelListener listener : listeners) {
109             listener.onAfterRemove(layoutSet);
110         }
111 
112         return layoutSet;
113     }
114 
115     protected LayoutSet removeImpl(LayoutSet layoutSet)
116         throws SystemException {
117         Session session = null;
118 
119         try {
120             session = openSession();
121 
122             if (BatchSessionUtil.isEnabled()) {
123                 Object staleObject = session.get(LayoutSetImpl.class,
124                         layoutSet.getPrimaryKeyObj());
125 
126                 if (staleObject != null) {
127                     session.evict(staleObject);
128                 }
129             }
130 
131             session.delete(layoutSet);
132 
133             session.flush();
134 
135             return layoutSet;
136         }
137         catch (Exception e) {
138             throw processException(e);
139         }
140         finally {
141             closeSession(session);
142 
143             FinderCacheUtil.clearCache(LayoutSet.class.getName());
144         }
145     }
146 
147     /**
148      * @deprecated Use <code>update(LayoutSet layoutSet, boolean merge)</code>.
149      */
150     public LayoutSet update(LayoutSet layoutSet) throws SystemException {
151         if (_log.isWarnEnabled()) {
152             _log.warn(
153                 "Using the deprecated update(LayoutSet layoutSet) method. Use update(LayoutSet layoutSet, boolean merge) instead.");
154         }
155 
156         return update(layoutSet, false);
157     }
158 
159     /**
160      * Add, update, or merge, the entity. This method also calls the model
161      * listeners to trigger the proper events associated with adding, deleting,
162      * or updating an entity.
163      *
164      * @param        layoutSet the entity to add, update, or merge
165      * @param        merge boolean value for whether to merge the entity. The
166      *                default value is false. Setting merge to true is more
167      *                expensive and should only be true when layoutSet is
168      *                transient. See LEP-5473 for a detailed discussion of this
169      *                method.
170      * @return        true if the portlet can be displayed via Ajax
171      */
172     public LayoutSet update(LayoutSet layoutSet, boolean merge)
173         throws SystemException {
174         boolean isNew = layoutSet.isNew();
175 
176         for (ModelListener listener : listeners) {
177             if (isNew) {
178                 listener.onBeforeCreate(layoutSet);
179             }
180             else {
181                 listener.onBeforeUpdate(layoutSet);
182             }
183         }
184 
185         layoutSet = updateImpl(layoutSet, merge);
186 
187         for (ModelListener listener : listeners) {
188             if (isNew) {
189                 listener.onAfterCreate(layoutSet);
190             }
191             else {
192                 listener.onAfterUpdate(layoutSet);
193             }
194         }
195 
196         return layoutSet;
197     }
198 
199     public LayoutSet updateImpl(com.liferay.portal.model.LayoutSet layoutSet,
200         boolean merge) throws SystemException {
201         Session session = null;
202 
203         try {
204             session = openSession();
205 
206             BatchSessionUtil.update(session, layoutSet, merge);
207 
208             layoutSet.setNew(false);
209 
210             return layoutSet;
211         }
212         catch (Exception e) {
213             throw processException(e);
214         }
215         finally {
216             closeSession(session);
217 
218             FinderCacheUtil.clearCache(LayoutSet.class.getName());
219         }
220     }
221 
222     public LayoutSet findByPrimaryKey(long layoutSetId)
223         throws NoSuchLayoutSetException, SystemException {
224         LayoutSet layoutSet = fetchByPrimaryKey(layoutSetId);
225 
226         if (layoutSet == null) {
227             if (_log.isWarnEnabled()) {
228                 _log.warn("No LayoutSet exists with the primary key " +
229                     layoutSetId);
230             }
231 
232             throw new NoSuchLayoutSetException(
233                 "No LayoutSet exists with the primary key " + layoutSetId);
234         }
235 
236         return layoutSet;
237     }
238 
239     public LayoutSet fetchByPrimaryKey(long layoutSetId)
240         throws SystemException {
241         Session session = null;
242 
243         try {
244             session = openSession();
245 
246             return (LayoutSet)session.get(LayoutSetImpl.class,
247                 new Long(layoutSetId));
248         }
249         catch (Exception e) {
250             throw processException(e);
251         }
252         finally {
253             closeSession(session);
254         }
255     }
256 
257     public List<LayoutSet> findByGroupId(long groupId)
258         throws SystemException {
259         boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
260         String finderClassName = LayoutSet.class.getName();
261         String finderMethodName = "findByGroupId";
262         String[] finderParams = new String[] { Long.class.getName() };
263         Object[] finderArgs = new Object[] { new Long(groupId) };
264 
265         Object result = null;
266 
267         if (finderClassNameCacheEnabled) {
268             result = FinderCacheUtil.getResult(finderClassName,
269                     finderMethodName, finderParams, finderArgs, this);
270         }
271 
272         if (result == null) {
273             Session session = null;
274 
275             try {
276                 session = openSession();
277 
278                 StringBuilder query = new StringBuilder();
279 
280                 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
281 
282                 query.append("groupId = ?");
283 
284                 query.append(" ");
285 
286                 Query q = session.createQuery(query.toString());
287 
288                 QueryPos qPos = QueryPos.getInstance(q);
289 
290                 qPos.add(groupId);
291 
292                 List<LayoutSet> list = q.list();
293 
294                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
295                     finderClassName, finderMethodName, finderParams,
296                     finderArgs, list);
297 
298                 return list;
299             }
300             catch (Exception e) {
301                 throw processException(e);
302             }
303             finally {
304                 closeSession(session);
305             }
306         }
307         else {
308             return (List<LayoutSet>)result;
309         }
310     }
311 
312     public List<LayoutSet> findByGroupId(long groupId, int start, int end)
313         throws SystemException {
314         return findByGroupId(groupId, start, end, null);
315     }
316 
317     public List<LayoutSet> findByGroupId(long groupId, int start, int end,
318         OrderByComparator obc) throws SystemException {
319         boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
320         String finderClassName = LayoutSet.class.getName();
321         String finderMethodName = "findByGroupId";
322         String[] finderParams = new String[] {
323                 Long.class.getName(),
324                 
325                 "java.lang.Integer", "java.lang.Integer",
326                 "com.liferay.portal.kernel.util.OrderByComparator"
327             };
328         Object[] finderArgs = new Object[] {
329                 new Long(groupId),
330                 
331                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
332             };
333 
334         Object result = null;
335 
336         if (finderClassNameCacheEnabled) {
337             result = FinderCacheUtil.getResult(finderClassName,
338                     finderMethodName, finderParams, finderArgs, this);
339         }
340 
341         if (result == null) {
342             Session session = null;
343 
344             try {
345                 session = openSession();
346 
347                 StringBuilder query = new StringBuilder();
348 
349                 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
350 
351                 query.append("groupId = ?");
352 
353                 query.append(" ");
354 
355                 if (obc != null) {
356                     query.append("ORDER BY ");
357                     query.append(obc.getOrderBy());
358                 }
359 
360                 Query q = session.createQuery(query.toString());
361 
362                 QueryPos qPos = QueryPos.getInstance(q);
363 
364                 qPos.add(groupId);
365 
366                 List<LayoutSet> list = (List<LayoutSet>)QueryUtil.list(q,
367                         getDialect(), start, end);
368 
369                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
370                     finderClassName, finderMethodName, finderParams,
371                     finderArgs, list);
372 
373                 return list;
374             }
375             catch (Exception e) {
376                 throw processException(e);
377             }
378             finally {
379                 closeSession(session);
380             }
381         }
382         else {
383             return (List<LayoutSet>)result;
384         }
385     }
386 
387     public LayoutSet findByGroupId_First(long groupId, OrderByComparator obc)
388         throws NoSuchLayoutSetException, SystemException {
389         List<LayoutSet> list = findByGroupId(groupId, 0, 1, obc);
390 
391         if (list.size() == 0) {
392             StringBuilder msg = new StringBuilder();
393 
394             msg.append("No LayoutSet exists with the key {");
395 
396             msg.append("groupId=" + groupId);
397 
398             msg.append(StringPool.CLOSE_CURLY_BRACE);
399 
400             throw new NoSuchLayoutSetException(msg.toString());
401         }
402         else {
403             return list.get(0);
404         }
405     }
406 
407     public LayoutSet findByGroupId_Last(long groupId, OrderByComparator obc)
408         throws NoSuchLayoutSetException, SystemException {
409         int count = countByGroupId(groupId);
410 
411         List<LayoutSet> list = findByGroupId(groupId, count - 1, count, obc);
412 
413         if (list.size() == 0) {
414             StringBuilder msg = new StringBuilder();
415 
416             msg.append("No LayoutSet exists with the key {");
417 
418             msg.append("groupId=" + groupId);
419 
420             msg.append(StringPool.CLOSE_CURLY_BRACE);
421 
422             throw new NoSuchLayoutSetException(msg.toString());
423         }
424         else {
425             return list.get(0);
426         }
427     }
428 
429     public LayoutSet[] findByGroupId_PrevAndNext(long layoutSetId,
430         long groupId, OrderByComparator obc)
431         throws NoSuchLayoutSetException, SystemException {
432         LayoutSet layoutSet = findByPrimaryKey(layoutSetId);
433 
434         int count = countByGroupId(groupId);
435 
436         Session session = null;
437 
438         try {
439             session = openSession();
440 
441             StringBuilder query = new StringBuilder();
442 
443             query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
444 
445             query.append("groupId = ?");
446 
447             query.append(" ");
448 
449             if (obc != null) {
450                 query.append("ORDER BY ");
451                 query.append(obc.getOrderBy());
452             }
453 
454             Query q = session.createQuery(query.toString());
455 
456             QueryPos qPos = QueryPos.getInstance(q);
457 
458             qPos.add(groupId);
459 
460             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
461                     layoutSet);
462 
463             LayoutSet[] array = new LayoutSetImpl[3];
464 
465             array[0] = (LayoutSet)objArray[0];
466             array[1] = (LayoutSet)objArray[1];
467             array[2] = (LayoutSet)objArray[2];
468 
469             return array;
470         }
471         catch (Exception e) {
472             throw processException(e);
473         }
474         finally {
475             closeSession(session);
476         }
477     }
478 
479     public LayoutSet findByVirtualHost(String virtualHost)
480         throws NoSuchLayoutSetException, SystemException {
481         LayoutSet layoutSet = fetchByVirtualHost(virtualHost);
482 
483         if (layoutSet == null) {
484             StringBuilder msg = new StringBuilder();
485 
486             msg.append("No LayoutSet exists with the key {");
487 
488             msg.append("virtualHost=" + virtualHost);
489 
490             msg.append(StringPool.CLOSE_CURLY_BRACE);
491 
492             if (_log.isWarnEnabled()) {
493                 _log.warn(msg.toString());
494             }
495 
496             throw new NoSuchLayoutSetException(msg.toString());
497         }
498 
499         return layoutSet;
500     }
501 
502     public LayoutSet fetchByVirtualHost(String virtualHost)
503         throws SystemException {
504         boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
505         String finderClassName = LayoutSet.class.getName();
506         String finderMethodName = "fetchByVirtualHost";
507         String[] finderParams = new String[] { String.class.getName() };
508         Object[] finderArgs = new Object[] { virtualHost };
509 
510         Object result = null;
511 
512         if (finderClassNameCacheEnabled) {
513             result = FinderCacheUtil.getResult(finderClassName,
514                     finderMethodName, finderParams, finderArgs, this);
515         }
516 
517         if (result == null) {
518             Session session = null;
519 
520             try {
521                 session = openSession();
522 
523                 StringBuilder query = new StringBuilder();
524 
525                 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
526 
527                 if (virtualHost == null) {
528                     query.append("virtualHost IS NULL");
529                 }
530                 else {
531                     query.append("virtualHost = ?");
532                 }
533 
534                 query.append(" ");
535 
536                 Query q = session.createQuery(query.toString());
537 
538                 QueryPos qPos = QueryPos.getInstance(q);
539 
540                 if (virtualHost != null) {
541                     qPos.add(virtualHost);
542                 }
543 
544                 List<LayoutSet> list = q.list();
545 
546                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
547                     finderClassName, finderMethodName, finderParams,
548                     finderArgs, list);
549 
550                 if (list.size() == 0) {
551                     return null;
552                 }
553                 else {
554                     return list.get(0);
555                 }
556             }
557             catch (Exception e) {
558                 throw processException(e);
559             }
560             finally {
561                 closeSession(session);
562             }
563         }
564         else {
565             List<LayoutSet> list = (List<LayoutSet>)result;
566 
567             if (list.size() == 0) {
568                 return null;
569             }
570             else {
571                 return list.get(0);
572             }
573         }
574     }
575 
576     public LayoutSet findByG_P(long groupId, boolean privateLayout)
577         throws NoSuchLayoutSetException, SystemException {
578         LayoutSet layoutSet = fetchByG_P(groupId, privateLayout);
579 
580         if (layoutSet == null) {
581             StringBuilder msg = new StringBuilder();
582 
583             msg.append("No LayoutSet exists with the key {");
584 
585             msg.append("groupId=" + groupId);
586 
587             msg.append(", ");
588             msg.append("privateLayout=" + privateLayout);
589 
590             msg.append(StringPool.CLOSE_CURLY_BRACE);
591 
592             if (_log.isWarnEnabled()) {
593                 _log.warn(msg.toString());
594             }
595 
596             throw new NoSuchLayoutSetException(msg.toString());
597         }
598 
599         return layoutSet;
600     }
601 
602     public LayoutSet fetchByG_P(long groupId, boolean privateLayout)
603         throws SystemException {
604         boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
605         String finderClassName = LayoutSet.class.getName();
606         String finderMethodName = "fetchByG_P";
607         String[] finderParams = new String[] {
608                 Long.class.getName(), Boolean.class.getName()
609             };
610         Object[] finderArgs = new Object[] {
611                 new Long(groupId), Boolean.valueOf(privateLayout)
612             };
613 
614         Object result = null;
615 
616         if (finderClassNameCacheEnabled) {
617             result = FinderCacheUtil.getResult(finderClassName,
618                     finderMethodName, finderParams, finderArgs, this);
619         }
620 
621         if (result == null) {
622             Session session = null;
623 
624             try {
625                 session = openSession();
626 
627                 StringBuilder query = new StringBuilder();
628 
629                 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
630 
631                 query.append("groupId = ?");
632 
633                 query.append(" AND ");
634 
635                 query.append("privateLayout = ?");
636 
637                 query.append(" ");
638 
639                 Query q = session.createQuery(query.toString());
640 
641                 QueryPos qPos = QueryPos.getInstance(q);
642 
643                 qPos.add(groupId);
644 
645                 qPos.add(privateLayout);
646 
647                 List<LayoutSet> list = q.list();
648 
649                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
650                     finderClassName, finderMethodName, finderParams,
651                     finderArgs, list);
652 
653                 if (list.size() == 0) {
654                     return null;
655                 }
656                 else {
657                     return list.get(0);
658                 }
659             }
660             catch (Exception e) {
661                 throw processException(e);
662             }
663             finally {
664                 closeSession(session);
665             }
666         }
667         else {
668             List<LayoutSet> list = (List<LayoutSet>)result;
669 
670             if (list.size() == 0) {
671                 return null;
672             }
673             else {
674                 return list.get(0);
675             }
676         }
677     }
678 
679     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
680         throws SystemException {
681         Session session = null;
682 
683         try {
684             session = openSession();
685 
686             dynamicQuery.compile(session);
687 
688             return dynamicQuery.list();
689         }
690         catch (Exception e) {
691             throw processException(e);
692         }
693         finally {
694             closeSession(session);
695         }
696     }
697 
698     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
699         int start, int end) throws SystemException {
700         Session session = null;
701 
702         try {
703             session = openSession();
704 
705             dynamicQuery.setLimit(start, end);
706 
707             dynamicQuery.compile(session);
708 
709             return dynamicQuery.list();
710         }
711         catch (Exception e) {
712             throw processException(e);
713         }
714         finally {
715             closeSession(session);
716         }
717     }
718 
719     public List<LayoutSet> findAll() throws SystemException {
720         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
721     }
722 
723     public List<LayoutSet> findAll(int start, int end)
724         throws SystemException {
725         return findAll(start, end, null);
726     }
727 
728     public List<LayoutSet> findAll(int start, int end, OrderByComparator obc)
729         throws SystemException {
730         boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
731         String finderClassName = LayoutSet.class.getName();
732         String finderMethodName = "findAll";
733         String[] finderParams = new String[] {
734                 "java.lang.Integer", "java.lang.Integer",
735                 "com.liferay.portal.kernel.util.OrderByComparator"
736             };
737         Object[] finderArgs = new Object[] {
738                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
739             };
740 
741         Object result = null;
742 
743         if (finderClassNameCacheEnabled) {
744             result = FinderCacheUtil.getResult(finderClassName,
745                     finderMethodName, finderParams, finderArgs, this);
746         }
747 
748         if (result == null) {
749             Session session = null;
750 
751             try {
752                 session = openSession();
753 
754                 StringBuilder query = new StringBuilder();
755 
756                 query.append("FROM com.liferay.portal.model.LayoutSet ");
757 
758                 if (obc != null) {
759                     query.append("ORDER BY ");
760                     query.append(obc.getOrderBy());
761                 }
762 
763                 Query q = session.createQuery(query.toString());
764 
765                 List<LayoutSet> list = null;
766 
767                 if (obc == null) {
768                     list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
769                             start, end, false);
770 
771                     Collections.sort(list);
772                 }
773                 else {
774                     list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
775                             start, end);
776                 }
777 
778                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
779                     finderClassName, finderMethodName, finderParams,
780                     finderArgs, list);
781 
782                 return list;
783             }
784             catch (Exception e) {
785                 throw processException(e);
786             }
787             finally {
788                 closeSession(session);
789             }
790         }
791         else {
792             return (List<LayoutSet>)result;
793         }
794     }
795 
796     public void removeByGroupId(long groupId) throws SystemException {
797         for (LayoutSet layoutSet : findByGroupId(groupId)) {
798             remove(layoutSet);
799         }
800     }
801 
802     public void removeByVirtualHost(String virtualHost)
803         throws NoSuchLayoutSetException, SystemException {
804         LayoutSet layoutSet = findByVirtualHost(virtualHost);
805 
806         remove(layoutSet);
807     }
808 
809     public void removeByG_P(long groupId, boolean privateLayout)
810         throws NoSuchLayoutSetException, SystemException {
811         LayoutSet layoutSet = findByG_P(groupId, privateLayout);
812 
813         remove(layoutSet);
814     }
815 
816     public void removeAll() throws SystemException {
817         for (LayoutSet layoutSet : findAll()) {
818             remove(layoutSet);
819         }
820     }
821 
822     public int countByGroupId(long groupId) throws SystemException {
823         boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
824         String finderClassName = LayoutSet.class.getName();
825         String finderMethodName = "countByGroupId";
826         String[] finderParams = new String[] { Long.class.getName() };
827         Object[] finderArgs = new Object[] { new Long(groupId) };
828 
829         Object result = null;
830 
831         if (finderClassNameCacheEnabled) {
832             result = FinderCacheUtil.getResult(finderClassName,
833                     finderMethodName, finderParams, finderArgs, this);
834         }
835 
836         if (result == null) {
837             Session session = null;
838 
839             try {
840                 session = openSession();
841 
842                 StringBuilder query = new StringBuilder();
843 
844                 query.append("SELECT COUNT(*) ");
845                 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
846 
847                 query.append("groupId = ?");
848 
849                 query.append(" ");
850 
851                 Query q = session.createQuery(query.toString());
852 
853                 QueryPos qPos = QueryPos.getInstance(q);
854 
855                 qPos.add(groupId);
856 
857                 Long count = null;
858 
859                 Iterator<Long> itr = q.list().iterator();
860 
861                 if (itr.hasNext()) {
862                     count = itr.next();
863                 }
864 
865                 if (count == null) {
866                     count = new Long(0);
867                 }
868 
869                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
870                     finderClassName, finderMethodName, finderParams,
871                     finderArgs, count);
872 
873                 return count.intValue();
874             }
875             catch (Exception e) {
876                 throw processException(e);
877             }
878             finally {
879                 closeSession(session);
880             }
881         }
882         else {
883             return ((Long)result).intValue();
884         }
885     }
886 
887     public int countByVirtualHost(String virtualHost) throws SystemException {
888         boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
889         String finderClassName = LayoutSet.class.getName();
890         String finderMethodName = "countByVirtualHost";
891         String[] finderParams = new String[] { String.class.getName() };
892         Object[] finderArgs = new Object[] { virtualHost };
893 
894         Object result = null;
895 
896         if (finderClassNameCacheEnabled) {
897             result = FinderCacheUtil.getResult(finderClassName,
898                     finderMethodName, finderParams, finderArgs, this);
899         }
900 
901         if (result == null) {
902             Session session = null;
903 
904             try {
905                 session = openSession();
906 
907                 StringBuilder query = new StringBuilder();
908 
909                 query.append("SELECT COUNT(*) ");
910                 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
911 
912                 if (virtualHost == null) {
913                     query.append("virtualHost IS NULL");
914                 }
915                 else {
916                     query.append("virtualHost = ?");
917                 }
918 
919                 query.append(" ");
920 
921                 Query q = session.createQuery(query.toString());
922 
923                 QueryPos qPos = QueryPos.getInstance(q);
924 
925                 if (virtualHost != null) {
926                     qPos.add(virtualHost);
927                 }
928 
929                 Long count = null;
930 
931                 Iterator<Long> itr = q.list().iterator();
932 
933                 if (itr.hasNext()) {
934                     count = itr.next();
935                 }
936 
937                 if (count == null) {
938                     count = new Long(0);
939                 }
940 
941                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
942                     finderClassName, finderMethodName, finderParams,
943                     finderArgs, count);
944 
945                 return count.intValue();
946             }
947             catch (Exception e) {
948                 throw processException(e);
949             }
950             finally {
951                 closeSession(session);
952             }
953         }
954         else {
955             return ((Long)result).intValue();
956         }
957     }
958 
959     public int countByG_P(long groupId, boolean privateLayout)
960         throws SystemException {
961         boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
962         String finderClassName = LayoutSet.class.getName();
963         String finderMethodName = "countByG_P";
964         String[] finderParams = new String[] {
965                 Long.class.getName(), Boolean.class.getName()
966             };
967         Object[] finderArgs = new Object[] {
968                 new Long(groupId), Boolean.valueOf(privateLayout)
969             };
970 
971         Object result = null;
972 
973         if (finderClassNameCacheEnabled) {
974             result = FinderCacheUtil.getResult(finderClassName,
975                     finderMethodName, finderParams, finderArgs, this);
976         }
977 
978         if (result == null) {
979             Session session = null;
980 
981             try {
982                 session = openSession();
983 
984                 StringBuilder query = new StringBuilder();
985 
986                 query.append("SELECT COUNT(*) ");
987                 query.append("FROM com.liferay.portal.model.LayoutSet WHERE ");
988 
989                 query.append("groupId = ?");
990 
991                 query.append(" AND ");
992 
993                 query.append("privateLayout = ?");
994 
995                 query.append(" ");
996 
997                 Query q = session.createQuery(query.toString());
998 
999                 QueryPos qPos = QueryPos.getInstance(q);
1000
1001                qPos.add(groupId);
1002
1003                qPos.add(privateLayout);
1004
1005                Long count = null;
1006
1007                Iterator<Long> itr = q.list().iterator();
1008
1009                if (itr.hasNext()) {
1010                    count = itr.next();
1011                }
1012
1013                if (count == null) {
1014                    count = new Long(0);
1015                }
1016
1017                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1018                    finderClassName, finderMethodName, finderParams,
1019                    finderArgs, count);
1020
1021                return count.intValue();
1022            }
1023            catch (Exception e) {
1024                throw processException(e);
1025            }
1026            finally {
1027                closeSession(session);
1028            }
1029        }
1030        else {
1031            return ((Long)result).intValue();
1032        }
1033    }
1034
1035    public int countAll() throws SystemException {
1036        boolean finderClassNameCacheEnabled = LayoutSetModelImpl.CACHE_ENABLED;
1037        String finderClassName = LayoutSet.class.getName();
1038        String finderMethodName = "countAll";
1039        String[] finderParams = new String[] {  };
1040        Object[] finderArgs = new Object[] {  };
1041
1042        Object result = null;
1043
1044        if (finderClassNameCacheEnabled) {
1045            result = FinderCacheUtil.getResult(finderClassName,
1046                    finderMethodName, finderParams, finderArgs, this);
1047        }
1048
1049        if (result == null) {
1050            Session session = null;
1051
1052            try {
1053                session = openSession();
1054
1055                Query q = session.createQuery(
1056                        "SELECT COUNT(*) FROM com.liferay.portal.model.LayoutSet");
1057
1058                Long count = null;
1059
1060                Iterator<Long> itr = q.list().iterator();
1061
1062                if (itr.hasNext()) {
1063                    count = itr.next();
1064                }
1065
1066                if (count == null) {
1067                    count = new Long(0);
1068                }
1069
1070                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1071                    finderClassName, finderMethodName, finderParams,
1072                    finderArgs, count);
1073
1074                return count.intValue();
1075            }
1076            catch (Exception e) {
1077                throw processException(e);
1078            }
1079            finally {
1080                closeSession(session);
1081            }
1082        }
1083        else {
1084            return ((Long)result).intValue();
1085        }
1086    }
1087
1088    public void afterPropertiesSet() {
1089        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1090                    com.liferay.portal.util.PropsUtil.get(
1091                        "value.object.listener.com.liferay.portal.model.LayoutSet")));
1092
1093        if (listenerClassNames.length > 0) {
1094            try {
1095                List<ModelListener> listenersList = new ArrayList<ModelListener>();
1096
1097                for (String listenerClassName : listenerClassNames) {
1098                    listenersList.add((ModelListener)Class.forName(
1099                            listenerClassName).newInstance());
1100                }
1101
1102                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1103            }
1104            catch (Exception e) {
1105                _log.error(e);
1106            }
1107        }
1108    }
1109
1110    @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
1111    protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1112    @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
1113    protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1114    @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
1115    protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1116    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1117    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1118    @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
1119    protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1120    @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
1121    protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1122    @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
1123    protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1124    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1125    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1126    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
1127    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1128    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
1129    protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1130    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
1131    protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1132    @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
1133    protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1134    @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
1135    protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1136    @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
1137    protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1138    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
1139    protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1140    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
1141    protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1142    @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
1143    protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1144    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
1145    protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1146    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
1147    protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1148    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
1149    protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1150    @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
1151    protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1152    @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
1153    protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1154    @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
1155    protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1156    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
1157    protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1158    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
1159    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1160    @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
1161    protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1162    @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
1163    protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1164    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1165    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1166    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
1167    protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1168    @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
1169    protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1170    @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
1171    protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1172    @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
1173    protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1174    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1175    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1176    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1177    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1178    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
1179    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1180    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
1181    protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1182    @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
1183    protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1184    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
1185    protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1186    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
1187    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1188    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
1189    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1190    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
1191    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1192    private static Log _log = LogFactoryUtil.getLog(LayoutSetPersistenceImpl.class);
1193}