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