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