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