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