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.NoSuchLayoutException;
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.Layout;
41  import com.liferay.portal.model.ModelListener;
42  import com.liferay.portal.model.impl.LayoutImpl;
43  import com.liferay.portal.model.impl.LayoutModelImpl;
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="LayoutPersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   */
57  public class LayoutPersistenceImpl extends BasePersistenceImpl
58      implements LayoutPersistence {
59      public Layout create(long plid) {
60          Layout layout = new LayoutImpl();
61  
62          layout.setNew(true);
63          layout.setPrimaryKey(plid);
64  
65          return layout;
66      }
67  
68      public Layout remove(long plid)
69          throws NoSuchLayoutException, SystemException {
70          Session session = null;
71  
72          try {
73              session = openSession();
74  
75              Layout layout = (Layout)session.get(LayoutImpl.class, new Long(plid));
76  
77              if (layout == null) {
78                  if (_log.isWarnEnabled()) {
79                      _log.warn("No Layout exists with the primary key " + plid);
80                  }
81  
82                  throw new NoSuchLayoutException(
83                      "No Layout exists with the primary key " + plid);
84              }
85  
86              return remove(layout);
87          }
88          catch (NoSuchLayoutException nsee) {
89              throw nsee;
90          }
91          catch (Exception e) {
92              throw processException(e);
93          }
94          finally {
95              closeSession(session);
96          }
97      }
98  
99      public Layout remove(Layout layout) throws SystemException {
100         for (ModelListener listener : listeners) {
101             listener.onBeforeRemove(layout);
102         }
103 
104         layout = removeImpl(layout);
105 
106         for (ModelListener listener : listeners) {
107             listener.onAfterRemove(layout);
108         }
109 
110         return layout;
111     }
112 
113     protected Layout removeImpl(Layout layout) throws SystemException {
114         Session session = null;
115 
116         try {
117             session = openSession();
118 
119             if (BatchSessionUtil.isEnabled()) {
120                 Object staleObject = session.get(LayoutImpl.class,
121                         layout.getPrimaryKeyObj());
122 
123                 if (staleObject != null) {
124                     session.evict(staleObject);
125                 }
126             }
127 
128             session.delete(layout);
129 
130             session.flush();
131 
132             return layout;
133         }
134         catch (Exception e) {
135             throw processException(e);
136         }
137         finally {
138             closeSession(session);
139 
140             FinderCacheUtil.clearCache(Layout.class.getName());
141         }
142     }
143 
144     /**
145      * @deprecated Use <code>update(Layout layout, boolean merge)</code>.
146      */
147     public Layout update(Layout layout) throws SystemException {
148         if (_log.isWarnEnabled()) {
149             _log.warn(
150                 "Using the deprecated update(Layout layout) method. Use update(Layout layout, boolean merge) instead.");
151         }
152 
153         return update(layout, false);
154     }
155 
156     /**
157      * Add, update, or merge, the entity. This method also calls the model
158      * listeners to trigger the proper events associated with adding, deleting,
159      * or updating an entity.
160      *
161      * @param        layout the entity to add, update, or merge
162      * @param        merge boolean value for whether to merge the entity. The
163      *                default value is false. Setting merge to true is more
164      *                expensive and should only be true when layout is
165      *                transient. See LEP-5473 for a detailed discussion of this
166      *                method.
167      * @return        true if the portlet can be displayed via Ajax
168      */
169     public Layout update(Layout layout, boolean merge)
170         throws SystemException {
171         boolean isNew = layout.isNew();
172 
173         for (ModelListener listener : listeners) {
174             if (isNew) {
175                 listener.onBeforeCreate(layout);
176             }
177             else {
178                 listener.onBeforeUpdate(layout);
179             }
180         }
181 
182         layout = updateImpl(layout, merge);
183 
184         for (ModelListener listener : listeners) {
185             if (isNew) {
186                 listener.onAfterCreate(layout);
187             }
188             else {
189                 listener.onAfterUpdate(layout);
190             }
191         }
192 
193         return layout;
194     }
195 
196     public Layout updateImpl(com.liferay.portal.model.Layout layout,
197         boolean merge) throws SystemException {
198         Session session = null;
199 
200         try {
201             session = openSession();
202 
203             BatchSessionUtil.update(session, layout, merge);
204 
205             layout.setNew(false);
206 
207             return layout;
208         }
209         catch (Exception e) {
210             throw processException(e);
211         }
212         finally {
213             closeSession(session);
214 
215             FinderCacheUtil.clearCache(Layout.class.getName());
216         }
217     }
218 
219     public Layout findByPrimaryKey(long plid)
220         throws NoSuchLayoutException, SystemException {
221         Layout layout = fetchByPrimaryKey(plid);
222 
223         if (layout == null) {
224             if (_log.isWarnEnabled()) {
225                 _log.warn("No Layout exists with the primary key " + plid);
226             }
227 
228             throw new NoSuchLayoutException(
229                 "No Layout exists with the primary key " + plid);
230         }
231 
232         return layout;
233     }
234 
235     public Layout fetchByPrimaryKey(long plid) throws SystemException {
236         Session session = null;
237 
238         try {
239             session = openSession();
240 
241             return (Layout)session.get(LayoutImpl.class, new Long(plid));
242         }
243         catch (Exception e) {
244             throw processException(e);
245         }
246         finally {
247             closeSession(session);
248         }
249     }
250 
251     public List<Layout> findByGroupId(long groupId) throws SystemException {
252         boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
253         String finderClassName = Layout.class.getName();
254         String finderMethodName = "findByGroupId";
255         String[] finderParams = new String[] { Long.class.getName() };
256         Object[] finderArgs = new Object[] { new Long(groupId) };
257 
258         Object result = null;
259 
260         if (finderClassNameCacheEnabled) {
261             result = FinderCacheUtil.getResult(finderClassName,
262                     finderMethodName, finderParams, finderArgs, this);
263         }
264 
265         if (result == null) {
266             Session session = null;
267 
268             try {
269                 session = openSession();
270 
271                 StringBuilder query = new StringBuilder();
272 
273                 query.append("FROM com.liferay.portal.model.Layout WHERE ");
274 
275                 query.append("groupId = ?");
276 
277                 query.append(" ");
278 
279                 query.append("ORDER BY ");
280 
281                 query.append("parentLayoutId ASC, ");
282                 query.append("priority ASC");
283 
284                 Query q = session.createQuery(query.toString());
285 
286                 QueryPos qPos = QueryPos.getInstance(q);
287 
288                 qPos.add(groupId);
289 
290                 List<Layout> list = q.list();
291 
292                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
293                     finderClassName, finderMethodName, finderParams,
294                     finderArgs, list);
295 
296                 return list;
297             }
298             catch (Exception e) {
299                 throw processException(e);
300             }
301             finally {
302                 closeSession(session);
303             }
304         }
305         else {
306             return (List<Layout>)result;
307         }
308     }
309 
310     public List<Layout> findByGroupId(long groupId, int start, int end)
311         throws SystemException {
312         return findByGroupId(groupId, start, end, null);
313     }
314 
315     public List<Layout> findByGroupId(long groupId, int start, int end,
316         OrderByComparator obc) throws SystemException {
317         boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
318         String finderClassName = Layout.class.getName();
319         String finderMethodName = "findByGroupId";
320         String[] finderParams = new String[] {
321                 Long.class.getName(),
322                 
323                 "java.lang.Integer", "java.lang.Integer",
324                 "com.liferay.portal.kernel.util.OrderByComparator"
325             };
326         Object[] finderArgs = new Object[] {
327                 new Long(groupId),
328                 
329                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
330             };
331 
332         Object result = null;
333 
334         if (finderClassNameCacheEnabled) {
335             result = FinderCacheUtil.getResult(finderClassName,
336                     finderMethodName, finderParams, finderArgs, this);
337         }
338 
339         if (result == null) {
340             Session session = null;
341 
342             try {
343                 session = openSession();
344 
345                 StringBuilder query = new StringBuilder();
346 
347                 query.append("FROM com.liferay.portal.model.Layout WHERE ");
348 
349                 query.append("groupId = ?");
350 
351                 query.append(" ");
352 
353                 if (obc != null) {
354                     query.append("ORDER BY ");
355                     query.append(obc.getOrderBy());
356                 }
357 
358                 else {
359                     query.append("ORDER BY ");
360 
361                     query.append("parentLayoutId ASC, ");
362                     query.append("priority ASC");
363                 }
364 
365                 Query q = session.createQuery(query.toString());
366 
367                 QueryPos qPos = QueryPos.getInstance(q);
368 
369                 qPos.add(groupId);
370 
371                 List<Layout> list = (List<Layout>)QueryUtil.list(q,
372                         getDialect(), start, end);
373 
374                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
375                     finderClassName, finderMethodName, finderParams,
376                     finderArgs, list);
377 
378                 return list;
379             }
380             catch (Exception e) {
381                 throw processException(e);
382             }
383             finally {
384                 closeSession(session);
385             }
386         }
387         else {
388             return (List<Layout>)result;
389         }
390     }
391 
392     public Layout findByGroupId_First(long groupId, OrderByComparator obc)
393         throws NoSuchLayoutException, SystemException {
394         List<Layout> list = findByGroupId(groupId, 0, 1, obc);
395 
396         if (list.size() == 0) {
397             StringBuilder msg = new StringBuilder();
398 
399             msg.append("No Layout exists with the key {");
400 
401             msg.append("groupId=" + groupId);
402 
403             msg.append(StringPool.CLOSE_CURLY_BRACE);
404 
405             throw new NoSuchLayoutException(msg.toString());
406         }
407         else {
408             return list.get(0);
409         }
410     }
411 
412     public Layout findByGroupId_Last(long groupId, OrderByComparator obc)
413         throws NoSuchLayoutException, SystemException {
414         int count = countByGroupId(groupId);
415 
416         List<Layout> list = findByGroupId(groupId, count - 1, count, obc);
417 
418         if (list.size() == 0) {
419             StringBuilder msg = new StringBuilder();
420 
421             msg.append("No Layout exists with the key {");
422 
423             msg.append("groupId=" + groupId);
424 
425             msg.append(StringPool.CLOSE_CURLY_BRACE);
426 
427             throw new NoSuchLayoutException(msg.toString());
428         }
429         else {
430             return list.get(0);
431         }
432     }
433 
434     public Layout[] findByGroupId_PrevAndNext(long plid, long groupId,
435         OrderByComparator obc) throws NoSuchLayoutException, SystemException {
436         Layout layout = findByPrimaryKey(plid);
437 
438         int count = countByGroupId(groupId);
439 
440         Session session = null;
441 
442         try {
443             session = openSession();
444 
445             StringBuilder query = new StringBuilder();
446 
447             query.append("FROM com.liferay.portal.model.Layout WHERE ");
448 
449             query.append("groupId = ?");
450 
451             query.append(" ");
452 
453             if (obc != null) {
454                 query.append("ORDER BY ");
455                 query.append(obc.getOrderBy());
456             }
457 
458             else {
459                 query.append("ORDER BY ");
460 
461                 query.append("parentLayoutId ASC, ");
462                 query.append("priority ASC");
463             }
464 
465             Query q = session.createQuery(query.toString());
466 
467             QueryPos qPos = QueryPos.getInstance(q);
468 
469             qPos.add(groupId);
470 
471             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, layout);
472 
473             Layout[] array = new LayoutImpl[3];
474 
475             array[0] = (Layout)objArray[0];
476             array[1] = (Layout)objArray[1];
477             array[2] = (Layout)objArray[2];
478 
479             return array;
480         }
481         catch (Exception e) {
482             throw processException(e);
483         }
484         finally {
485             closeSession(session);
486         }
487     }
488 
489     public List<Layout> findByCompanyId(long companyId)
490         throws SystemException {
491         boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
492         String finderClassName = Layout.class.getName();
493         String finderMethodName = "findByCompanyId";
494         String[] finderParams = new String[] { Long.class.getName() };
495         Object[] finderArgs = new Object[] { new Long(companyId) };
496 
497         Object result = null;
498 
499         if (finderClassNameCacheEnabled) {
500             result = FinderCacheUtil.getResult(finderClassName,
501                     finderMethodName, finderParams, finderArgs, this);
502         }
503 
504         if (result == null) {
505             Session session = null;
506 
507             try {
508                 session = openSession();
509 
510                 StringBuilder query = new StringBuilder();
511 
512                 query.append("FROM com.liferay.portal.model.Layout WHERE ");
513 
514                 query.append("companyId = ?");
515 
516                 query.append(" ");
517 
518                 query.append("ORDER BY ");
519 
520                 query.append("parentLayoutId ASC, ");
521                 query.append("priority ASC");
522 
523                 Query q = session.createQuery(query.toString());
524 
525                 QueryPos qPos = QueryPos.getInstance(q);
526 
527                 qPos.add(companyId);
528 
529                 List<Layout> list = q.list();
530 
531                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
532                     finderClassName, finderMethodName, finderParams,
533                     finderArgs, list);
534 
535                 return list;
536             }
537             catch (Exception e) {
538                 throw processException(e);
539             }
540             finally {
541                 closeSession(session);
542             }
543         }
544         else {
545             return (List<Layout>)result;
546         }
547     }
548 
549     public List<Layout> findByCompanyId(long companyId, int start, int end)
550         throws SystemException {
551         return findByCompanyId(companyId, start, end, null);
552     }
553 
554     public List<Layout> findByCompanyId(long companyId, int start, int end,
555         OrderByComparator obc) throws SystemException {
556         boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
557         String finderClassName = Layout.class.getName();
558         String finderMethodName = "findByCompanyId";
559         String[] finderParams = new String[] {
560                 Long.class.getName(),
561                 
562                 "java.lang.Integer", "java.lang.Integer",
563                 "com.liferay.portal.kernel.util.OrderByComparator"
564             };
565         Object[] finderArgs = new Object[] {
566                 new Long(companyId),
567                 
568                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
569             };
570 
571         Object result = null;
572 
573         if (finderClassNameCacheEnabled) {
574             result = FinderCacheUtil.getResult(finderClassName,
575                     finderMethodName, finderParams, finderArgs, this);
576         }
577 
578         if (result == null) {
579             Session session = null;
580 
581             try {
582                 session = openSession();
583 
584                 StringBuilder query = new StringBuilder();
585 
586                 query.append("FROM com.liferay.portal.model.Layout WHERE ");
587 
588                 query.append("companyId = ?");
589 
590                 query.append(" ");
591 
592                 if (obc != null) {
593                     query.append("ORDER BY ");
594                     query.append(obc.getOrderBy());
595                 }
596 
597                 else {
598                     query.append("ORDER BY ");
599 
600                     query.append("parentLayoutId ASC, ");
601                     query.append("priority ASC");
602                 }
603 
604                 Query q = session.createQuery(query.toString());
605 
606                 QueryPos qPos = QueryPos.getInstance(q);
607 
608                 qPos.add(companyId);
609 
610                 List<Layout> list = (List<Layout>)QueryUtil.list(q,
611                         getDialect(), start, end);
612 
613                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
614                     finderClassName, finderMethodName, finderParams,
615                     finderArgs, list);
616 
617                 return list;
618             }
619             catch (Exception e) {
620                 throw processException(e);
621             }
622             finally {
623                 closeSession(session);
624             }
625         }
626         else {
627             return (List<Layout>)result;
628         }
629     }
630 
631     public Layout findByCompanyId_First(long companyId, OrderByComparator obc)
632         throws NoSuchLayoutException, SystemException {
633         List<Layout> list = findByCompanyId(companyId, 0, 1, obc);
634 
635         if (list.size() == 0) {
636             StringBuilder msg = new StringBuilder();
637 
638             msg.append("No Layout exists with the key {");
639 
640             msg.append("companyId=" + companyId);
641 
642             msg.append(StringPool.CLOSE_CURLY_BRACE);
643 
644             throw new NoSuchLayoutException(msg.toString());
645         }
646         else {
647             return list.get(0);
648         }
649     }
650 
651     public Layout findByCompanyId_Last(long companyId, OrderByComparator obc)
652         throws NoSuchLayoutException, SystemException {
653         int count = countByCompanyId(companyId);
654 
655         List<Layout> list = findByCompanyId(companyId, count - 1, count, obc);
656 
657         if (list.size() == 0) {
658             StringBuilder msg = new StringBuilder();
659 
660             msg.append("No Layout exists with the key {");
661 
662             msg.append("companyId=" + companyId);
663 
664             msg.append(StringPool.CLOSE_CURLY_BRACE);
665 
666             throw new NoSuchLayoutException(msg.toString());
667         }
668         else {
669             return list.get(0);
670         }
671     }
672 
673     public Layout[] findByCompanyId_PrevAndNext(long plid, long companyId,
674         OrderByComparator obc) throws NoSuchLayoutException, SystemException {
675         Layout layout = findByPrimaryKey(plid);
676 
677         int count = countByCompanyId(companyId);
678 
679         Session session = null;
680 
681         try {
682             session = openSession();
683 
684             StringBuilder query = new StringBuilder();
685 
686             query.append("FROM com.liferay.portal.model.Layout WHERE ");
687 
688             query.append("companyId = ?");
689 
690             query.append(" ");
691 
692             if (obc != null) {
693                 query.append("ORDER BY ");
694                 query.append(obc.getOrderBy());
695             }
696 
697             else {
698                 query.append("ORDER BY ");
699 
700                 query.append("parentLayoutId ASC, ");
701                 query.append("priority ASC");
702             }
703 
704             Query q = session.createQuery(query.toString());
705 
706             QueryPos qPos = QueryPos.getInstance(q);
707 
708             qPos.add(companyId);
709 
710             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, layout);
711 
712             Layout[] array = new LayoutImpl[3];
713 
714             array[0] = (Layout)objArray[0];
715             array[1] = (Layout)objArray[1];
716             array[2] = (Layout)objArray[2];
717 
718             return array;
719         }
720         catch (Exception e) {
721             throw processException(e);
722         }
723         finally {
724             closeSession(session);
725         }
726     }
727 
728     public Layout findByDLFolderId(long dlFolderId)
729         throws NoSuchLayoutException, SystemException {
730         Layout layout = fetchByDLFolderId(dlFolderId);
731 
732         if (layout == null) {
733             StringBuilder msg = new StringBuilder();
734 
735             msg.append("No Layout exists with the key {");
736 
737             msg.append("dlFolderId=" + dlFolderId);
738 
739             msg.append(StringPool.CLOSE_CURLY_BRACE);
740 
741             if (_log.isWarnEnabled()) {
742                 _log.warn(msg.toString());
743             }
744 
745             throw new NoSuchLayoutException(msg.toString());
746         }
747 
748         return layout;
749     }
750 
751     public Layout fetchByDLFolderId(long dlFolderId) throws SystemException {
752         boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
753         String finderClassName = Layout.class.getName();
754         String finderMethodName = "fetchByDLFolderId";
755         String[] finderParams = new String[] { Long.class.getName() };
756         Object[] finderArgs = new Object[] { new Long(dlFolderId) };
757 
758         Object result = null;
759 
760         if (finderClassNameCacheEnabled) {
761             result = FinderCacheUtil.getResult(finderClassName,
762                     finderMethodName, finderParams, finderArgs, this);
763         }
764 
765         if (result == null) {
766             Session session = null;
767 
768             try {
769                 session = openSession();
770 
771                 StringBuilder query = new StringBuilder();
772 
773                 query.append("FROM com.liferay.portal.model.Layout WHERE ");
774 
775                 query.append("dlFolderId = ?");
776 
777                 query.append(" ");
778 
779                 query.append("ORDER BY ");
780 
781                 query.append("parentLayoutId ASC, ");
782                 query.append("priority ASC");
783 
784                 Query q = session.createQuery(query.toString());
785 
786                 QueryPos qPos = QueryPos.getInstance(q);
787 
788                 qPos.add(dlFolderId);
789 
790                 List<Layout> list = q.list();
791 
792                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
793                     finderClassName, finderMethodName, finderParams,
794                     finderArgs, list);
795 
796                 if (list.size() == 0) {
797                     return null;
798                 }
799                 else {
800                     return list.get(0);
801                 }
802             }
803             catch (Exception e) {
804                 throw processException(e);
805             }
806             finally {
807                 closeSession(session);
808             }
809         }
810         else {
811             List<Layout> list = (List<Layout>)result;
812 
813             if (list.size() == 0) {
814                 return null;
815             }
816             else {
817                 return list.get(0);
818             }
819         }
820     }
821 
822     public Layout findByIconImageId(long iconImageId)
823         throws NoSuchLayoutException, SystemException {
824         Layout layout = fetchByIconImageId(iconImageId);
825 
826         if (layout == null) {
827             StringBuilder msg = new StringBuilder();
828 
829             msg.append("No Layout exists with the key {");
830 
831             msg.append("iconImageId=" + iconImageId);
832 
833             msg.append(StringPool.CLOSE_CURLY_BRACE);
834 
835             if (_log.isWarnEnabled()) {
836                 _log.warn(msg.toString());
837             }
838 
839             throw new NoSuchLayoutException(msg.toString());
840         }
841 
842         return layout;
843     }
844 
845     public Layout fetchByIconImageId(long iconImageId)
846         throws SystemException {
847         boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
848         String finderClassName = Layout.class.getName();
849         String finderMethodName = "fetchByIconImageId";
850         String[] finderParams = new String[] { Long.class.getName() };
851         Object[] finderArgs = new Object[] { new Long(iconImageId) };
852 
853         Object result = null;
854 
855         if (finderClassNameCacheEnabled) {
856             result = FinderCacheUtil.getResult(finderClassName,
857                     finderMethodName, finderParams, finderArgs, this);
858         }
859 
860         if (result == null) {
861             Session session = null;
862 
863             try {
864                 session = openSession();
865 
866                 StringBuilder query = new StringBuilder();
867 
868                 query.append("FROM com.liferay.portal.model.Layout WHERE ");
869 
870                 query.append("iconImageId = ?");
871 
872                 query.append(" ");
873 
874                 query.append("ORDER BY ");
875 
876                 query.append("parentLayoutId ASC, ");
877                 query.append("priority ASC");
878 
879                 Query q = session.createQuery(query.toString());
880 
881                 QueryPos qPos = QueryPos.getInstance(q);
882 
883                 qPos.add(iconImageId);
884 
885                 List<Layout> list = q.list();
886 
887                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
888                     finderClassName, finderMethodName, finderParams,
889                     finderArgs, list);
890 
891                 if (list.size() == 0) {
892                     return null;
893                 }
894                 else {
895                     return list.get(0);
896                 }
897             }
898             catch (Exception e) {
899                 throw processException(e);
900             }
901             finally {
902                 closeSession(session);
903             }
904         }
905         else {
906             List<Layout> list = (List<Layout>)result;
907 
908             if (list.size() == 0) {
909                 return null;
910             }
911             else {
912                 return list.get(0);
913             }
914         }
915     }
916 
917     public List<Layout> findByG_P(long groupId, boolean privateLayout)
918         throws SystemException {
919         boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
920         String finderClassName = Layout.class.getName();
921         String finderMethodName = "findByG_P";
922         String[] finderParams = new String[] {
923                 Long.class.getName(), Boolean.class.getName()
924             };
925         Object[] finderArgs = new Object[] {
926                 new Long(groupId), Boolean.valueOf(privateLayout)
927             };
928 
929         Object result = null;
930 
931         if (finderClassNameCacheEnabled) {
932             result = FinderCacheUtil.getResult(finderClassName,
933                     finderMethodName, finderParams, finderArgs, this);
934         }
935 
936         if (result == null) {
937             Session session = null;
938 
939             try {
940                 session = openSession();
941 
942                 StringBuilder query = new StringBuilder();
943 
944                 query.append("FROM com.liferay.portal.model.Layout WHERE ");
945 
946                 query.append("groupId = ?");
947 
948                 query.append(" AND ");
949 
950                 query.append("privateLayout = ?");
951 
952                 query.append(" ");
953 
954                 query.append("ORDER BY ");
955 
956                 query.append("parentLayoutId ASC, ");
957                 query.append("priority ASC");
958 
959                 Query q = session.createQuery(query.toString());
960 
961                 QueryPos qPos = QueryPos.getInstance(q);
962 
963                 qPos.add(groupId);
964 
965                 qPos.add(privateLayout);
966 
967                 List<Layout> list = q.list();
968 
969                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
970                     finderClassName, finderMethodName, finderParams,
971                     finderArgs, list);
972 
973                 return list;
974             }
975             catch (Exception e) {
976                 throw processException(e);
977             }
978             finally {
979                 closeSession(session);
980             }
981         }
982         else {
983             return (List<Layout>)result;
984         }
985     }
986 
987     public List<Layout> findByG_P(long groupId, boolean privateLayout,
988         int start, int end) throws SystemException {
989         return findByG_P(groupId, privateLayout, start, end, null);
990     }
991 
992     public List<Layout> findByG_P(long groupId, boolean privateLayout,
993         int start, int end, OrderByComparator obc) throws SystemException {
994         boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
995         String finderClassName = Layout.class.getName();
996         String finderMethodName = "findByG_P";
997         String[] finderParams = new String[] {
998                 Long.class.getName(), Boolean.class.getName(),
999                 
1000                "java.lang.Integer", "java.lang.Integer",
1001                "com.liferay.portal.kernel.util.OrderByComparator"
1002            };
1003        Object[] finderArgs = new Object[] {
1004                new Long(groupId), Boolean.valueOf(privateLayout),
1005                
1006                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1007            };
1008
1009        Object result = null;
1010
1011        if (finderClassNameCacheEnabled) {
1012            result = FinderCacheUtil.getResult(finderClassName,
1013                    finderMethodName, finderParams, finderArgs, this);
1014        }
1015
1016        if (result == null) {
1017            Session session = null;
1018
1019            try {
1020                session = openSession();
1021
1022                StringBuilder query = new StringBuilder();
1023
1024                query.append("FROM com.liferay.portal.model.Layout WHERE ");
1025
1026                query.append("groupId = ?");
1027
1028                query.append(" AND ");
1029
1030                query.append("privateLayout = ?");
1031
1032                query.append(" ");
1033
1034                if (obc != null) {
1035                    query.append("ORDER BY ");
1036                    query.append(obc.getOrderBy());
1037                }
1038
1039                else {
1040                    query.append("ORDER BY ");
1041
1042                    query.append("parentLayoutId ASC, ");
1043                    query.append("priority ASC");
1044                }
1045
1046                Query q = session.createQuery(query.toString());
1047
1048                QueryPos qPos = QueryPos.getInstance(q);
1049
1050                qPos.add(groupId);
1051
1052                qPos.add(privateLayout);
1053
1054                List<Layout> list = (List<Layout>)QueryUtil.list(q,
1055                        getDialect(), start, end);
1056
1057                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1058                    finderClassName, finderMethodName, finderParams,
1059                    finderArgs, list);
1060
1061                return list;
1062            }
1063            catch (Exception e) {
1064                throw processException(e);
1065            }
1066            finally {
1067                closeSession(session);
1068            }
1069        }
1070        else {
1071            return (List<Layout>)result;
1072        }
1073    }
1074
1075    public Layout findByG_P_First(long groupId, boolean privateLayout,
1076        OrderByComparator obc) throws NoSuchLayoutException, SystemException {
1077        List<Layout> list = findByG_P(groupId, privateLayout, 0, 1, obc);
1078
1079        if (list.size() == 0) {
1080            StringBuilder msg = new StringBuilder();
1081
1082            msg.append("No Layout exists with the key {");
1083
1084            msg.append("groupId=" + groupId);
1085
1086            msg.append(", ");
1087            msg.append("privateLayout=" + privateLayout);
1088
1089            msg.append(StringPool.CLOSE_CURLY_BRACE);
1090
1091            throw new NoSuchLayoutException(msg.toString());
1092        }
1093        else {
1094            return list.get(0);
1095        }
1096    }
1097
1098    public Layout findByG_P_Last(long groupId, boolean privateLayout,
1099        OrderByComparator obc) throws NoSuchLayoutException, SystemException {
1100        int count = countByG_P(groupId, privateLayout);
1101
1102        List<Layout> list = findByG_P(groupId, privateLayout, count - 1, count,
1103                obc);
1104
1105        if (list.size() == 0) {
1106            StringBuilder msg = new StringBuilder();
1107
1108            msg.append("No Layout exists with the key {");
1109
1110            msg.append("groupId=" + groupId);
1111
1112            msg.append(", ");
1113            msg.append("privateLayout=" + privateLayout);
1114
1115            msg.append(StringPool.CLOSE_CURLY_BRACE);
1116
1117            throw new NoSuchLayoutException(msg.toString());
1118        }
1119        else {
1120            return list.get(0);
1121        }
1122    }
1123
1124    public Layout[] findByG_P_PrevAndNext(long plid, long groupId,
1125        boolean privateLayout, OrderByComparator obc)
1126        throws NoSuchLayoutException, SystemException {
1127        Layout layout = findByPrimaryKey(plid);
1128
1129        int count = countByG_P(groupId, privateLayout);
1130
1131        Session session = null;
1132
1133        try {
1134            session = openSession();
1135
1136            StringBuilder query = new StringBuilder();
1137
1138            query.append("FROM com.liferay.portal.model.Layout WHERE ");
1139
1140            query.append("groupId = ?");
1141
1142            query.append(" AND ");
1143
1144            query.append("privateLayout = ?");
1145
1146            query.append(" ");
1147
1148            if (obc != null) {
1149                query.append("ORDER BY ");
1150                query.append(obc.getOrderBy());
1151            }
1152
1153            else {
1154                query.append("ORDER BY ");
1155
1156                query.append("parentLayoutId ASC, ");
1157                query.append("priority ASC");
1158            }
1159
1160            Query q = session.createQuery(query.toString());
1161
1162            QueryPos qPos = QueryPos.getInstance(q);
1163
1164            qPos.add(groupId);
1165
1166            qPos.add(privateLayout);
1167
1168            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, layout);
1169
1170            Layout[] array = new LayoutImpl[3];
1171
1172            array[0] = (Layout)objArray[0];
1173            array[1] = (Layout)objArray[1];
1174            array[2] = (Layout)objArray[2];
1175
1176            return array;
1177        }
1178        catch (Exception e) {
1179            throw processException(e);
1180        }
1181        finally {
1182            closeSession(session);
1183        }
1184    }
1185
1186    public Layout findByG_P_L(long groupId, boolean privateLayout, long layoutId)
1187        throws NoSuchLayoutException, SystemException {
1188        Layout layout = fetchByG_P_L(groupId, privateLayout, layoutId);
1189
1190        if (layout == null) {
1191            StringBuilder msg = new StringBuilder();
1192
1193            msg.append("No Layout exists with the key {");
1194
1195            msg.append("groupId=" + groupId);
1196
1197            msg.append(", ");
1198            msg.append("privateLayout=" + privateLayout);
1199
1200            msg.append(", ");
1201            msg.append("layoutId=" + layoutId);
1202
1203            msg.append(StringPool.CLOSE_CURLY_BRACE);
1204
1205            if (_log.isWarnEnabled()) {
1206                _log.warn(msg.toString());
1207            }
1208
1209            throw new NoSuchLayoutException(msg.toString());
1210        }
1211
1212        return layout;
1213    }
1214
1215    public Layout fetchByG_P_L(long groupId, boolean privateLayout,
1216        long layoutId) throws SystemException {
1217        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
1218        String finderClassName = Layout.class.getName();
1219        String finderMethodName = "fetchByG_P_L";
1220        String[] finderParams = new String[] {
1221                Long.class.getName(), Boolean.class.getName(),
1222                Long.class.getName()
1223            };
1224        Object[] finderArgs = new Object[] {
1225                new Long(groupId), Boolean.valueOf(privateLayout),
1226                new Long(layoutId)
1227            };
1228
1229        Object result = null;
1230
1231        if (finderClassNameCacheEnabled) {
1232            result = FinderCacheUtil.getResult(finderClassName,
1233                    finderMethodName, finderParams, finderArgs, this);
1234        }
1235
1236        if (result == null) {
1237            Session session = null;
1238
1239            try {
1240                session = openSession();
1241
1242                StringBuilder query = new StringBuilder();
1243
1244                query.append("FROM com.liferay.portal.model.Layout WHERE ");
1245
1246                query.append("groupId = ?");
1247
1248                query.append(" AND ");
1249
1250                query.append("privateLayout = ?");
1251
1252                query.append(" AND ");
1253
1254                query.append("layoutId = ?");
1255
1256                query.append(" ");
1257
1258                query.append("ORDER BY ");
1259
1260                query.append("parentLayoutId ASC, ");
1261                query.append("priority ASC");
1262
1263                Query q = session.createQuery(query.toString());
1264
1265                QueryPos qPos = QueryPos.getInstance(q);
1266
1267                qPos.add(groupId);
1268
1269                qPos.add(privateLayout);
1270
1271                qPos.add(layoutId);
1272
1273                List<Layout> list = q.list();
1274
1275                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1276                    finderClassName, finderMethodName, finderParams,
1277                    finderArgs, list);
1278
1279                if (list.size() == 0) {
1280                    return null;
1281                }
1282                else {
1283                    return list.get(0);
1284                }
1285            }
1286            catch (Exception e) {
1287                throw processException(e);
1288            }
1289            finally {
1290                closeSession(session);
1291            }
1292        }
1293        else {
1294            List<Layout> list = (List<Layout>)result;
1295
1296            if (list.size() == 0) {
1297                return null;
1298            }
1299            else {
1300                return list.get(0);
1301            }
1302        }
1303    }
1304
1305    public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
1306        long parentLayoutId) throws SystemException {
1307        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
1308        String finderClassName = Layout.class.getName();
1309        String finderMethodName = "findByG_P_P";
1310        String[] finderParams = new String[] {
1311                Long.class.getName(), Boolean.class.getName(),
1312                Long.class.getName()
1313            };
1314        Object[] finderArgs = new Object[] {
1315                new Long(groupId), Boolean.valueOf(privateLayout),
1316                new Long(parentLayoutId)
1317            };
1318
1319        Object result = null;
1320
1321        if (finderClassNameCacheEnabled) {
1322            result = FinderCacheUtil.getResult(finderClassName,
1323                    finderMethodName, finderParams, finderArgs, this);
1324        }
1325
1326        if (result == null) {
1327            Session session = null;
1328
1329            try {
1330                session = openSession();
1331
1332                StringBuilder query = new StringBuilder();
1333
1334                query.append("FROM com.liferay.portal.model.Layout WHERE ");
1335
1336                query.append("groupId = ?");
1337
1338                query.append(" AND ");
1339
1340                query.append("privateLayout = ?");
1341
1342                query.append(" AND ");
1343
1344                query.append("parentLayoutId = ?");
1345
1346                query.append(" ");
1347
1348                query.append("ORDER BY ");
1349
1350                query.append("parentLayoutId ASC, ");
1351                query.append("priority ASC");
1352
1353                Query q = session.createQuery(query.toString());
1354
1355                QueryPos qPos = QueryPos.getInstance(q);
1356
1357                qPos.add(groupId);
1358
1359                qPos.add(privateLayout);
1360
1361                qPos.add(parentLayoutId);
1362
1363                List<Layout> list = q.list();
1364
1365                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1366                    finderClassName, finderMethodName, finderParams,
1367                    finderArgs, list);
1368
1369                return list;
1370            }
1371            catch (Exception e) {
1372                throw processException(e);
1373            }
1374            finally {
1375                closeSession(session);
1376            }
1377        }
1378        else {
1379            return (List<Layout>)result;
1380        }
1381    }
1382
1383    public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
1384        long parentLayoutId, int start, int end) throws SystemException {
1385        return findByG_P_P(groupId, privateLayout, parentLayoutId, start, end,
1386            null);
1387    }
1388
1389    public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
1390        long parentLayoutId, int start, int end, OrderByComparator obc)
1391        throws SystemException {
1392        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
1393        String finderClassName = Layout.class.getName();
1394        String finderMethodName = "findByG_P_P";
1395        String[] finderParams = new String[] {
1396                Long.class.getName(), Boolean.class.getName(),
1397                Long.class.getName(),
1398                
1399                "java.lang.Integer", "java.lang.Integer",
1400                "com.liferay.portal.kernel.util.OrderByComparator"
1401            };
1402        Object[] finderArgs = new Object[] {
1403                new Long(groupId), Boolean.valueOf(privateLayout),
1404                new Long(parentLayoutId),
1405                
1406                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1407            };
1408
1409        Object result = null;
1410
1411        if (finderClassNameCacheEnabled) {
1412            result = FinderCacheUtil.getResult(finderClassName,
1413                    finderMethodName, finderParams, finderArgs, this);
1414        }
1415
1416        if (result == null) {
1417            Session session = null;
1418
1419            try {
1420                session = openSession();
1421
1422                StringBuilder query = new StringBuilder();
1423
1424                query.append("FROM com.liferay.portal.model.Layout WHERE ");
1425
1426                query.append("groupId = ?");
1427
1428                query.append(" AND ");
1429
1430                query.append("privateLayout = ?");
1431
1432                query.append(" AND ");
1433
1434                query.append("parentLayoutId = ?");
1435
1436                query.append(" ");
1437
1438                if (obc != null) {
1439                    query.append("ORDER BY ");
1440                    query.append(obc.getOrderBy());
1441                }
1442
1443                else {
1444                    query.append("ORDER BY ");
1445
1446                    query.append("parentLayoutId ASC, ");
1447                    query.append("priority ASC");
1448                }
1449
1450                Query q = session.createQuery(query.toString());
1451
1452                QueryPos qPos = QueryPos.getInstance(q);
1453
1454                qPos.add(groupId);
1455
1456                qPos.add(privateLayout);
1457
1458                qPos.add(parentLayoutId);
1459
1460                List<Layout> list = (List<Layout>)QueryUtil.list(q,
1461                        getDialect(), start, end);
1462
1463                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1464                    finderClassName, finderMethodName, finderParams,
1465                    finderArgs, list);
1466
1467                return list;
1468            }
1469            catch (Exception e) {
1470                throw processException(e);
1471            }
1472            finally {
1473                closeSession(session);
1474            }
1475        }
1476        else {
1477            return (List<Layout>)result;
1478        }
1479    }
1480
1481    public Layout findByG_P_P_First(long groupId, boolean privateLayout,
1482        long parentLayoutId, OrderByComparator obc)
1483        throws NoSuchLayoutException, SystemException {
1484        List<Layout> list = findByG_P_P(groupId, privateLayout, parentLayoutId,
1485                0, 1, obc);
1486
1487        if (list.size() == 0) {
1488            StringBuilder msg = new StringBuilder();
1489
1490            msg.append("No Layout exists with the key {");
1491
1492            msg.append("groupId=" + groupId);
1493
1494            msg.append(", ");
1495            msg.append("privateLayout=" + privateLayout);
1496
1497            msg.append(", ");
1498            msg.append("parentLayoutId=" + parentLayoutId);
1499
1500            msg.append(StringPool.CLOSE_CURLY_BRACE);
1501
1502            throw new NoSuchLayoutException(msg.toString());
1503        }
1504        else {
1505            return list.get(0);
1506        }
1507    }
1508
1509    public Layout findByG_P_P_Last(long groupId, boolean privateLayout,
1510        long parentLayoutId, OrderByComparator obc)
1511        throws NoSuchLayoutException, SystemException {
1512        int count = countByG_P_P(groupId, privateLayout, parentLayoutId);
1513
1514        List<Layout> list = findByG_P_P(groupId, privateLayout, parentLayoutId,
1515                count - 1, count, obc);
1516
1517        if (list.size() == 0) {
1518            StringBuilder msg = new StringBuilder();
1519
1520            msg.append("No Layout exists with the key {");
1521
1522            msg.append("groupId=" + groupId);
1523
1524            msg.append(", ");
1525            msg.append("privateLayout=" + privateLayout);
1526
1527            msg.append(", ");
1528            msg.append("parentLayoutId=" + parentLayoutId);
1529
1530            msg.append(StringPool.CLOSE_CURLY_BRACE);
1531
1532            throw new NoSuchLayoutException(msg.toString());
1533        }
1534        else {
1535            return list.get(0);
1536        }
1537    }
1538
1539    public Layout[] findByG_P_P_PrevAndNext(long plid, long groupId,
1540        boolean privateLayout, long parentLayoutId, OrderByComparator obc)
1541        throws NoSuchLayoutException, SystemException {
1542        Layout layout = findByPrimaryKey(plid);
1543
1544        int count = countByG_P_P(groupId, privateLayout, parentLayoutId);
1545
1546        Session session = null;
1547
1548        try {
1549            session = openSession();
1550
1551            StringBuilder query = new StringBuilder();
1552
1553            query.append("FROM com.liferay.portal.model.Layout WHERE ");
1554
1555            query.append("groupId = ?");
1556
1557            query.append(" AND ");
1558
1559            query.append("privateLayout = ?");
1560
1561            query.append(" AND ");
1562
1563            query.append("parentLayoutId = ?");
1564
1565            query.append(" ");
1566
1567            if (obc != null) {
1568                query.append("ORDER BY ");
1569                query.append(obc.getOrderBy());
1570            }
1571
1572            else {
1573                query.append("ORDER BY ");
1574
1575                query.append("parentLayoutId ASC, ");
1576                query.append("priority ASC");
1577            }
1578
1579            Query q = session.createQuery(query.toString());
1580
1581            QueryPos qPos = QueryPos.getInstance(q);
1582
1583            qPos.add(groupId);
1584
1585            qPos.add(privateLayout);
1586
1587            qPos.add(parentLayoutId);
1588
1589            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, layout);
1590
1591            Layout[] array = new LayoutImpl[3];
1592
1593            array[0] = (Layout)objArray[0];
1594            array[1] = (Layout)objArray[1];
1595            array[2] = (Layout)objArray[2];
1596
1597            return array;
1598        }
1599        catch (Exception e) {
1600            throw processException(e);
1601        }
1602        finally {
1603            closeSession(session);
1604        }
1605    }
1606
1607    public Layout findByG_P_F(long groupId, boolean privateLayout,
1608        String friendlyURL) throws NoSuchLayoutException, SystemException {
1609        Layout layout = fetchByG_P_F(groupId, privateLayout, friendlyURL);
1610
1611        if (layout == null) {
1612            StringBuilder msg = new StringBuilder();
1613
1614            msg.append("No Layout exists with the key {");
1615
1616            msg.append("groupId=" + groupId);
1617
1618            msg.append(", ");
1619            msg.append("privateLayout=" + privateLayout);
1620
1621            msg.append(", ");
1622            msg.append("friendlyURL=" + friendlyURL);
1623
1624            msg.append(StringPool.CLOSE_CURLY_BRACE);
1625
1626            if (_log.isWarnEnabled()) {
1627                _log.warn(msg.toString());
1628            }
1629
1630            throw new NoSuchLayoutException(msg.toString());
1631        }
1632
1633        return layout;
1634    }
1635
1636    public Layout fetchByG_P_F(long groupId, boolean privateLayout,
1637        String friendlyURL) throws SystemException {
1638        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
1639        String finderClassName = Layout.class.getName();
1640        String finderMethodName = "fetchByG_P_F";
1641        String[] finderParams = new String[] {
1642                Long.class.getName(), Boolean.class.getName(),
1643                String.class.getName()
1644            };
1645        Object[] finderArgs = new Object[] {
1646                new Long(groupId), Boolean.valueOf(privateLayout),
1647                
1648                friendlyURL
1649            };
1650
1651        Object result = null;
1652
1653        if (finderClassNameCacheEnabled) {
1654            result = FinderCacheUtil.getResult(finderClassName,
1655                    finderMethodName, finderParams, finderArgs, this);
1656        }
1657
1658        if (result == null) {
1659            Session session = null;
1660
1661            try {
1662                session = openSession();
1663
1664                StringBuilder query = new StringBuilder();
1665
1666                query.append("FROM com.liferay.portal.model.Layout WHERE ");
1667
1668                query.append("groupId = ?");
1669
1670                query.append(" AND ");
1671
1672                query.append("privateLayout = ?");
1673
1674                query.append(" AND ");
1675
1676                if (friendlyURL == null) {
1677                    query.append("friendlyURL IS NULL");
1678                }
1679                else {
1680                    query.append("lower(friendlyURL) = ?");
1681                }
1682
1683                query.append(" ");
1684
1685                query.append("ORDER BY ");
1686
1687                query.append("parentLayoutId ASC, ");
1688                query.append("priority ASC");
1689
1690                Query q = session.createQuery(query.toString());
1691
1692                QueryPos qPos = QueryPos.getInstance(q);
1693
1694                qPos.add(groupId);
1695
1696                qPos.add(privateLayout);
1697
1698                if (friendlyURL != null) {
1699                    qPos.add(friendlyURL);
1700                }
1701
1702                List<Layout> list = q.list();
1703
1704                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1705                    finderClassName, finderMethodName, finderParams,
1706                    finderArgs, list);
1707
1708                if (list.size() == 0) {
1709                    return null;
1710                }
1711                else {
1712                    return list.get(0);
1713                }
1714            }
1715            catch (Exception e) {
1716                throw processException(e);
1717            }
1718            finally {
1719                closeSession(session);
1720            }
1721        }
1722        else {
1723            List<Layout> list = (List<Layout>)result;
1724
1725            if (list.size() == 0) {
1726                return null;
1727            }
1728            else {
1729                return list.get(0);
1730            }
1731        }
1732    }
1733
1734    public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
1735        String type) throws SystemException {
1736        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
1737        String finderClassName = Layout.class.getName();
1738        String finderMethodName = "findByG_P_T";
1739        String[] finderParams = new String[] {
1740                Long.class.getName(), Boolean.class.getName(),
1741                String.class.getName()
1742            };
1743        Object[] finderArgs = new Object[] {
1744                new Long(groupId), Boolean.valueOf(privateLayout),
1745                
1746                type
1747            };
1748
1749        Object result = null;
1750
1751        if (finderClassNameCacheEnabled) {
1752            result = FinderCacheUtil.getResult(finderClassName,
1753                    finderMethodName, finderParams, finderArgs, this);
1754        }
1755
1756        if (result == null) {
1757            Session session = null;
1758
1759            try {
1760                session = openSession();
1761
1762                StringBuilder query = new StringBuilder();
1763
1764                query.append("FROM com.liferay.portal.model.Layout WHERE ");
1765
1766                query.append("groupId = ?");
1767
1768                query.append(" AND ");
1769
1770                query.append("privateLayout = ?");
1771
1772                query.append(" AND ");
1773
1774                if (type == null) {
1775                    query.append("type_ IS NULL");
1776                }
1777                else {
1778                    query.append("type_ = ?");
1779                }
1780
1781                query.append(" ");
1782
1783                query.append("ORDER BY ");
1784
1785                query.append("parentLayoutId ASC, ");
1786                query.append("priority ASC");
1787
1788                Query q = session.createQuery(query.toString());
1789
1790                QueryPos qPos = QueryPos.getInstance(q);
1791
1792                qPos.add(groupId);
1793
1794                qPos.add(privateLayout);
1795
1796                if (type != null) {
1797                    qPos.add(type);
1798                }
1799
1800                List<Layout> list = q.list();
1801
1802                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1803                    finderClassName, finderMethodName, finderParams,
1804                    finderArgs, list);
1805
1806                return list;
1807            }
1808            catch (Exception e) {
1809                throw processException(e);
1810            }
1811            finally {
1812                closeSession(session);
1813            }
1814        }
1815        else {
1816            return (List<Layout>)result;
1817        }
1818    }
1819
1820    public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
1821        String type, int start, int end) throws SystemException {
1822        return findByG_P_T(groupId, privateLayout, type, start, end, null);
1823    }
1824
1825    public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
1826        String type, int start, int end, OrderByComparator obc)
1827        throws SystemException {
1828        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
1829        String finderClassName = Layout.class.getName();
1830        String finderMethodName = "findByG_P_T";
1831        String[] finderParams = new String[] {
1832                Long.class.getName(), Boolean.class.getName(),
1833                String.class.getName(),
1834                
1835                "java.lang.Integer", "java.lang.Integer",
1836                "com.liferay.portal.kernel.util.OrderByComparator"
1837            };
1838        Object[] finderArgs = new Object[] {
1839                new Long(groupId), Boolean.valueOf(privateLayout),
1840                
1841                type,
1842                
1843                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1844            };
1845
1846        Object result = null;
1847
1848        if (finderClassNameCacheEnabled) {
1849            result = FinderCacheUtil.getResult(finderClassName,
1850                    finderMethodName, finderParams, finderArgs, this);
1851        }
1852
1853        if (result == null) {
1854            Session session = null;
1855
1856            try {
1857                session = openSession();
1858
1859                StringBuilder query = new StringBuilder();
1860
1861                query.append("FROM com.liferay.portal.model.Layout WHERE ");
1862
1863                query.append("groupId = ?");
1864
1865                query.append(" AND ");
1866
1867                query.append("privateLayout = ?");
1868
1869                query.append(" AND ");
1870
1871                if (type == null) {
1872                    query.append("type_ IS NULL");
1873                }
1874                else {
1875                    query.append("type_ = ?");
1876                }
1877
1878                query.append(" ");
1879
1880                if (obc != null) {
1881                    query.append("ORDER BY ");
1882                    query.append(obc.getOrderBy());
1883                }
1884
1885                else {
1886                    query.append("ORDER BY ");
1887
1888                    query.append("parentLayoutId ASC, ");
1889                    query.append("priority ASC");
1890                }
1891
1892                Query q = session.createQuery(query.toString());
1893
1894                QueryPos qPos = QueryPos.getInstance(q);
1895
1896                qPos.add(groupId);
1897
1898                qPos.add(privateLayout);
1899
1900                if (type != null) {
1901                    qPos.add(type);
1902                }
1903
1904                List<Layout> list = (List<Layout>)QueryUtil.list(q,
1905                        getDialect(), start, end);
1906
1907                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1908                    finderClassName, finderMethodName, finderParams,
1909                    finderArgs, list);
1910
1911                return list;
1912            }
1913            catch (Exception e) {
1914                throw processException(e);
1915            }
1916            finally {
1917                closeSession(session);
1918            }
1919        }
1920        else {
1921            return (List<Layout>)result;
1922        }
1923    }
1924
1925    public Layout findByG_P_T_First(long groupId, boolean privateLayout,
1926        String type, OrderByComparator obc)
1927        throws NoSuchLayoutException, SystemException {
1928        List<Layout> list = findByG_P_T(groupId, privateLayout, type, 0, 1, obc);
1929
1930        if (list.size() == 0) {
1931            StringBuilder msg = new StringBuilder();
1932
1933            msg.append("No Layout exists with the key {");
1934
1935            msg.append("groupId=" + groupId);
1936
1937            msg.append(", ");
1938            msg.append("privateLayout=" + privateLayout);
1939
1940            msg.append(", ");
1941            msg.append("type=" + type);
1942
1943            msg.append(StringPool.CLOSE_CURLY_BRACE);
1944
1945            throw new NoSuchLayoutException(msg.toString());
1946        }
1947        else {
1948            return list.get(0);
1949        }
1950    }
1951
1952    public Layout findByG_P_T_Last(long groupId, boolean privateLayout,
1953        String type, OrderByComparator obc)
1954        throws NoSuchLayoutException, SystemException {
1955        int count = countByG_P_T(groupId, privateLayout, type);
1956
1957        List<Layout> list = findByG_P_T(groupId, privateLayout, type,
1958                count - 1, count, obc);
1959
1960        if (list.size() == 0) {
1961            StringBuilder msg = new StringBuilder();
1962
1963            msg.append("No Layout exists with the key {");
1964
1965            msg.append("groupId=" + groupId);
1966
1967            msg.append(", ");
1968            msg.append("privateLayout=" + privateLayout);
1969
1970            msg.append(", ");
1971            msg.append("type=" + type);
1972
1973            msg.append(StringPool.CLOSE_CURLY_BRACE);
1974
1975            throw new NoSuchLayoutException(msg.toString());
1976        }
1977        else {
1978            return list.get(0);
1979        }
1980    }
1981
1982    public Layout[] findByG_P_T_PrevAndNext(long plid, long groupId,
1983        boolean privateLayout, String type, OrderByComparator obc)
1984        throws NoSuchLayoutException, SystemException {
1985        Layout layout = findByPrimaryKey(plid);
1986
1987        int count = countByG_P_T(groupId, privateLayout, type);
1988
1989        Session session = null;
1990
1991        try {
1992            session = openSession();
1993
1994            StringBuilder query = new StringBuilder();
1995
1996            query.append("FROM com.liferay.portal.model.Layout WHERE ");
1997
1998            query.append("groupId = ?");
1999
2000            query.append(" AND ");
2001
2002            query.append("privateLayout = ?");
2003
2004            query.append(" AND ");
2005
2006            if (type == null) {
2007                query.append("type_ IS NULL");
2008            }
2009            else {
2010                query.append("type_ = ?");
2011            }
2012
2013            query.append(" ");
2014
2015            if (obc != null) {
2016                query.append("ORDER BY ");
2017                query.append(obc.getOrderBy());
2018            }
2019
2020            else {
2021                query.append("ORDER BY ");
2022
2023                query.append("parentLayoutId ASC, ");
2024                query.append("priority ASC");
2025            }
2026
2027            Query q = session.createQuery(query.toString());
2028
2029            QueryPos qPos = QueryPos.getInstance(q);
2030
2031            qPos.add(groupId);
2032
2033            qPos.add(privateLayout);
2034
2035            if (type != null) {
2036                qPos.add(type);
2037            }
2038
2039            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, layout);
2040
2041            Layout[] array = new LayoutImpl[3];
2042
2043            array[0] = (Layout)objArray[0];
2044            array[1] = (Layout)objArray[1];
2045            array[2] = (Layout)objArray[2];
2046
2047            return array;
2048        }
2049        catch (Exception e) {
2050            throw processException(e);
2051        }
2052        finally {
2053            closeSession(session);
2054        }
2055    }
2056
2057    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
2058        throws SystemException {
2059        Session session = null;
2060
2061        try {
2062            session = openSession();
2063
2064            dynamicQuery.compile(session);
2065
2066            return dynamicQuery.list();
2067        }
2068        catch (Exception e) {
2069            throw processException(e);
2070        }
2071        finally {
2072            closeSession(session);
2073        }
2074    }
2075
2076    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
2077        int start, int end) throws SystemException {
2078        Session session = null;
2079
2080        try {
2081            session = openSession();
2082
2083            dynamicQuery.setLimit(start, end);
2084
2085            dynamicQuery.compile(session);
2086
2087            return dynamicQuery.list();
2088        }
2089        catch (Exception e) {
2090            throw processException(e);
2091        }
2092        finally {
2093            closeSession(session);
2094        }
2095    }
2096
2097    public List<Layout> findAll() throws SystemException {
2098        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2099    }
2100
2101    public List<Layout> findAll(int start, int end) throws SystemException {
2102        return findAll(start, end, null);
2103    }
2104
2105    public List<Layout> findAll(int start, int end, OrderByComparator obc)
2106        throws SystemException {
2107        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
2108        String finderClassName = Layout.class.getName();
2109        String finderMethodName = "findAll";
2110        String[] finderParams = new String[] {
2111                "java.lang.Integer", "java.lang.Integer",
2112                "com.liferay.portal.kernel.util.OrderByComparator"
2113            };
2114        Object[] finderArgs = new Object[] {
2115                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2116            };
2117
2118        Object result = null;
2119
2120        if (finderClassNameCacheEnabled) {
2121            result = FinderCacheUtil.getResult(finderClassName,
2122                    finderMethodName, finderParams, finderArgs, this);
2123        }
2124
2125        if (result == null) {
2126            Session session = null;
2127
2128            try {
2129                session = openSession();
2130
2131                StringBuilder query = new StringBuilder();
2132
2133                query.append("FROM com.liferay.portal.model.Layout ");
2134
2135                if (obc != null) {
2136                    query.append("ORDER BY ");
2137                    query.append(obc.getOrderBy());
2138                }
2139
2140                else {
2141                    query.append("ORDER BY ");
2142
2143                    query.append("parentLayoutId ASC, ");
2144                    query.append("priority ASC");
2145                }
2146
2147                Query q = session.createQuery(query.toString());
2148
2149                List<Layout> list = null;
2150
2151                if (obc == null) {
2152                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
2153                            end, false);
2154
2155                    Collections.sort(list);
2156                }
2157                else {
2158                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
2159                            end);
2160                }
2161
2162                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2163                    finderClassName, finderMethodName, finderParams,
2164                    finderArgs, list);
2165
2166                return list;
2167            }
2168            catch (Exception e) {
2169                throw processException(e);
2170            }
2171            finally {
2172                closeSession(session);
2173            }
2174        }
2175        else {
2176            return (List<Layout>)result;
2177        }
2178    }
2179
2180    public void removeByGroupId(long groupId) throws SystemException {
2181        for (Layout layout : findByGroupId(groupId)) {
2182            remove(layout);
2183        }
2184    }
2185
2186    public void removeByCompanyId(long companyId) throws SystemException {
2187        for (Layout layout : findByCompanyId(companyId)) {
2188            remove(layout);
2189        }
2190    }
2191
2192    public void removeByDLFolderId(long dlFolderId)
2193        throws NoSuchLayoutException, SystemException {
2194        Layout layout = findByDLFolderId(dlFolderId);
2195
2196        remove(layout);
2197    }
2198
2199    public void removeByIconImageId(long iconImageId)
2200        throws NoSuchLayoutException, SystemException {
2201        Layout layout = findByIconImageId(iconImageId);
2202
2203        remove(layout);
2204    }
2205
2206    public void removeByG_P(long groupId, boolean privateLayout)
2207        throws SystemException {
2208        for (Layout layout : findByG_P(groupId, privateLayout)) {
2209            remove(layout);
2210        }
2211    }
2212
2213    public void removeByG_P_L(long groupId, boolean privateLayout, long layoutId)
2214        throws NoSuchLayoutException, SystemException {
2215        Layout layout = findByG_P_L(groupId, privateLayout, layoutId);
2216
2217        remove(layout);
2218    }
2219
2220    public void removeByG_P_P(long groupId, boolean privateLayout,
2221        long parentLayoutId) throws SystemException {
2222        for (Layout layout : findByG_P_P(groupId, privateLayout, parentLayoutId)) {
2223            remove(layout);
2224        }
2225    }
2226
2227    public void removeByG_P_F(long groupId, boolean privateLayout,
2228        String friendlyURL) throws NoSuchLayoutException, SystemException {
2229        Layout layout = findByG_P_F(groupId, privateLayout, friendlyURL);
2230
2231        remove(layout);
2232    }
2233
2234    public void removeByG_P_T(long groupId, boolean privateLayout, String type)
2235        throws SystemException {
2236        for (Layout layout : findByG_P_T(groupId, privateLayout, type)) {
2237            remove(layout);
2238        }
2239    }
2240
2241    public void removeAll() throws SystemException {
2242        for (Layout layout : findAll()) {
2243            remove(layout);
2244        }
2245    }
2246
2247    public int countByGroupId(long groupId) throws SystemException {
2248        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
2249        String finderClassName = Layout.class.getName();
2250        String finderMethodName = "countByGroupId";
2251        String[] finderParams = new String[] { Long.class.getName() };
2252        Object[] finderArgs = new Object[] { new Long(groupId) };
2253
2254        Object result = null;
2255
2256        if (finderClassNameCacheEnabled) {
2257            result = FinderCacheUtil.getResult(finderClassName,
2258                    finderMethodName, finderParams, finderArgs, this);
2259        }
2260
2261        if (result == null) {
2262            Session session = null;
2263
2264            try {
2265                session = openSession();
2266
2267                StringBuilder query = new StringBuilder();
2268
2269                query.append("SELECT COUNT(*) ");
2270                query.append("FROM com.liferay.portal.model.Layout WHERE ");
2271
2272                query.append("groupId = ?");
2273
2274                query.append(" ");
2275
2276                Query q = session.createQuery(query.toString());
2277
2278                QueryPos qPos = QueryPos.getInstance(q);
2279
2280                qPos.add(groupId);
2281
2282                Long count = null;
2283
2284                Iterator<Long> itr = q.list().iterator();
2285
2286                if (itr.hasNext()) {
2287                    count = itr.next();
2288                }
2289
2290                if (count == null) {
2291                    count = new Long(0);
2292                }
2293
2294                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2295                    finderClassName, finderMethodName, finderParams,
2296                    finderArgs, count);
2297
2298                return count.intValue();
2299            }
2300            catch (Exception e) {
2301                throw processException(e);
2302            }
2303            finally {
2304                closeSession(session);
2305            }
2306        }
2307        else {
2308            return ((Long)result).intValue();
2309        }
2310    }
2311
2312    public int countByCompanyId(long companyId) throws SystemException {
2313        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
2314        String finderClassName = Layout.class.getName();
2315        String finderMethodName = "countByCompanyId";
2316        String[] finderParams = new String[] { Long.class.getName() };
2317        Object[] finderArgs = new Object[] { new Long(companyId) };
2318
2319        Object result = null;
2320
2321        if (finderClassNameCacheEnabled) {
2322            result = FinderCacheUtil.getResult(finderClassName,
2323                    finderMethodName, finderParams, finderArgs, this);
2324        }
2325
2326        if (result == null) {
2327            Session session = null;
2328
2329            try {
2330                session = openSession();
2331
2332                StringBuilder query = new StringBuilder();
2333
2334                query.append("SELECT COUNT(*) ");
2335                query.append("FROM com.liferay.portal.model.Layout WHERE ");
2336
2337                query.append("companyId = ?");
2338
2339                query.append(" ");
2340
2341                Query q = session.createQuery(query.toString());
2342
2343                QueryPos qPos = QueryPos.getInstance(q);
2344
2345                qPos.add(companyId);
2346
2347                Long count = null;
2348
2349                Iterator<Long> itr = q.list().iterator();
2350
2351                if (itr.hasNext()) {
2352                    count = itr.next();
2353                }
2354
2355                if (count == null) {
2356                    count = new Long(0);
2357                }
2358
2359                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2360                    finderClassName, finderMethodName, finderParams,
2361                    finderArgs, count);
2362
2363                return count.intValue();
2364            }
2365            catch (Exception e) {
2366                throw processException(e);
2367            }
2368            finally {
2369                closeSession(session);
2370            }
2371        }
2372        else {
2373            return ((Long)result).intValue();
2374        }
2375    }
2376
2377    public int countByDLFolderId(long dlFolderId) throws SystemException {
2378        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
2379        String finderClassName = Layout.class.getName();
2380        String finderMethodName = "countByDLFolderId";
2381        String[] finderParams = new String[] { Long.class.getName() };
2382        Object[] finderArgs = new Object[] { new Long(dlFolderId) };
2383
2384        Object result = null;
2385
2386        if (finderClassNameCacheEnabled) {
2387            result = FinderCacheUtil.getResult(finderClassName,
2388                    finderMethodName, finderParams, finderArgs, this);
2389        }
2390
2391        if (result == null) {
2392            Session session = null;
2393
2394            try {
2395                session = openSession();
2396
2397                StringBuilder query = new StringBuilder();
2398
2399                query.append("SELECT COUNT(*) ");
2400                query.append("FROM com.liferay.portal.model.Layout WHERE ");
2401
2402                query.append("dlFolderId = ?");
2403
2404                query.append(" ");
2405
2406                Query q = session.createQuery(query.toString());
2407
2408                QueryPos qPos = QueryPos.getInstance(q);
2409
2410                qPos.add(dlFolderId);
2411
2412                Long count = null;
2413
2414                Iterator<Long> itr = q.list().iterator();
2415
2416                if (itr.hasNext()) {
2417                    count = itr.next();
2418                }
2419
2420                if (count == null) {
2421                    count = new Long(0);
2422                }
2423
2424                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2425                    finderClassName, finderMethodName, finderParams,
2426                    finderArgs, count);
2427
2428                return count.intValue();
2429            }
2430            catch (Exception e) {
2431                throw processException(e);
2432            }
2433            finally {
2434                closeSession(session);
2435            }
2436        }
2437        else {
2438            return ((Long)result).intValue();
2439        }
2440    }
2441
2442    public int countByIconImageId(long iconImageId) throws SystemException {
2443        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
2444        String finderClassName = Layout.class.getName();
2445        String finderMethodName = "countByIconImageId";
2446        String[] finderParams = new String[] { Long.class.getName() };
2447        Object[] finderArgs = new Object[] { new Long(iconImageId) };
2448
2449        Object result = null;
2450
2451        if (finderClassNameCacheEnabled) {
2452            result = FinderCacheUtil.getResult(finderClassName,
2453                    finderMethodName, finderParams, finderArgs, this);
2454        }
2455
2456        if (result == null) {
2457            Session session = null;
2458
2459            try {
2460                session = openSession();
2461
2462                StringBuilder query = new StringBuilder();
2463
2464                query.append("SELECT COUNT(*) ");
2465                query.append("FROM com.liferay.portal.model.Layout WHERE ");
2466
2467                query.append("iconImageId = ?");
2468
2469                query.append(" ");
2470
2471                Query q = session.createQuery(query.toString());
2472
2473                QueryPos qPos = QueryPos.getInstance(q);
2474
2475                qPos.add(iconImageId);
2476
2477                Long count = null;
2478
2479                Iterator<Long> itr = q.list().iterator();
2480
2481                if (itr.hasNext()) {
2482                    count = itr.next();
2483                }
2484
2485                if (count == null) {
2486                    count = new Long(0);
2487                }
2488
2489                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2490                    finderClassName, finderMethodName, finderParams,
2491                    finderArgs, count);
2492
2493                return count.intValue();
2494            }
2495            catch (Exception e) {
2496                throw processException(e);
2497            }
2498            finally {
2499                closeSession(session);
2500            }
2501        }
2502        else {
2503            return ((Long)result).intValue();
2504        }
2505    }
2506
2507    public int countByG_P(long groupId, boolean privateLayout)
2508        throws SystemException {
2509        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
2510        String finderClassName = Layout.class.getName();
2511        String finderMethodName = "countByG_P";
2512        String[] finderParams = new String[] {
2513                Long.class.getName(), Boolean.class.getName()
2514            };
2515        Object[] finderArgs = new Object[] {
2516                new Long(groupId), Boolean.valueOf(privateLayout)
2517            };
2518
2519        Object result = null;
2520
2521        if (finderClassNameCacheEnabled) {
2522            result = FinderCacheUtil.getResult(finderClassName,
2523                    finderMethodName, finderParams, finderArgs, this);
2524        }
2525
2526        if (result == null) {
2527            Session session = null;
2528
2529            try {
2530                session = openSession();
2531
2532                StringBuilder query = new StringBuilder();
2533
2534                query.append("SELECT COUNT(*) ");
2535                query.append("FROM com.liferay.portal.model.Layout WHERE ");
2536
2537                query.append("groupId = ?");
2538
2539                query.append(" AND ");
2540
2541                query.append("privateLayout = ?");
2542
2543                query.append(" ");
2544
2545                Query q = session.createQuery(query.toString());
2546
2547                QueryPos qPos = QueryPos.getInstance(q);
2548
2549                qPos.add(groupId);
2550
2551                qPos.add(privateLayout);
2552
2553                Long count = null;
2554
2555                Iterator<Long> itr = q.list().iterator();
2556
2557                if (itr.hasNext()) {
2558                    count = itr.next();
2559                }
2560
2561                if (count == null) {
2562                    count = new Long(0);
2563                }
2564
2565                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2566                    finderClassName, finderMethodName, finderParams,
2567                    finderArgs, count);
2568
2569                return count.intValue();
2570            }
2571            catch (Exception e) {
2572                throw processException(e);
2573            }
2574            finally {
2575                closeSession(session);
2576            }
2577        }
2578        else {
2579            return ((Long)result).intValue();
2580        }
2581    }
2582
2583    public int countByG_P_L(long groupId, boolean privateLayout, long layoutId)
2584        throws SystemException {
2585        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
2586        String finderClassName = Layout.class.getName();
2587        String finderMethodName = "countByG_P_L";
2588        String[] finderParams = new String[] {
2589                Long.class.getName(), Boolean.class.getName(),
2590                Long.class.getName()
2591            };
2592        Object[] finderArgs = new Object[] {
2593                new Long(groupId), Boolean.valueOf(privateLayout),
2594                new Long(layoutId)
2595            };
2596
2597        Object result = null;
2598
2599        if (finderClassNameCacheEnabled) {
2600            result = FinderCacheUtil.getResult(finderClassName,
2601                    finderMethodName, finderParams, finderArgs, this);
2602        }
2603
2604        if (result == null) {
2605            Session session = null;
2606
2607            try {
2608                session = openSession();
2609
2610                StringBuilder query = new StringBuilder();
2611
2612                query.append("SELECT COUNT(*) ");
2613                query.append("FROM com.liferay.portal.model.Layout WHERE ");
2614
2615                query.append("groupId = ?");
2616
2617                query.append(" AND ");
2618
2619                query.append("privateLayout = ?");
2620
2621                query.append(" AND ");
2622
2623                query.append("layoutId = ?");
2624
2625                query.append(" ");
2626
2627                Query q = session.createQuery(query.toString());
2628
2629                QueryPos qPos = QueryPos.getInstance(q);
2630
2631                qPos.add(groupId);
2632
2633                qPos.add(privateLayout);
2634
2635                qPos.add(layoutId);
2636
2637                Long count = null;
2638
2639                Iterator<Long> itr = q.list().iterator();
2640
2641                if (itr.hasNext()) {
2642                    count = itr.next();
2643                }
2644
2645                if (count == null) {
2646                    count = new Long(0);
2647                }
2648
2649                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2650                    finderClassName, finderMethodName, finderParams,
2651                    finderArgs, count);
2652
2653                return count.intValue();
2654            }
2655            catch (Exception e) {
2656                throw processException(e);
2657            }
2658            finally {
2659                closeSession(session);
2660            }
2661        }
2662        else {
2663            return ((Long)result).intValue();
2664        }
2665    }
2666
2667    public int countByG_P_P(long groupId, boolean privateLayout,
2668        long parentLayoutId) throws SystemException {
2669        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
2670        String finderClassName = Layout.class.getName();
2671        String finderMethodName = "countByG_P_P";
2672        String[] finderParams = new String[] {
2673                Long.class.getName(), Boolean.class.getName(),
2674                Long.class.getName()
2675            };
2676        Object[] finderArgs = new Object[] {
2677                new Long(groupId), Boolean.valueOf(privateLayout),
2678                new Long(parentLayoutId)
2679            };
2680
2681        Object result = null;
2682
2683        if (finderClassNameCacheEnabled) {
2684            result = FinderCacheUtil.getResult(finderClassName,
2685                    finderMethodName, finderParams, finderArgs, this);
2686        }
2687
2688        if (result == null) {
2689            Session session = null;
2690
2691            try {
2692                session = openSession();
2693
2694                StringBuilder query = new StringBuilder();
2695
2696                query.append("SELECT COUNT(*) ");
2697                query.append("FROM com.liferay.portal.model.Layout WHERE ");
2698
2699                query.append("groupId = ?");
2700
2701                query.append(" AND ");
2702
2703                query.append("privateLayout = ?");
2704
2705                query.append(" AND ");
2706
2707                query.append("parentLayoutId = ?");
2708
2709                query.append(" ");
2710
2711                Query q = session.createQuery(query.toString());
2712
2713                QueryPos qPos = QueryPos.getInstance(q);
2714
2715                qPos.add(groupId);
2716
2717                qPos.add(privateLayout);
2718
2719                qPos.add(parentLayoutId);
2720
2721                Long count = null;
2722
2723                Iterator<Long> itr = q.list().iterator();
2724
2725                if (itr.hasNext()) {
2726                    count = itr.next();
2727                }
2728
2729                if (count == null) {
2730                    count = new Long(0);
2731                }
2732
2733                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2734                    finderClassName, finderMethodName, finderParams,
2735                    finderArgs, count);
2736
2737                return count.intValue();
2738            }
2739            catch (Exception e) {
2740                throw processException(e);
2741            }
2742            finally {
2743                closeSession(session);
2744            }
2745        }
2746        else {
2747            return ((Long)result).intValue();
2748        }
2749    }
2750
2751    public int countByG_P_F(long groupId, boolean privateLayout,
2752        String friendlyURL) throws SystemException {
2753        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
2754        String finderClassName = Layout.class.getName();
2755        String finderMethodName = "countByG_P_F";
2756        String[] finderParams = new String[] {
2757                Long.class.getName(), Boolean.class.getName(),
2758                String.class.getName()
2759            };
2760        Object[] finderArgs = new Object[] {
2761                new Long(groupId), Boolean.valueOf(privateLayout),
2762                
2763                friendlyURL
2764            };
2765
2766        Object result = null;
2767
2768        if (finderClassNameCacheEnabled) {
2769            result = FinderCacheUtil.getResult(finderClassName,
2770                    finderMethodName, finderParams, finderArgs, this);
2771        }
2772
2773        if (result == null) {
2774            Session session = null;
2775
2776            try {
2777                session = openSession();
2778
2779                StringBuilder query = new StringBuilder();
2780
2781                query.append("SELECT COUNT(*) ");
2782                query.append("FROM com.liferay.portal.model.Layout WHERE ");
2783
2784                query.append("groupId = ?");
2785
2786                query.append(" AND ");
2787
2788                query.append("privateLayout = ?");
2789
2790                query.append(" AND ");
2791
2792                if (friendlyURL == null) {
2793                    query.append("friendlyURL IS NULL");
2794                }
2795                else {
2796                    query.append("lower(friendlyURL) = ?");
2797                }
2798
2799                query.append(" ");
2800
2801                Query q = session.createQuery(query.toString());
2802
2803                QueryPos qPos = QueryPos.getInstance(q);
2804
2805                qPos.add(groupId);
2806
2807                qPos.add(privateLayout);
2808
2809                if (friendlyURL != null) {
2810                    qPos.add(friendlyURL);
2811                }
2812
2813                Long count = null;
2814
2815                Iterator<Long> itr = q.list().iterator();
2816
2817                if (itr.hasNext()) {
2818                    count = itr.next();
2819                }
2820
2821                if (count == null) {
2822                    count = new Long(0);
2823                }
2824
2825                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2826                    finderClassName, finderMethodName, finderParams,
2827                    finderArgs, count);
2828
2829                return count.intValue();
2830            }
2831            catch (Exception e) {
2832                throw processException(e);
2833            }
2834            finally {
2835                closeSession(session);
2836            }
2837        }
2838        else {
2839            return ((Long)result).intValue();
2840        }
2841    }
2842
2843    public int countByG_P_T(long groupId, boolean privateLayout, String type)
2844        throws SystemException {
2845        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
2846        String finderClassName = Layout.class.getName();
2847        String finderMethodName = "countByG_P_T";
2848        String[] finderParams = new String[] {
2849                Long.class.getName(), Boolean.class.getName(),
2850                String.class.getName()
2851            };
2852        Object[] finderArgs = new Object[] {
2853                new Long(groupId), Boolean.valueOf(privateLayout),
2854                
2855                type
2856            };
2857
2858        Object result = null;
2859
2860        if (finderClassNameCacheEnabled) {
2861            result = FinderCacheUtil.getResult(finderClassName,
2862                    finderMethodName, finderParams, finderArgs, this);
2863        }
2864
2865        if (result == null) {
2866            Session session = null;
2867
2868            try {
2869                session = openSession();
2870
2871                StringBuilder query = new StringBuilder();
2872
2873                query.append("SELECT COUNT(*) ");
2874                query.append("FROM com.liferay.portal.model.Layout WHERE ");
2875
2876                query.append("groupId = ?");
2877
2878                query.append(" AND ");
2879
2880                query.append("privateLayout = ?");
2881
2882                query.append(" AND ");
2883
2884                if (type == null) {
2885                    query.append("type_ IS NULL");
2886                }
2887                else {
2888                    query.append("type_ = ?");
2889                }
2890
2891                query.append(" ");
2892
2893                Query q = session.createQuery(query.toString());
2894
2895                QueryPos qPos = QueryPos.getInstance(q);
2896
2897                qPos.add(groupId);
2898
2899                qPos.add(privateLayout);
2900
2901                if (type != null) {
2902                    qPos.add(type);
2903                }
2904
2905                Long count = null;
2906
2907                Iterator<Long> itr = q.list().iterator();
2908
2909                if (itr.hasNext()) {
2910                    count = itr.next();
2911                }
2912
2913                if (count == null) {
2914                    count = new Long(0);
2915                }
2916
2917                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2918                    finderClassName, finderMethodName, finderParams,
2919                    finderArgs, count);
2920
2921                return count.intValue();
2922            }
2923            catch (Exception e) {
2924                throw processException(e);
2925            }
2926            finally {
2927                closeSession(session);
2928            }
2929        }
2930        else {
2931            return ((Long)result).intValue();
2932        }
2933    }
2934
2935    public int countAll() throws SystemException {
2936        boolean finderClassNameCacheEnabled = LayoutModelImpl.CACHE_ENABLED;
2937        String finderClassName = Layout.class.getName();
2938        String finderMethodName = "countAll";
2939        String[] finderParams = new String[] {  };
2940        Object[] finderArgs = new Object[] {  };
2941
2942        Object result = null;
2943
2944        if (finderClassNameCacheEnabled) {
2945            result = FinderCacheUtil.getResult(finderClassName,
2946                    finderMethodName, finderParams, finderArgs, this);
2947        }
2948
2949        if (result == null) {
2950            Session session = null;
2951
2952            try {
2953                session = openSession();
2954
2955                Query q = session.createQuery(
2956                        "SELECT COUNT(*) FROM com.liferay.portal.model.Layout");
2957
2958                Long count = null;
2959
2960                Iterator<Long> itr = q.list().iterator();
2961
2962                if (itr.hasNext()) {
2963                    count = itr.next();
2964                }
2965
2966                if (count == null) {
2967                    count = new Long(0);
2968                }
2969
2970                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2971                    finderClassName, finderMethodName, finderParams,
2972                    finderArgs, count);
2973
2974                return count.intValue();
2975            }
2976            catch (Exception e) {
2977                throw processException(e);
2978            }
2979            finally {
2980                closeSession(session);
2981            }
2982        }
2983        else {
2984            return ((Long)result).intValue();
2985        }
2986    }
2987
2988    public void afterPropertiesSet() {
2989        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2990                    com.liferay.portal.util.PropsUtil.get(
2991                        "value.object.listener.com.liferay.portal.model.Layout")));
2992
2993        if (listenerClassNames.length > 0) {
2994            try {
2995                List<ModelListener> listenersList = new ArrayList<ModelListener>();
2996
2997                for (String listenerClassName : listenerClassNames) {
2998                    listenersList.add((ModelListener)Class.forName(
2999                            listenerClassName).newInstance());
3000                }
3001
3002                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3003            }
3004            catch (Exception e) {
3005                _log.error(e);
3006            }
3007        }
3008    }
3009
3010    @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
3011    protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
3012    @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
3013    protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
3014    @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
3015    protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
3016    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
3017    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
3018    @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
3019    protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
3020    @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
3021    protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
3022    @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
3023    protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
3024    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
3025    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
3026    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
3027    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
3028    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
3029    protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
3030    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
3031    protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
3032    @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
3033    protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
3034    @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
3035    protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
3036    @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
3037    protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
3038    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
3039    protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
3040    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
3041    protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
3042    @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
3043    protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
3044    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
3045    protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
3046    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
3047    protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
3048    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
3049    protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
3050    @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
3051    protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
3052    @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
3053    protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
3054    @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
3055    protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
3056    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
3057    protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
3058    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
3059    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
3060    @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
3061    protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
3062    @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
3063    protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
3064    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
3065    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
3066    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
3067    protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
3068    @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
3069    protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
3070    @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
3071    protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
3072    @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
3073    protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
3074    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
3075    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
3076    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
3077    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
3078    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
3079    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
3080    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
3081    protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
3082    @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
3083    protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
3084    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
3085    protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
3086    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
3087    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
3088    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
3089    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
3090    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
3091    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
3092    @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence.impl")
3093    protected com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence dlFolderPersistence;
3094    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalContentSearchPersistence.impl")
3095    protected com.liferay.portlet.journal.service.persistence.JournalContentSearchPersistence journalContentSearchPersistence;
3096    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence.impl")
3097    protected com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence mbMessagePersistence;
3098    @BeanReference(name = "com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence.impl")
3099    protected com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence ratingsStatsPersistence;
3100    @BeanReference(name = "com.liferay.portlet.tasks.service.persistence.TasksProposalPersistence.impl")
3101    protected com.liferay.portlet.tasks.service.persistence.TasksProposalPersistence tasksProposalPersistence;
3102    private static Log _log = LogFactoryUtil.getLog(LayoutPersistenceImpl.class);
3103}