001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchLayoutException;
018    import com.liferay.portal.NoSuchModelException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.SQLQuery;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.exception.SystemException;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
032    import com.liferay.portal.kernel.util.GetterUtil;
033    import com.liferay.portal.kernel.util.InstanceFactory;
034    import com.liferay.portal.kernel.util.OrderByComparator;
035    import com.liferay.portal.kernel.util.StringBundler;
036    import com.liferay.portal.kernel.util.StringPool;
037    import com.liferay.portal.kernel.util.StringUtil;
038    import com.liferay.portal.kernel.util.Validator;
039    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
040    import com.liferay.portal.model.CacheModel;
041    import com.liferay.portal.model.Layout;
042    import com.liferay.portal.model.ModelListener;
043    import com.liferay.portal.model.impl.LayoutImpl;
044    import com.liferay.portal.model.impl.LayoutModelImpl;
045    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
046    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
047    
048    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
049    import com.liferay.portlet.journal.service.persistence.JournalArticlePersistence;
050    import com.liferay.portlet.journal.service.persistence.JournalContentSearchPersistence;
051    import com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence;
052    import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
053    
054    import java.io.Serializable;
055    
056    import java.util.ArrayList;
057    import java.util.Collections;
058    import java.util.List;
059    
060    /**
061     * The persistence implementation for the layout service.
062     *
063     * <p>
064     * Caching information and settings can be found in <code>portal.properties</code>
065     * </p>
066     *
067     * @author Brian Wing Shun Chan
068     * @see LayoutPersistence
069     * @see LayoutUtil
070     * @generated
071     */
072    public class LayoutPersistenceImpl extends BasePersistenceImpl<Layout>
073            implements LayoutPersistence {
074            /*
075             * NOTE FOR DEVELOPERS:
076             *
077             * Never modify or reference this class directly. Always use {@link LayoutUtil} to access the layout persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
078             */
079            public static final String FINDER_CLASS_NAME_ENTITY = LayoutImpl.class.getName();
080            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List1";
082            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List2";
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
085                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
087                            new String[] {
088                                    String.class.getName(),
089                                    
090                            "java.lang.Integer", "java.lang.Integer",
091                                    "com.liferay.portal.kernel.util.OrderByComparator"
092                            });
093            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
094                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
096                            new String[] { String.class.getName() },
097                            LayoutModelImpl.UUID_COLUMN_BITMASK);
098            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
099                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
101                            new String[] { String.class.getName() });
102            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
103                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
104                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
105                            new String[] { String.class.getName(), Long.class.getName() },
106                            LayoutModelImpl.UUID_COLUMN_BITMASK |
107                            LayoutModelImpl.GROUPID_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
109                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
111                            new String[] { String.class.getName(), Long.class.getName() });
112            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
113                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
114                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
115                            new String[] {
116                                    Long.class.getName(),
117                                    
118                            "java.lang.Integer", "java.lang.Integer",
119                                    "com.liferay.portal.kernel.util.OrderByComparator"
120                            });
121            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
122                    new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
123                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
124                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
125                            new String[] { Long.class.getName() },
126                            LayoutModelImpl.GROUPID_COLUMN_BITMASK);
127            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
128                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
129                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
130                            new String[] { Long.class.getName() });
131            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
132                    new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
133                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
134                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
135                            new String[] {
136                                    Long.class.getName(),
137                                    
138                            "java.lang.Integer", "java.lang.Integer",
139                                    "com.liferay.portal.kernel.util.OrderByComparator"
140                            });
141            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
142                    new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
143                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
144                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
145                            new String[] { Long.class.getName() },
146                            LayoutModelImpl.COMPANYID_COLUMN_BITMASK);
147            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
148                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
149                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
150                            new String[] { Long.class.getName() });
151            public static final FinderPath FINDER_PATH_FETCH_BY_ICONIMAGEID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
152                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
153                            FINDER_CLASS_NAME_ENTITY, "fetchByIconImageId",
154                            new String[] { Long.class.getName() },
155                            LayoutModelImpl.ICONIMAGEID_COLUMN_BITMASK);
156            public static final FinderPath FINDER_PATH_COUNT_BY_ICONIMAGEID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
157                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
158                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByIconImageId",
159                            new String[] { Long.class.getName() });
160            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
161                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
162                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
163                            new String[] {
164                                    Long.class.getName(), Boolean.class.getName(),
165                                    
166                            "java.lang.Integer", "java.lang.Integer",
167                                    "com.liferay.portal.kernel.util.OrderByComparator"
168                            });
169            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
170                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
171                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
172                            new String[] { Long.class.getName(), Boolean.class.getName() },
173                            LayoutModelImpl.GROUPID_COLUMN_BITMASK |
174                            LayoutModelImpl.PRIVATELAYOUT_COLUMN_BITMASK);
175            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
176                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
177                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
178                            new String[] { Long.class.getName(), Boolean.class.getName() });
179            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_L = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
180                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
181                            FINDER_CLASS_NAME_ENTITY, "fetchByG_P_L",
182                            new String[] {
183                                    Long.class.getName(), Boolean.class.getName(),
184                                    Long.class.getName()
185                            },
186                            LayoutModelImpl.GROUPID_COLUMN_BITMASK |
187                            LayoutModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
188                            LayoutModelImpl.LAYOUTID_COLUMN_BITMASK);
189            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_L = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
190                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
191                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_L",
192                            new String[] {
193                                    Long.class.getName(), Boolean.class.getName(),
194                                    Long.class.getName()
195                            });
196            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
197                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
198                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_P",
199                            new String[] {
200                                    Long.class.getName(), Boolean.class.getName(),
201                                    Long.class.getName(),
202                                    
203                            "java.lang.Integer", "java.lang.Integer",
204                                    "com.liferay.portal.kernel.util.OrderByComparator"
205                            });
206            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
207                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
208                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_P",
209                            new String[] {
210                                    Long.class.getName(), Boolean.class.getName(),
211                                    Long.class.getName()
212                            },
213                            LayoutModelImpl.GROUPID_COLUMN_BITMASK |
214                            LayoutModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
215                            LayoutModelImpl.PARENTLAYOUTID_COLUMN_BITMASK);
216            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
217                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
218                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_P",
219                            new String[] {
220                                    Long.class.getName(), Boolean.class.getName(),
221                                    Long.class.getName()
222                            });
223            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_F = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
224                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
225                            FINDER_CLASS_NAME_ENTITY, "fetchByG_P_F",
226                            new String[] {
227                                    Long.class.getName(), Boolean.class.getName(),
228                                    String.class.getName()
229                            },
230                            LayoutModelImpl.GROUPID_COLUMN_BITMASK |
231                            LayoutModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
232                            LayoutModelImpl.FRIENDLYURL_COLUMN_BITMASK);
233            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_F = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
234                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
235                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_F",
236                            new String[] {
237                                    Long.class.getName(), Boolean.class.getName(),
238                                    String.class.getName()
239                            });
240            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_T = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
241                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
242                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_T",
243                            new String[] {
244                                    Long.class.getName(), Boolean.class.getName(),
245                                    String.class.getName(),
246                                    
247                            "java.lang.Integer", "java.lang.Integer",
248                                    "com.liferay.portal.kernel.util.OrderByComparator"
249                            });
250            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_T = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
251                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
252                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_T",
253                            new String[] {
254                                    Long.class.getName(), Boolean.class.getName(),
255                                    String.class.getName()
256                            },
257                            LayoutModelImpl.GROUPID_COLUMN_BITMASK |
258                            LayoutModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
259                            LayoutModelImpl.TYPE_COLUMN_BITMASK);
260            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_T = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
261                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
262                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_T",
263                            new String[] {
264                                    Long.class.getName(), Boolean.class.getName(),
265                                    String.class.getName()
266                            });
267            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_TLU = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
268                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
269                            FINDER_CLASS_NAME_ENTITY, "fetchByG_P_TLU",
270                            new String[] {
271                                    Long.class.getName(), Boolean.class.getName(),
272                                    String.class.getName()
273                            },
274                            LayoutModelImpl.GROUPID_COLUMN_BITMASK |
275                            LayoutModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
276                            LayoutModelImpl.TEMPLATELAYOUTUUID_COLUMN_BITMASK);
277            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_TLU = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
278                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
279                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_TLU",
280                            new String[] {
281                                    Long.class.getName(), Boolean.class.getName(),
282                                    String.class.getName()
283                            });
284            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
285                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
286                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
287            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
288                            LayoutModelImpl.FINDER_CACHE_ENABLED, LayoutImpl.class,
289                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
290            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
291                            LayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
292                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
293    
294            /**
295             * Caches the layout in the entity cache if it is enabled.
296             *
297             * @param layout the layout
298             */
299            public void cacheResult(Layout layout) {
300                    EntityCacheUtil.putResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
301                            LayoutImpl.class, layout.getPrimaryKey(), layout);
302    
303                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
304                            new Object[] { layout.getUuid(), Long.valueOf(layout.getGroupId()) },
305                            layout);
306    
307                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
308                            new Object[] { Long.valueOf(layout.getIconImageId()) }, layout);
309    
310                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L,
311                            new Object[] {
312                                    Long.valueOf(layout.getGroupId()),
313                                    Boolean.valueOf(layout.getPrivateLayout()),
314                                    Long.valueOf(layout.getLayoutId())
315                            }, layout);
316    
317                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_F,
318                            new Object[] {
319                                    Long.valueOf(layout.getGroupId()),
320                                    Boolean.valueOf(layout.getPrivateLayout()),
321                                    
322                            layout.getFriendlyURL()
323                            }, layout);
324    
325                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_TLU,
326                            new Object[] {
327                                    Long.valueOf(layout.getGroupId()),
328                                    Boolean.valueOf(layout.getPrivateLayout()),
329                                    
330                            layout.getTemplateLayoutUuid()
331                            }, layout);
332    
333                    layout.resetOriginalValues();
334            }
335    
336            /**
337             * Caches the layouts in the entity cache if it is enabled.
338             *
339             * @param layouts the layouts
340             */
341            public void cacheResult(List<Layout> layouts) {
342                    for (Layout layout : layouts) {
343                            if (EntityCacheUtil.getResult(
344                                                    LayoutModelImpl.ENTITY_CACHE_ENABLED, LayoutImpl.class,
345                                                    layout.getPrimaryKey()) == null) {
346                                    cacheResult(layout);
347                            }
348                            else {
349                                    layout.resetOriginalValues();
350                            }
351                    }
352            }
353    
354            /**
355             * Clears the cache for all layouts.
356             *
357             * <p>
358             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
359             * </p>
360             */
361            @Override
362            public void clearCache() {
363                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
364                            CacheRegistryUtil.clear(LayoutImpl.class.getName());
365                    }
366    
367                    EntityCacheUtil.clearCache(LayoutImpl.class.getName());
368    
369                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
370                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
371                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
372            }
373    
374            /**
375             * Clears the cache for the layout.
376             *
377             * <p>
378             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
379             * </p>
380             */
381            @Override
382            public void clearCache(Layout layout) {
383                    EntityCacheUtil.removeResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
384                            LayoutImpl.class, layout.getPrimaryKey());
385    
386                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
387                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
388    
389                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
390                            new Object[] { layout.getUuid(), Long.valueOf(layout.getGroupId()) });
391    
392                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
393                            new Object[] { Long.valueOf(layout.getIconImageId()) });
394    
395                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_L,
396                            new Object[] {
397                                    Long.valueOf(layout.getGroupId()),
398                                    Boolean.valueOf(layout.getPrivateLayout()),
399                                    Long.valueOf(layout.getLayoutId())
400                            });
401    
402                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_F,
403                            new Object[] {
404                                    Long.valueOf(layout.getGroupId()),
405                                    Boolean.valueOf(layout.getPrivateLayout()),
406                                    
407                            layout.getFriendlyURL()
408                            });
409    
410                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_TLU,
411                            new Object[] {
412                                    Long.valueOf(layout.getGroupId()),
413                                    Boolean.valueOf(layout.getPrivateLayout()),
414                                    
415                            layout.getTemplateLayoutUuid()
416                            });
417            }
418    
419            /**
420             * Creates a new layout with the primary key. Does not add the layout to the database.
421             *
422             * @param plid the primary key for the new layout
423             * @return the new layout
424             */
425            public Layout create(long plid) {
426                    Layout layout = new LayoutImpl();
427    
428                    layout.setNew(true);
429                    layout.setPrimaryKey(plid);
430    
431                    String uuid = PortalUUIDUtil.generate();
432    
433                    layout.setUuid(uuid);
434    
435                    return layout;
436            }
437    
438            /**
439             * Removes the layout with the primary key from the database. Also notifies the appropriate model listeners.
440             *
441             * @param primaryKey the primary key of the layout
442             * @return the layout that was removed
443             * @throws com.liferay.portal.NoSuchModelException if a layout with the primary key could not be found
444             * @throws SystemException if a system exception occurred
445             */
446            @Override
447            public Layout remove(Serializable primaryKey)
448                    throws NoSuchModelException, SystemException {
449                    return remove(((Long)primaryKey).longValue());
450            }
451    
452            /**
453             * Removes the layout with the primary key from the database. Also notifies the appropriate model listeners.
454             *
455             * @param plid the primary key of the layout
456             * @return the layout that was removed
457             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
458             * @throws SystemException if a system exception occurred
459             */
460            public Layout remove(long plid)
461                    throws NoSuchLayoutException, SystemException {
462                    Session session = null;
463    
464                    try {
465                            session = openSession();
466    
467                            Layout layout = (Layout)session.get(LayoutImpl.class,
468                                            Long.valueOf(plid));
469    
470                            if (layout == null) {
471                                    if (_log.isWarnEnabled()) {
472                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + plid);
473                                    }
474    
475                                    throw new NoSuchLayoutException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
476                                            plid);
477                            }
478    
479                            return layoutPersistence.remove(layout);
480                    }
481                    catch (NoSuchLayoutException nsee) {
482                            throw nsee;
483                    }
484                    catch (Exception e) {
485                            throw processException(e);
486                    }
487                    finally {
488                            closeSession(session);
489                    }
490            }
491    
492            /**
493             * Removes the layout from the database. Also notifies the appropriate model listeners.
494             *
495             * @param layout the layout
496             * @return the layout that was removed
497             * @throws SystemException if a system exception occurred
498             */
499            @Override
500            public Layout remove(Layout layout) throws SystemException {
501                    return super.remove(layout);
502            }
503    
504            @Override
505            protected Layout removeImpl(Layout layout) throws SystemException {
506                    layout = toUnwrappedModel(layout);
507    
508                    Session session = null;
509    
510                    try {
511                            session = openSession();
512    
513                            BatchSessionUtil.delete(session, layout);
514                    }
515                    catch (Exception e) {
516                            throw processException(e);
517                    }
518                    finally {
519                            closeSession(session);
520                    }
521    
522                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
523                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
524    
525                    LayoutModelImpl layoutModelImpl = (LayoutModelImpl)layout;
526    
527                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
528                            new Object[] {
529                                    layoutModelImpl.getUuid(),
530                                    Long.valueOf(layoutModelImpl.getGroupId())
531                            });
532    
533                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
534                            new Object[] { Long.valueOf(layoutModelImpl.getIconImageId()) });
535    
536                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_L,
537                            new Object[] {
538                                    Long.valueOf(layoutModelImpl.getGroupId()),
539                                    Boolean.valueOf(layoutModelImpl.getPrivateLayout()),
540                                    Long.valueOf(layoutModelImpl.getLayoutId())
541                            });
542    
543                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_F,
544                            new Object[] {
545                                    Long.valueOf(layoutModelImpl.getGroupId()),
546                                    Boolean.valueOf(layoutModelImpl.getPrivateLayout()),
547                                    
548                            layoutModelImpl.getFriendlyURL()
549                            });
550    
551                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_TLU,
552                            new Object[] {
553                                    Long.valueOf(layoutModelImpl.getGroupId()),
554                                    Boolean.valueOf(layoutModelImpl.getPrivateLayout()),
555                                    
556                            layoutModelImpl.getTemplateLayoutUuid()
557                            });
558    
559                    EntityCacheUtil.removeResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
560                            LayoutImpl.class, layout.getPrimaryKey());
561    
562                    return layout;
563            }
564    
565            @Override
566            public Layout updateImpl(com.liferay.portal.model.Layout layout,
567                    boolean merge) throws SystemException {
568                    layout = toUnwrappedModel(layout);
569    
570                    boolean isNew = layout.isNew();
571    
572                    LayoutModelImpl layoutModelImpl = (LayoutModelImpl)layout;
573    
574                    if (Validator.isNull(layout.getUuid())) {
575                            String uuid = PortalUUIDUtil.generate();
576    
577                            layout.setUuid(uuid);
578                    }
579    
580                    Session session = null;
581    
582                    try {
583                            session = openSession();
584    
585                            BatchSessionUtil.update(session, layout, merge);
586    
587                            layout.setNew(false);
588                    }
589                    catch (Exception e) {
590                            throw processException(e);
591                    }
592                    finally {
593                            closeSession(session);
594                    }
595    
596                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
597    
598                    if (isNew || !LayoutModelImpl.COLUMN_BITMASK_ENABLED) {
599                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
600                    }
601    
602                    else {
603                            if ((layoutModelImpl.getColumnBitmask() &
604                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
605                                    Object[] args = new Object[] { layoutModelImpl.getOriginalUuid() };
606    
607                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
608                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
609                                            args);
610    
611                                    args = new Object[] { layoutModelImpl.getUuid() };
612    
613                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
614                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
615                                            args);
616                            }
617    
618                            if ((layoutModelImpl.getColumnBitmask() &
619                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
620                                    Object[] args = new Object[] {
621                                                    Long.valueOf(layoutModelImpl.getOriginalGroupId())
622                                            };
623    
624                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
625                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
626                                            args);
627    
628                                    args = new Object[] { Long.valueOf(layoutModelImpl.getGroupId()) };
629    
630                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
631                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
632                                            args);
633                            }
634    
635                            if ((layoutModelImpl.getColumnBitmask() &
636                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
637                                    Object[] args = new Object[] {
638                                                    Long.valueOf(layoutModelImpl.getOriginalCompanyId())
639                                            };
640    
641                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
642                                            args);
643                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
644                                            args);
645    
646                                    args = new Object[] { Long.valueOf(layoutModelImpl.getCompanyId()) };
647    
648                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
649                                            args);
650                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
651                                            args);
652                            }
653    
654                            if ((layoutModelImpl.getColumnBitmask() &
655                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
656                                    Object[] args = new Object[] {
657                                                    Long.valueOf(layoutModelImpl.getOriginalGroupId()),
658                                                    Boolean.valueOf(layoutModelImpl.getOriginalPrivateLayout())
659                                            };
660    
661                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
662                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
663                                            args);
664    
665                                    args = new Object[] {
666                                                    Long.valueOf(layoutModelImpl.getGroupId()),
667                                                    Boolean.valueOf(layoutModelImpl.getPrivateLayout())
668                                            };
669    
670                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
671                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
672                                            args);
673                            }
674    
675                            if ((layoutModelImpl.getColumnBitmask() &
676                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_P.getColumnBitmask()) != 0) {
677                                    Object[] args = new Object[] {
678                                                    Long.valueOf(layoutModelImpl.getOriginalGroupId()),
679                                                    Boolean.valueOf(layoutModelImpl.getOriginalPrivateLayout()),
680                                                    Long.valueOf(layoutModelImpl.getOriginalParentLayoutId())
681                                            };
682    
683                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_P, args);
684                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_P,
685                                            args);
686    
687                                    args = new Object[] {
688                                                    Long.valueOf(layoutModelImpl.getGroupId()),
689                                                    Boolean.valueOf(layoutModelImpl.getPrivateLayout()),
690                                                    Long.valueOf(layoutModelImpl.getParentLayoutId())
691                                            };
692    
693                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_P, args);
694                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_P,
695                                            args);
696                            }
697    
698                            if ((layoutModelImpl.getColumnBitmask() &
699                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_T.getColumnBitmask()) != 0) {
700                                    Object[] args = new Object[] {
701                                                    Long.valueOf(layoutModelImpl.getOriginalGroupId()),
702                                                    Boolean.valueOf(layoutModelImpl.getOriginalPrivateLayout()),
703                                                    
704                                                    layoutModelImpl.getOriginalType()
705                                            };
706    
707                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_T, args);
708                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_T,
709                                            args);
710    
711                                    args = new Object[] {
712                                                    Long.valueOf(layoutModelImpl.getGroupId()),
713                                                    Boolean.valueOf(layoutModelImpl.getPrivateLayout()),
714                                                    
715                                                    layoutModelImpl.getType()
716                                            };
717    
718                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_T, args);
719                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_T,
720                                            args);
721                            }
722                    }
723    
724                    EntityCacheUtil.putResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
725                            LayoutImpl.class, layout.getPrimaryKey(), layout);
726    
727                    if (isNew) {
728                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
729                                    new Object[] { layout.getUuid(), Long.valueOf(
730                                                    layout.getGroupId()) }, layout);
731    
732                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
733                                    new Object[] { Long.valueOf(layout.getIconImageId()) }, layout);
734    
735                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L,
736                                    new Object[] {
737                                            Long.valueOf(layout.getGroupId()),
738                                            Boolean.valueOf(layout.getPrivateLayout()),
739                                            Long.valueOf(layout.getLayoutId())
740                                    }, layout);
741    
742                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_F,
743                                    new Object[] {
744                                            Long.valueOf(layout.getGroupId()),
745                                            Boolean.valueOf(layout.getPrivateLayout()),
746                                            
747                                    layout.getFriendlyURL()
748                                    }, layout);
749    
750                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_TLU,
751                                    new Object[] {
752                                            Long.valueOf(layout.getGroupId()),
753                                            Boolean.valueOf(layout.getPrivateLayout()),
754                                            
755                                    layout.getTemplateLayoutUuid()
756                                    }, layout);
757                    }
758                    else {
759                            if ((layoutModelImpl.getColumnBitmask() &
760                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
761                                    Object[] args = new Object[] {
762                                                    layoutModelImpl.getOriginalUuid(),
763                                                    Long.valueOf(layoutModelImpl.getOriginalGroupId())
764                                            };
765    
766                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
767                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
768    
769                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
770                                            new Object[] {
771                                                    layout.getUuid(), Long.valueOf(layout.getGroupId())
772                                            }, layout);
773                            }
774    
775                            if ((layoutModelImpl.getColumnBitmask() &
776                                            FINDER_PATH_FETCH_BY_ICONIMAGEID.getColumnBitmask()) != 0) {
777                                    Object[] args = new Object[] {
778                                                    Long.valueOf(layoutModelImpl.getOriginalIconImageId())
779                                            };
780    
781                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ICONIMAGEID,
782                                            args);
783                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
784                                            args);
785    
786                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
787                                            new Object[] { Long.valueOf(layout.getIconImageId()) },
788                                            layout);
789                            }
790    
791                            if ((layoutModelImpl.getColumnBitmask() &
792                                            FINDER_PATH_FETCH_BY_G_P_L.getColumnBitmask()) != 0) {
793                                    Object[] args = new Object[] {
794                                                    Long.valueOf(layoutModelImpl.getOriginalGroupId()),
795                                                    Boolean.valueOf(layoutModelImpl.getOriginalPrivateLayout()),
796                                                    Long.valueOf(layoutModelImpl.getOriginalLayoutId())
797                                            };
798    
799                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_L, args);
800                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_L, args);
801    
802                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L,
803                                            new Object[] {
804                                                    Long.valueOf(layout.getGroupId()),
805                                                    Boolean.valueOf(layout.getPrivateLayout()),
806                                                    Long.valueOf(layout.getLayoutId())
807                                            }, layout);
808                            }
809    
810                            if ((layoutModelImpl.getColumnBitmask() &
811                                            FINDER_PATH_FETCH_BY_G_P_F.getColumnBitmask()) != 0) {
812                                    Object[] args = new Object[] {
813                                                    Long.valueOf(layoutModelImpl.getOriginalGroupId()),
814                                                    Boolean.valueOf(layoutModelImpl.getOriginalPrivateLayout()),
815                                                    
816                                                    layoutModelImpl.getOriginalFriendlyURL()
817                                            };
818    
819                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_F, args);
820                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_F, args);
821    
822                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_F,
823                                            new Object[] {
824                                                    Long.valueOf(layout.getGroupId()),
825                                                    Boolean.valueOf(layout.getPrivateLayout()),
826                                                    
827                                            layout.getFriendlyURL()
828                                            }, layout);
829                            }
830    
831                            if ((layoutModelImpl.getColumnBitmask() &
832                                            FINDER_PATH_FETCH_BY_G_P_TLU.getColumnBitmask()) != 0) {
833                                    Object[] args = new Object[] {
834                                                    Long.valueOf(layoutModelImpl.getOriginalGroupId()),
835                                                    Boolean.valueOf(layoutModelImpl.getOriginalPrivateLayout()),
836                                                    
837                                                    layoutModelImpl.getOriginalTemplateLayoutUuid()
838                                            };
839    
840                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_TLU, args);
841                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_TLU, args);
842    
843                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_TLU,
844                                            new Object[] {
845                                                    Long.valueOf(layout.getGroupId()),
846                                                    Boolean.valueOf(layout.getPrivateLayout()),
847                                                    
848                                            layout.getTemplateLayoutUuid()
849                                            }, layout);
850                            }
851                    }
852    
853                    return layout;
854            }
855    
856            protected Layout toUnwrappedModel(Layout layout) {
857                    if (layout instanceof LayoutImpl) {
858                            return layout;
859                    }
860    
861                    LayoutImpl layoutImpl = new LayoutImpl();
862    
863                    layoutImpl.setNew(layout.isNew());
864                    layoutImpl.setPrimaryKey(layout.getPrimaryKey());
865    
866                    layoutImpl.setUuid(layout.getUuid());
867                    layoutImpl.setPlid(layout.getPlid());
868                    layoutImpl.setGroupId(layout.getGroupId());
869                    layoutImpl.setCompanyId(layout.getCompanyId());
870                    layoutImpl.setCreateDate(layout.getCreateDate());
871                    layoutImpl.setModifiedDate(layout.getModifiedDate());
872                    layoutImpl.setPrivateLayout(layout.isPrivateLayout());
873                    layoutImpl.setLayoutId(layout.getLayoutId());
874                    layoutImpl.setParentLayoutId(layout.getParentLayoutId());
875                    layoutImpl.setName(layout.getName());
876                    layoutImpl.setTitle(layout.getTitle());
877                    layoutImpl.setDescription(layout.getDescription());
878                    layoutImpl.setKeywords(layout.getKeywords());
879                    layoutImpl.setRobots(layout.getRobots());
880                    layoutImpl.setType(layout.getType());
881                    layoutImpl.setTypeSettings(layout.getTypeSettings());
882                    layoutImpl.setHidden(layout.isHidden());
883                    layoutImpl.setFriendlyURL(layout.getFriendlyURL());
884                    layoutImpl.setIconImage(layout.isIconImage());
885                    layoutImpl.setIconImageId(layout.getIconImageId());
886                    layoutImpl.setThemeId(layout.getThemeId());
887                    layoutImpl.setColorSchemeId(layout.getColorSchemeId());
888                    layoutImpl.setWapThemeId(layout.getWapThemeId());
889                    layoutImpl.setWapColorSchemeId(layout.getWapColorSchemeId());
890                    layoutImpl.setCss(layout.getCss());
891                    layoutImpl.setPriority(layout.getPriority());
892                    layoutImpl.setLayoutPrototypeUuid(layout.getLayoutPrototypeUuid());
893                    layoutImpl.setLayoutPrototypeLinkEnabled(layout.isLayoutPrototypeLinkEnabled());
894                    layoutImpl.setTemplateLayoutUuid(layout.getTemplateLayoutUuid());
895    
896                    return layoutImpl;
897            }
898    
899            /**
900             * Returns the layout with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
901             *
902             * @param primaryKey the primary key of the layout
903             * @return the layout
904             * @throws com.liferay.portal.NoSuchModelException if a layout with the primary key could not be found
905             * @throws SystemException if a system exception occurred
906             */
907            @Override
908            public Layout findByPrimaryKey(Serializable primaryKey)
909                    throws NoSuchModelException, SystemException {
910                    return findByPrimaryKey(((Long)primaryKey).longValue());
911            }
912    
913            /**
914             * Returns the layout with the primary key or throws a {@link com.liferay.portal.NoSuchLayoutException} if it could not be found.
915             *
916             * @param plid the primary key of the layout
917             * @return the layout
918             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
919             * @throws SystemException if a system exception occurred
920             */
921            public Layout findByPrimaryKey(long plid)
922                    throws NoSuchLayoutException, SystemException {
923                    Layout layout = fetchByPrimaryKey(plid);
924    
925                    if (layout == null) {
926                            if (_log.isWarnEnabled()) {
927                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + plid);
928                            }
929    
930                            throw new NoSuchLayoutException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
931                                    plid);
932                    }
933    
934                    return layout;
935            }
936    
937            /**
938             * Returns the layout with the primary key or returns <code>null</code> if it could not be found.
939             *
940             * @param primaryKey the primary key of the layout
941             * @return the layout, or <code>null</code> if a layout with the primary key could not be found
942             * @throws SystemException if a system exception occurred
943             */
944            @Override
945            public Layout fetchByPrimaryKey(Serializable primaryKey)
946                    throws SystemException {
947                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
948            }
949    
950            /**
951             * Returns the layout with the primary key or returns <code>null</code> if it could not be found.
952             *
953             * @param plid the primary key of the layout
954             * @return the layout, or <code>null</code> if a layout with the primary key could not be found
955             * @throws SystemException if a system exception occurred
956             */
957            public Layout fetchByPrimaryKey(long plid) throws SystemException {
958                    Layout layout = (Layout)EntityCacheUtil.getResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
959                                    LayoutImpl.class, plid);
960    
961                    if (layout == _nullLayout) {
962                            return null;
963                    }
964    
965                    if (layout == null) {
966                            Session session = null;
967    
968                            boolean hasException = false;
969    
970                            try {
971                                    session = openSession();
972    
973                                    layout = (Layout)session.get(LayoutImpl.class,
974                                                    Long.valueOf(plid));
975                            }
976                            catch (Exception e) {
977                                    hasException = true;
978    
979                                    throw processException(e);
980                            }
981                            finally {
982                                    if (layout != null) {
983                                            cacheResult(layout);
984                                    }
985                                    else if (!hasException) {
986                                            EntityCacheUtil.putResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
987                                                    LayoutImpl.class, plid, _nullLayout);
988                                    }
989    
990                                    closeSession(session);
991                            }
992                    }
993    
994                    return layout;
995            }
996    
997            /**
998             * Returns all the layouts where uuid = &#63;.
999             *
1000             * @param uuid the uuid
1001             * @return the matching layouts
1002             * @throws SystemException if a system exception occurred
1003             */
1004            public List<Layout> findByUuid(String uuid) throws SystemException {
1005                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1006            }
1007    
1008            /**
1009             * Returns a range of all the layouts where uuid = &#63;.
1010             *
1011             * <p>
1012             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1013             * </p>
1014             *
1015             * @param uuid the uuid
1016             * @param start the lower bound of the range of layouts
1017             * @param end the upper bound of the range of layouts (not inclusive)
1018             * @return the range of matching layouts
1019             * @throws SystemException if a system exception occurred
1020             */
1021            public List<Layout> findByUuid(String uuid, int start, int end)
1022                    throws SystemException {
1023                    return findByUuid(uuid, start, end, null);
1024            }
1025    
1026            /**
1027             * Returns an ordered range of all the layouts where uuid = &#63;.
1028             *
1029             * <p>
1030             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1031             * </p>
1032             *
1033             * @param uuid the uuid
1034             * @param start the lower bound of the range of layouts
1035             * @param end the upper bound of the range of layouts (not inclusive)
1036             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1037             * @return the ordered range of matching layouts
1038             * @throws SystemException if a system exception occurred
1039             */
1040            public List<Layout> findByUuid(String uuid, int start, int end,
1041                    OrderByComparator orderByComparator) throws SystemException {
1042                    FinderPath finderPath = null;
1043                    Object[] finderArgs = null;
1044    
1045                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1046                                    (orderByComparator == null)) {
1047                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
1048                            finderArgs = new Object[] { uuid };
1049                    }
1050                    else {
1051                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
1052                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
1053                    }
1054    
1055                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(finderPath,
1056                                    finderArgs, this);
1057    
1058                    if (list == null) {
1059                            StringBundler query = null;
1060    
1061                            if (orderByComparator != null) {
1062                                    query = new StringBundler(3 +
1063                                                    (orderByComparator.getOrderByFields().length * 3));
1064                            }
1065                            else {
1066                                    query = new StringBundler(3);
1067                            }
1068    
1069                            query.append(_SQL_SELECT_LAYOUT_WHERE);
1070    
1071                            if (uuid == null) {
1072                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1073                            }
1074                            else {
1075                                    if (uuid.equals(StringPool.BLANK)) {
1076                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1077                                    }
1078                                    else {
1079                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1080                                    }
1081                            }
1082    
1083                            if (orderByComparator != null) {
1084                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1085                                            orderByComparator);
1086                            }
1087    
1088                            else {
1089                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
1090                            }
1091    
1092                            String sql = query.toString();
1093    
1094                            Session session = null;
1095    
1096                            try {
1097                                    session = openSession();
1098    
1099                                    Query q = session.createQuery(sql);
1100    
1101                                    QueryPos qPos = QueryPos.getInstance(q);
1102    
1103                                    if (uuid != null) {
1104                                            qPos.add(uuid);
1105                                    }
1106    
1107                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
1108                            }
1109                            catch (Exception e) {
1110                                    throw processException(e);
1111                            }
1112                            finally {
1113                                    if (list == null) {
1114                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1115                                    }
1116                                    else {
1117                                            cacheResult(list);
1118    
1119                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1120                                    }
1121    
1122                                    closeSession(session);
1123                            }
1124                    }
1125    
1126                    return list;
1127            }
1128    
1129            /**
1130             * Returns the first layout in the ordered set where uuid = &#63;.
1131             *
1132             * <p>
1133             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1134             * </p>
1135             *
1136             * @param uuid the uuid
1137             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1138             * @return the first matching layout
1139             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1140             * @throws SystemException if a system exception occurred
1141             */
1142            public Layout findByUuid_First(String uuid,
1143                    OrderByComparator orderByComparator)
1144                    throws NoSuchLayoutException, SystemException {
1145                    List<Layout> list = findByUuid(uuid, 0, 1, orderByComparator);
1146    
1147                    if (list.isEmpty()) {
1148                            StringBundler msg = new StringBundler(4);
1149    
1150                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1151    
1152                            msg.append("uuid=");
1153                            msg.append(uuid);
1154    
1155                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1156    
1157                            throw new NoSuchLayoutException(msg.toString());
1158                    }
1159                    else {
1160                            return list.get(0);
1161                    }
1162            }
1163    
1164            /**
1165             * Returns the last layout in the ordered set where uuid = &#63;.
1166             *
1167             * <p>
1168             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1169             * </p>
1170             *
1171             * @param uuid the uuid
1172             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1173             * @return the last matching layout
1174             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1175             * @throws SystemException if a system exception occurred
1176             */
1177            public Layout findByUuid_Last(String uuid,
1178                    OrderByComparator orderByComparator)
1179                    throws NoSuchLayoutException, SystemException {
1180                    int count = countByUuid(uuid);
1181    
1182                    List<Layout> list = findByUuid(uuid, count - 1, count, orderByComparator);
1183    
1184                    if (list.isEmpty()) {
1185                            StringBundler msg = new StringBundler(4);
1186    
1187                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1188    
1189                            msg.append("uuid=");
1190                            msg.append(uuid);
1191    
1192                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1193    
1194                            throw new NoSuchLayoutException(msg.toString());
1195                    }
1196                    else {
1197                            return list.get(0);
1198                    }
1199            }
1200    
1201            /**
1202             * Returns the layouts before and after the current layout in the ordered set where uuid = &#63;.
1203             *
1204             * <p>
1205             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1206             * </p>
1207             *
1208             * @param plid the primary key of the current layout
1209             * @param uuid the uuid
1210             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1211             * @return the previous, current, and next layout
1212             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
1213             * @throws SystemException if a system exception occurred
1214             */
1215            public Layout[] findByUuid_PrevAndNext(long plid, String uuid,
1216                    OrderByComparator orderByComparator)
1217                    throws NoSuchLayoutException, SystemException {
1218                    Layout layout = findByPrimaryKey(plid);
1219    
1220                    Session session = null;
1221    
1222                    try {
1223                            session = openSession();
1224    
1225                            Layout[] array = new LayoutImpl[3];
1226    
1227                            array[0] = getByUuid_PrevAndNext(session, layout, uuid,
1228                                            orderByComparator, true);
1229    
1230                            array[1] = layout;
1231    
1232                            array[2] = getByUuid_PrevAndNext(session, layout, uuid,
1233                                            orderByComparator, false);
1234    
1235                            return array;
1236                    }
1237                    catch (Exception e) {
1238                            throw processException(e);
1239                    }
1240                    finally {
1241                            closeSession(session);
1242                    }
1243            }
1244    
1245            protected Layout getByUuid_PrevAndNext(Session session, Layout layout,
1246                    String uuid, OrderByComparator orderByComparator, boolean previous) {
1247                    StringBundler query = null;
1248    
1249                    if (orderByComparator != null) {
1250                            query = new StringBundler(6 +
1251                                            (orderByComparator.getOrderByFields().length * 6));
1252                    }
1253                    else {
1254                            query = new StringBundler(3);
1255                    }
1256    
1257                    query.append(_SQL_SELECT_LAYOUT_WHERE);
1258    
1259                    if (uuid == null) {
1260                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1261                    }
1262                    else {
1263                            if (uuid.equals(StringPool.BLANK)) {
1264                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1265                            }
1266                            else {
1267                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1268                            }
1269                    }
1270    
1271                    if (orderByComparator != null) {
1272                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1273    
1274                            if (orderByConditionFields.length > 0) {
1275                                    query.append(WHERE_AND);
1276                            }
1277    
1278                            for (int i = 0; i < orderByConditionFields.length; i++) {
1279                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1280                                    query.append(orderByConditionFields[i]);
1281    
1282                                    if ((i + 1) < orderByConditionFields.length) {
1283                                            if (orderByComparator.isAscending() ^ previous) {
1284                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1285                                            }
1286                                            else {
1287                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1288                                            }
1289                                    }
1290                                    else {
1291                                            if (orderByComparator.isAscending() ^ previous) {
1292                                                    query.append(WHERE_GREATER_THAN);
1293                                            }
1294                                            else {
1295                                                    query.append(WHERE_LESSER_THAN);
1296                                            }
1297                                    }
1298                            }
1299    
1300                            query.append(ORDER_BY_CLAUSE);
1301    
1302                            String[] orderByFields = orderByComparator.getOrderByFields();
1303    
1304                            for (int i = 0; i < orderByFields.length; i++) {
1305                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1306                                    query.append(orderByFields[i]);
1307    
1308                                    if ((i + 1) < orderByFields.length) {
1309                                            if (orderByComparator.isAscending() ^ previous) {
1310                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1311                                            }
1312                                            else {
1313                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1314                                            }
1315                                    }
1316                                    else {
1317                                            if (orderByComparator.isAscending() ^ previous) {
1318                                                    query.append(ORDER_BY_ASC);
1319                                            }
1320                                            else {
1321                                                    query.append(ORDER_BY_DESC);
1322                                            }
1323                                    }
1324                            }
1325                    }
1326    
1327                    else {
1328                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
1329                    }
1330    
1331                    String sql = query.toString();
1332    
1333                    Query q = session.createQuery(sql);
1334    
1335                    q.setFirstResult(0);
1336                    q.setMaxResults(2);
1337    
1338                    QueryPos qPos = QueryPos.getInstance(q);
1339    
1340                    if (uuid != null) {
1341                            qPos.add(uuid);
1342                    }
1343    
1344                    if (orderByComparator != null) {
1345                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
1346    
1347                            for (Object value : values) {
1348                                    qPos.add(value);
1349                            }
1350                    }
1351    
1352                    List<Layout> list = q.list();
1353    
1354                    if (list.size() == 2) {
1355                            return list.get(1);
1356                    }
1357                    else {
1358                            return null;
1359                    }
1360            }
1361    
1362            /**
1363             * Returns the layout where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutException} if it could not be found.
1364             *
1365             * @param uuid the uuid
1366             * @param groupId the group ID
1367             * @return the matching layout
1368             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1369             * @throws SystemException if a system exception occurred
1370             */
1371            public Layout findByUUID_G(String uuid, long groupId)
1372                    throws NoSuchLayoutException, SystemException {
1373                    Layout layout = fetchByUUID_G(uuid, groupId);
1374    
1375                    if (layout == null) {
1376                            StringBundler msg = new StringBundler(6);
1377    
1378                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1379    
1380                            msg.append("uuid=");
1381                            msg.append(uuid);
1382    
1383                            msg.append(", groupId=");
1384                            msg.append(groupId);
1385    
1386                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1387    
1388                            if (_log.isWarnEnabled()) {
1389                                    _log.warn(msg.toString());
1390                            }
1391    
1392                            throw new NoSuchLayoutException(msg.toString());
1393                    }
1394    
1395                    return layout;
1396            }
1397    
1398            /**
1399             * Returns the layout where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1400             *
1401             * @param uuid the uuid
1402             * @param groupId the group ID
1403             * @return the matching layout, or <code>null</code> if a matching layout could not be found
1404             * @throws SystemException if a system exception occurred
1405             */
1406            public Layout fetchByUUID_G(String uuid, long groupId)
1407                    throws SystemException {
1408                    return fetchByUUID_G(uuid, groupId, true);
1409            }
1410    
1411            /**
1412             * Returns the layout where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1413             *
1414             * @param uuid the uuid
1415             * @param groupId the group ID
1416             * @param retrieveFromCache whether to use the finder cache
1417             * @return the matching layout, or <code>null</code> if a matching layout could not be found
1418             * @throws SystemException if a system exception occurred
1419             */
1420            public Layout fetchByUUID_G(String uuid, long groupId,
1421                    boolean retrieveFromCache) throws SystemException {
1422                    Object[] finderArgs = new Object[] { uuid, groupId };
1423    
1424                    Object result = null;
1425    
1426                    if (retrieveFromCache) {
1427                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1428                                            finderArgs, this);
1429                    }
1430    
1431                    if (result == null) {
1432                            StringBundler query = new StringBundler(4);
1433    
1434                            query.append(_SQL_SELECT_LAYOUT_WHERE);
1435    
1436                            if (uuid == null) {
1437                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1438                            }
1439                            else {
1440                                    if (uuid.equals(StringPool.BLANK)) {
1441                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1442                                    }
1443                                    else {
1444                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1445                                    }
1446                            }
1447    
1448                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1449    
1450                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
1451    
1452                            String sql = query.toString();
1453    
1454                            Session session = null;
1455    
1456                            try {
1457                                    session = openSession();
1458    
1459                                    Query q = session.createQuery(sql);
1460    
1461                                    QueryPos qPos = QueryPos.getInstance(q);
1462    
1463                                    if (uuid != null) {
1464                                            qPos.add(uuid);
1465                                    }
1466    
1467                                    qPos.add(groupId);
1468    
1469                                    List<Layout> list = q.list();
1470    
1471                                    result = list;
1472    
1473                                    Layout layout = null;
1474    
1475                                    if (list.isEmpty()) {
1476                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1477                                                    finderArgs, list);
1478                                    }
1479                                    else {
1480                                            layout = list.get(0);
1481    
1482                                            cacheResult(layout);
1483    
1484                                            if ((layout.getUuid() == null) ||
1485                                                            !layout.getUuid().equals(uuid) ||
1486                                                            (layout.getGroupId() != groupId)) {
1487                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1488                                                            finderArgs, layout);
1489                                            }
1490                                    }
1491    
1492                                    return layout;
1493                            }
1494                            catch (Exception e) {
1495                                    throw processException(e);
1496                            }
1497                            finally {
1498                                    if (result == null) {
1499                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1500                                                    finderArgs);
1501                                    }
1502    
1503                                    closeSession(session);
1504                            }
1505                    }
1506                    else {
1507                            if (result instanceof List<?>) {
1508                                    return null;
1509                            }
1510                            else {
1511                                    return (Layout)result;
1512                            }
1513                    }
1514            }
1515    
1516            /**
1517             * Returns all the layouts where groupId = &#63;.
1518             *
1519             * @param groupId the group ID
1520             * @return the matching layouts
1521             * @throws SystemException if a system exception occurred
1522             */
1523            public List<Layout> findByGroupId(long groupId) throws SystemException {
1524                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1525            }
1526    
1527            /**
1528             * Returns a range of all the layouts where groupId = &#63;.
1529             *
1530             * <p>
1531             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1532             * </p>
1533             *
1534             * @param groupId the group ID
1535             * @param start the lower bound of the range of layouts
1536             * @param end the upper bound of the range of layouts (not inclusive)
1537             * @return the range of matching layouts
1538             * @throws SystemException if a system exception occurred
1539             */
1540            public List<Layout> findByGroupId(long groupId, int start, int end)
1541                    throws SystemException {
1542                    return findByGroupId(groupId, start, end, null);
1543            }
1544    
1545            /**
1546             * Returns an ordered range of all the layouts where groupId = &#63;.
1547             *
1548             * <p>
1549             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1550             * </p>
1551             *
1552             * @param groupId the group ID
1553             * @param start the lower bound of the range of layouts
1554             * @param end the upper bound of the range of layouts (not inclusive)
1555             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1556             * @return the ordered range of matching layouts
1557             * @throws SystemException if a system exception occurred
1558             */
1559            public List<Layout> findByGroupId(long groupId, int start, int end,
1560                    OrderByComparator orderByComparator) throws SystemException {
1561                    FinderPath finderPath = null;
1562                    Object[] finderArgs = null;
1563    
1564                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1565                                    (orderByComparator == null)) {
1566                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1567                            finderArgs = new Object[] { groupId };
1568                    }
1569                    else {
1570                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1571                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1572                    }
1573    
1574                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(finderPath,
1575                                    finderArgs, this);
1576    
1577                    if (list == null) {
1578                            StringBundler query = null;
1579    
1580                            if (orderByComparator != null) {
1581                                    query = new StringBundler(3 +
1582                                                    (orderByComparator.getOrderByFields().length * 3));
1583                            }
1584                            else {
1585                                    query = new StringBundler(3);
1586                            }
1587    
1588                            query.append(_SQL_SELECT_LAYOUT_WHERE);
1589    
1590                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1591    
1592                            if (orderByComparator != null) {
1593                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1594                                            orderByComparator);
1595                            }
1596    
1597                            else {
1598                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
1599                            }
1600    
1601                            String sql = query.toString();
1602    
1603                            Session session = null;
1604    
1605                            try {
1606                                    session = openSession();
1607    
1608                                    Query q = session.createQuery(sql);
1609    
1610                                    QueryPos qPos = QueryPos.getInstance(q);
1611    
1612                                    qPos.add(groupId);
1613    
1614                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
1615                            }
1616                            catch (Exception e) {
1617                                    throw processException(e);
1618                            }
1619                            finally {
1620                                    if (list == null) {
1621                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1622                                    }
1623                                    else {
1624                                            cacheResult(list);
1625    
1626                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1627                                    }
1628    
1629                                    closeSession(session);
1630                            }
1631                    }
1632    
1633                    return list;
1634            }
1635    
1636            /**
1637             * Returns the first layout in the ordered set where groupId = &#63;.
1638             *
1639             * <p>
1640             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1641             * </p>
1642             *
1643             * @param groupId the group ID
1644             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1645             * @return the first matching layout
1646             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1647             * @throws SystemException if a system exception occurred
1648             */
1649            public Layout findByGroupId_First(long groupId,
1650                    OrderByComparator orderByComparator)
1651                    throws NoSuchLayoutException, SystemException {
1652                    List<Layout> list = findByGroupId(groupId, 0, 1, orderByComparator);
1653    
1654                    if (list.isEmpty()) {
1655                            StringBundler msg = new StringBundler(4);
1656    
1657                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1658    
1659                            msg.append("groupId=");
1660                            msg.append(groupId);
1661    
1662                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1663    
1664                            throw new NoSuchLayoutException(msg.toString());
1665                    }
1666                    else {
1667                            return list.get(0);
1668                    }
1669            }
1670    
1671            /**
1672             * Returns the last layout in the ordered set where groupId = &#63;.
1673             *
1674             * <p>
1675             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1676             * </p>
1677             *
1678             * @param groupId the group ID
1679             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1680             * @return the last matching layout
1681             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1682             * @throws SystemException if a system exception occurred
1683             */
1684            public Layout findByGroupId_Last(long groupId,
1685                    OrderByComparator orderByComparator)
1686                    throws NoSuchLayoutException, SystemException {
1687                    int count = countByGroupId(groupId);
1688    
1689                    List<Layout> list = findByGroupId(groupId, count - 1, count,
1690                                    orderByComparator);
1691    
1692                    if (list.isEmpty()) {
1693                            StringBundler msg = new StringBundler(4);
1694    
1695                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1696    
1697                            msg.append("groupId=");
1698                            msg.append(groupId);
1699    
1700                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1701    
1702                            throw new NoSuchLayoutException(msg.toString());
1703                    }
1704                    else {
1705                            return list.get(0);
1706                    }
1707            }
1708    
1709            /**
1710             * Returns the layouts before and after the current layout in the ordered set where groupId = &#63;.
1711             *
1712             * <p>
1713             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1714             * </p>
1715             *
1716             * @param plid the primary key of the current layout
1717             * @param groupId the group ID
1718             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1719             * @return the previous, current, and next layout
1720             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
1721             * @throws SystemException if a system exception occurred
1722             */
1723            public Layout[] findByGroupId_PrevAndNext(long plid, long groupId,
1724                    OrderByComparator orderByComparator)
1725                    throws NoSuchLayoutException, SystemException {
1726                    Layout layout = findByPrimaryKey(plid);
1727    
1728                    Session session = null;
1729    
1730                    try {
1731                            session = openSession();
1732    
1733                            Layout[] array = new LayoutImpl[3];
1734    
1735                            array[0] = getByGroupId_PrevAndNext(session, layout, groupId,
1736                                            orderByComparator, true);
1737    
1738                            array[1] = layout;
1739    
1740                            array[2] = getByGroupId_PrevAndNext(session, layout, groupId,
1741                                            orderByComparator, false);
1742    
1743                            return array;
1744                    }
1745                    catch (Exception e) {
1746                            throw processException(e);
1747                    }
1748                    finally {
1749                            closeSession(session);
1750                    }
1751            }
1752    
1753            protected Layout getByGroupId_PrevAndNext(Session session, Layout layout,
1754                    long groupId, OrderByComparator orderByComparator, boolean previous) {
1755                    StringBundler query = null;
1756    
1757                    if (orderByComparator != null) {
1758                            query = new StringBundler(6 +
1759                                            (orderByComparator.getOrderByFields().length * 6));
1760                    }
1761                    else {
1762                            query = new StringBundler(3);
1763                    }
1764    
1765                    query.append(_SQL_SELECT_LAYOUT_WHERE);
1766    
1767                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1768    
1769                    if (orderByComparator != null) {
1770                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1771    
1772                            if (orderByConditionFields.length > 0) {
1773                                    query.append(WHERE_AND);
1774                            }
1775    
1776                            for (int i = 0; i < orderByConditionFields.length; i++) {
1777                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1778                                    query.append(orderByConditionFields[i]);
1779    
1780                                    if ((i + 1) < orderByConditionFields.length) {
1781                                            if (orderByComparator.isAscending() ^ previous) {
1782                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1783                                            }
1784                                            else {
1785                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1786                                            }
1787                                    }
1788                                    else {
1789                                            if (orderByComparator.isAscending() ^ previous) {
1790                                                    query.append(WHERE_GREATER_THAN);
1791                                            }
1792                                            else {
1793                                                    query.append(WHERE_LESSER_THAN);
1794                                            }
1795                                    }
1796                            }
1797    
1798                            query.append(ORDER_BY_CLAUSE);
1799    
1800                            String[] orderByFields = orderByComparator.getOrderByFields();
1801    
1802                            for (int i = 0; i < orderByFields.length; i++) {
1803                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1804                                    query.append(orderByFields[i]);
1805    
1806                                    if ((i + 1) < orderByFields.length) {
1807                                            if (orderByComparator.isAscending() ^ previous) {
1808                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1809                                            }
1810                                            else {
1811                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1812                                            }
1813                                    }
1814                                    else {
1815                                            if (orderByComparator.isAscending() ^ previous) {
1816                                                    query.append(ORDER_BY_ASC);
1817                                            }
1818                                            else {
1819                                                    query.append(ORDER_BY_DESC);
1820                                            }
1821                                    }
1822                            }
1823                    }
1824    
1825                    else {
1826                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
1827                    }
1828    
1829                    String sql = query.toString();
1830    
1831                    Query q = session.createQuery(sql);
1832    
1833                    q.setFirstResult(0);
1834                    q.setMaxResults(2);
1835    
1836                    QueryPos qPos = QueryPos.getInstance(q);
1837    
1838                    qPos.add(groupId);
1839    
1840                    if (orderByComparator != null) {
1841                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
1842    
1843                            for (Object value : values) {
1844                                    qPos.add(value);
1845                            }
1846                    }
1847    
1848                    List<Layout> list = q.list();
1849    
1850                    if (list.size() == 2) {
1851                            return list.get(1);
1852                    }
1853                    else {
1854                            return null;
1855                    }
1856            }
1857    
1858            /**
1859             * Returns all the layouts that the user has permission to view where groupId = &#63;.
1860             *
1861             * @param groupId the group ID
1862             * @return the matching layouts that the user has permission to view
1863             * @throws SystemException if a system exception occurred
1864             */
1865            public List<Layout> filterFindByGroupId(long groupId)
1866                    throws SystemException {
1867                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1868                            QueryUtil.ALL_POS, null);
1869            }
1870    
1871            /**
1872             * Returns a range of all the layouts that the user has permission to view where groupId = &#63;.
1873             *
1874             * <p>
1875             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1876             * </p>
1877             *
1878             * @param groupId the group ID
1879             * @param start the lower bound of the range of layouts
1880             * @param end the upper bound of the range of layouts (not inclusive)
1881             * @return the range of matching layouts that the user has permission to view
1882             * @throws SystemException if a system exception occurred
1883             */
1884            public List<Layout> filterFindByGroupId(long groupId, int start, int end)
1885                    throws SystemException {
1886                    return filterFindByGroupId(groupId, start, end, null);
1887            }
1888    
1889            /**
1890             * Returns an ordered range of all the layouts that the user has permissions to view where groupId = &#63;.
1891             *
1892             * <p>
1893             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1894             * </p>
1895             *
1896             * @param groupId the group ID
1897             * @param start the lower bound of the range of layouts
1898             * @param end the upper bound of the range of layouts (not inclusive)
1899             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1900             * @return the ordered range of matching layouts that the user has permission to view
1901             * @throws SystemException if a system exception occurred
1902             */
1903            public List<Layout> filterFindByGroupId(long groupId, int start, int end,
1904                    OrderByComparator orderByComparator) throws SystemException {
1905                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1906                            return findByGroupId(groupId, start, end, orderByComparator);
1907                    }
1908    
1909                    StringBundler query = null;
1910    
1911                    if (orderByComparator != null) {
1912                            query = new StringBundler(3 +
1913                                            (orderByComparator.getOrderByFields().length * 3));
1914                    }
1915                    else {
1916                            query = new StringBundler(3);
1917                    }
1918    
1919                    if (getDB().isSupportsInlineDistinct()) {
1920                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
1921                    }
1922                    else {
1923                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
1924                    }
1925    
1926                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1927    
1928                    if (!getDB().isSupportsInlineDistinct()) {
1929                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
1930                    }
1931    
1932                    if (orderByComparator != null) {
1933                            if (getDB().isSupportsInlineDistinct()) {
1934                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1935                                            orderByComparator);
1936                            }
1937                            else {
1938                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1939                                            orderByComparator);
1940                            }
1941                    }
1942    
1943                    else {
1944                            if (getDB().isSupportsInlineDistinct()) {
1945                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
1946                            }
1947                            else {
1948                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
1949                            }
1950                    }
1951    
1952                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1953                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
1954                                    groupId);
1955    
1956                    Session session = null;
1957    
1958                    try {
1959                            session = openSession();
1960    
1961                            SQLQuery q = session.createSQLQuery(sql);
1962    
1963                            if (getDB().isSupportsInlineDistinct()) {
1964                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
1965                            }
1966                            else {
1967                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
1968                            }
1969    
1970                            QueryPos qPos = QueryPos.getInstance(q);
1971    
1972                            qPos.add(groupId);
1973    
1974                            return (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
1975                    }
1976                    catch (Exception e) {
1977                            throw processException(e);
1978                    }
1979                    finally {
1980                            closeSession(session);
1981                    }
1982            }
1983    
1984            /**
1985             * Returns the layouts before and after the current layout in the ordered set of layouts that the user has permission to view where groupId = &#63;.
1986             *
1987             * @param plid the primary key of the current layout
1988             * @param groupId the group ID
1989             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1990             * @return the previous, current, and next layout
1991             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
1992             * @throws SystemException if a system exception occurred
1993             */
1994            public Layout[] filterFindByGroupId_PrevAndNext(long plid, long groupId,
1995                    OrderByComparator orderByComparator)
1996                    throws NoSuchLayoutException, SystemException {
1997                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1998                            return findByGroupId_PrevAndNext(plid, groupId, orderByComparator);
1999                    }
2000    
2001                    Layout layout = findByPrimaryKey(plid);
2002    
2003                    Session session = null;
2004    
2005                    try {
2006                            session = openSession();
2007    
2008                            Layout[] array = new LayoutImpl[3];
2009    
2010                            array[0] = filterGetByGroupId_PrevAndNext(session, layout, groupId,
2011                                            orderByComparator, true);
2012    
2013                            array[1] = layout;
2014    
2015                            array[2] = filterGetByGroupId_PrevAndNext(session, layout, groupId,
2016                                            orderByComparator, false);
2017    
2018                            return array;
2019                    }
2020                    catch (Exception e) {
2021                            throw processException(e);
2022                    }
2023                    finally {
2024                            closeSession(session);
2025                    }
2026            }
2027    
2028            protected Layout filterGetByGroupId_PrevAndNext(Session session,
2029                    Layout layout, long groupId, OrderByComparator orderByComparator,
2030                    boolean previous) {
2031                    StringBundler query = null;
2032    
2033                    if (orderByComparator != null) {
2034                            query = new StringBundler(6 +
2035                                            (orderByComparator.getOrderByFields().length * 6));
2036                    }
2037                    else {
2038                            query = new StringBundler(3);
2039                    }
2040    
2041                    if (getDB().isSupportsInlineDistinct()) {
2042                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
2043                    }
2044                    else {
2045                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
2046                    }
2047    
2048                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2049    
2050                    if (!getDB().isSupportsInlineDistinct()) {
2051                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
2052                    }
2053    
2054                    if (orderByComparator != null) {
2055                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2056    
2057                            if (orderByConditionFields.length > 0) {
2058                                    query.append(WHERE_AND);
2059                            }
2060    
2061                            for (int i = 0; i < orderByConditionFields.length; i++) {
2062                                    if (getDB().isSupportsInlineDistinct()) {
2063                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2064                                    }
2065                                    else {
2066                                            query.append(_ORDER_BY_ENTITY_TABLE);
2067                                    }
2068    
2069                                    query.append(orderByConditionFields[i]);
2070    
2071                                    if ((i + 1) < orderByConditionFields.length) {
2072                                            if (orderByComparator.isAscending() ^ previous) {
2073                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2074                                            }
2075                                            else {
2076                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2077                                            }
2078                                    }
2079                                    else {
2080                                            if (orderByComparator.isAscending() ^ previous) {
2081                                                    query.append(WHERE_GREATER_THAN);
2082                                            }
2083                                            else {
2084                                                    query.append(WHERE_LESSER_THAN);
2085                                            }
2086                                    }
2087                            }
2088    
2089                            query.append(ORDER_BY_CLAUSE);
2090    
2091                            String[] orderByFields = orderByComparator.getOrderByFields();
2092    
2093                            for (int i = 0; i < orderByFields.length; i++) {
2094                                    if (getDB().isSupportsInlineDistinct()) {
2095                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2096                                    }
2097                                    else {
2098                                            query.append(_ORDER_BY_ENTITY_TABLE);
2099                                    }
2100    
2101                                    query.append(orderByFields[i]);
2102    
2103                                    if ((i + 1) < orderByFields.length) {
2104                                            if (orderByComparator.isAscending() ^ previous) {
2105                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2106                                            }
2107                                            else {
2108                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2109                                            }
2110                                    }
2111                                    else {
2112                                            if (orderByComparator.isAscending() ^ previous) {
2113                                                    query.append(ORDER_BY_ASC);
2114                                            }
2115                                            else {
2116                                                    query.append(ORDER_BY_DESC);
2117                                            }
2118                                    }
2119                            }
2120                    }
2121    
2122                    else {
2123                            if (getDB().isSupportsInlineDistinct()) {
2124                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
2125                            }
2126                            else {
2127                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
2128                            }
2129                    }
2130    
2131                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2132                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
2133                                    groupId);
2134    
2135                    SQLQuery q = session.createSQLQuery(sql);
2136    
2137                    q.setFirstResult(0);
2138                    q.setMaxResults(2);
2139    
2140                    if (getDB().isSupportsInlineDistinct()) {
2141                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
2142                    }
2143                    else {
2144                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
2145                    }
2146    
2147                    QueryPos qPos = QueryPos.getInstance(q);
2148    
2149                    qPos.add(groupId);
2150    
2151                    if (orderByComparator != null) {
2152                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
2153    
2154                            for (Object value : values) {
2155                                    qPos.add(value);
2156                            }
2157                    }
2158    
2159                    List<Layout> list = q.list();
2160    
2161                    if (list.size() == 2) {
2162                            return list.get(1);
2163                    }
2164                    else {
2165                            return null;
2166                    }
2167            }
2168    
2169            /**
2170             * Returns all the layouts where companyId = &#63;.
2171             *
2172             * @param companyId the company ID
2173             * @return the matching layouts
2174             * @throws SystemException if a system exception occurred
2175             */
2176            public List<Layout> findByCompanyId(long companyId)
2177                    throws SystemException {
2178                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2179                            null);
2180            }
2181    
2182            /**
2183             * Returns a range of all the layouts where companyId = &#63;.
2184             *
2185             * <p>
2186             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2187             * </p>
2188             *
2189             * @param companyId the company ID
2190             * @param start the lower bound of the range of layouts
2191             * @param end the upper bound of the range of layouts (not inclusive)
2192             * @return the range of matching layouts
2193             * @throws SystemException if a system exception occurred
2194             */
2195            public List<Layout> findByCompanyId(long companyId, int start, int end)
2196                    throws SystemException {
2197                    return findByCompanyId(companyId, start, end, null);
2198            }
2199    
2200            /**
2201             * Returns an ordered range of all the layouts where companyId = &#63;.
2202             *
2203             * <p>
2204             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2205             * </p>
2206             *
2207             * @param companyId the company ID
2208             * @param start the lower bound of the range of layouts
2209             * @param end the upper bound of the range of layouts (not inclusive)
2210             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2211             * @return the ordered range of matching layouts
2212             * @throws SystemException if a system exception occurred
2213             */
2214            public List<Layout> findByCompanyId(long companyId, int start, int end,
2215                    OrderByComparator orderByComparator) throws SystemException {
2216                    FinderPath finderPath = null;
2217                    Object[] finderArgs = null;
2218    
2219                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2220                                    (orderByComparator == null)) {
2221                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2222                            finderArgs = new Object[] { companyId };
2223                    }
2224                    else {
2225                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2226                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2227                    }
2228    
2229                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(finderPath,
2230                                    finderArgs, this);
2231    
2232                    if (list == null) {
2233                            StringBundler query = null;
2234    
2235                            if (orderByComparator != null) {
2236                                    query = new StringBundler(3 +
2237                                                    (orderByComparator.getOrderByFields().length * 3));
2238                            }
2239                            else {
2240                                    query = new StringBundler(3);
2241                            }
2242    
2243                            query.append(_SQL_SELECT_LAYOUT_WHERE);
2244    
2245                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2246    
2247                            if (orderByComparator != null) {
2248                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2249                                            orderByComparator);
2250                            }
2251    
2252                            else {
2253                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
2254                            }
2255    
2256                            String sql = query.toString();
2257    
2258                            Session session = null;
2259    
2260                            try {
2261                                    session = openSession();
2262    
2263                                    Query q = session.createQuery(sql);
2264    
2265                                    QueryPos qPos = QueryPos.getInstance(q);
2266    
2267                                    qPos.add(companyId);
2268    
2269                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
2270                            }
2271                            catch (Exception e) {
2272                                    throw processException(e);
2273                            }
2274                            finally {
2275                                    if (list == null) {
2276                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2277                                    }
2278                                    else {
2279                                            cacheResult(list);
2280    
2281                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2282                                    }
2283    
2284                                    closeSession(session);
2285                            }
2286                    }
2287    
2288                    return list;
2289            }
2290    
2291            /**
2292             * Returns the first layout in the ordered set where companyId = &#63;.
2293             *
2294             * <p>
2295             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2296             * </p>
2297             *
2298             * @param companyId the company ID
2299             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2300             * @return the first matching layout
2301             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2302             * @throws SystemException if a system exception occurred
2303             */
2304            public Layout findByCompanyId_First(long companyId,
2305                    OrderByComparator orderByComparator)
2306                    throws NoSuchLayoutException, SystemException {
2307                    List<Layout> list = findByCompanyId(companyId, 0, 1, orderByComparator);
2308    
2309                    if (list.isEmpty()) {
2310                            StringBundler msg = new StringBundler(4);
2311    
2312                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2313    
2314                            msg.append("companyId=");
2315                            msg.append(companyId);
2316    
2317                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2318    
2319                            throw new NoSuchLayoutException(msg.toString());
2320                    }
2321                    else {
2322                            return list.get(0);
2323                    }
2324            }
2325    
2326            /**
2327             * Returns the last layout in the ordered set where companyId = &#63;.
2328             *
2329             * <p>
2330             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2331             * </p>
2332             *
2333             * @param companyId the company ID
2334             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2335             * @return the last matching layout
2336             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2337             * @throws SystemException if a system exception occurred
2338             */
2339            public Layout findByCompanyId_Last(long companyId,
2340                    OrderByComparator orderByComparator)
2341                    throws NoSuchLayoutException, SystemException {
2342                    int count = countByCompanyId(companyId);
2343    
2344                    List<Layout> list = findByCompanyId(companyId, count - 1, count,
2345                                    orderByComparator);
2346    
2347                    if (list.isEmpty()) {
2348                            StringBundler msg = new StringBundler(4);
2349    
2350                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2351    
2352                            msg.append("companyId=");
2353                            msg.append(companyId);
2354    
2355                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2356    
2357                            throw new NoSuchLayoutException(msg.toString());
2358                    }
2359                    else {
2360                            return list.get(0);
2361                    }
2362            }
2363    
2364            /**
2365             * Returns the layouts before and after the current layout in the ordered set where companyId = &#63;.
2366             *
2367             * <p>
2368             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2369             * </p>
2370             *
2371             * @param plid the primary key of the current layout
2372             * @param companyId the company ID
2373             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2374             * @return the previous, current, and next layout
2375             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
2376             * @throws SystemException if a system exception occurred
2377             */
2378            public Layout[] findByCompanyId_PrevAndNext(long plid, long companyId,
2379                    OrderByComparator orderByComparator)
2380                    throws NoSuchLayoutException, SystemException {
2381                    Layout layout = findByPrimaryKey(plid);
2382    
2383                    Session session = null;
2384    
2385                    try {
2386                            session = openSession();
2387    
2388                            Layout[] array = new LayoutImpl[3];
2389    
2390                            array[0] = getByCompanyId_PrevAndNext(session, layout, companyId,
2391                                            orderByComparator, true);
2392    
2393                            array[1] = layout;
2394    
2395                            array[2] = getByCompanyId_PrevAndNext(session, layout, companyId,
2396                                            orderByComparator, false);
2397    
2398                            return array;
2399                    }
2400                    catch (Exception e) {
2401                            throw processException(e);
2402                    }
2403                    finally {
2404                            closeSession(session);
2405                    }
2406            }
2407    
2408            protected Layout getByCompanyId_PrevAndNext(Session session, Layout layout,
2409                    long companyId, OrderByComparator orderByComparator, boolean previous) {
2410                    StringBundler query = null;
2411    
2412                    if (orderByComparator != null) {
2413                            query = new StringBundler(6 +
2414                                            (orderByComparator.getOrderByFields().length * 6));
2415                    }
2416                    else {
2417                            query = new StringBundler(3);
2418                    }
2419    
2420                    query.append(_SQL_SELECT_LAYOUT_WHERE);
2421    
2422                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2423    
2424                    if (orderByComparator != null) {
2425                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2426    
2427                            if (orderByConditionFields.length > 0) {
2428                                    query.append(WHERE_AND);
2429                            }
2430    
2431                            for (int i = 0; i < orderByConditionFields.length; i++) {
2432                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2433                                    query.append(orderByConditionFields[i]);
2434    
2435                                    if ((i + 1) < orderByConditionFields.length) {
2436                                            if (orderByComparator.isAscending() ^ previous) {
2437                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2438                                            }
2439                                            else {
2440                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2441                                            }
2442                                    }
2443                                    else {
2444                                            if (orderByComparator.isAscending() ^ previous) {
2445                                                    query.append(WHERE_GREATER_THAN);
2446                                            }
2447                                            else {
2448                                                    query.append(WHERE_LESSER_THAN);
2449                                            }
2450                                    }
2451                            }
2452    
2453                            query.append(ORDER_BY_CLAUSE);
2454    
2455                            String[] orderByFields = orderByComparator.getOrderByFields();
2456    
2457                            for (int i = 0; i < orderByFields.length; i++) {
2458                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2459                                    query.append(orderByFields[i]);
2460    
2461                                    if ((i + 1) < orderByFields.length) {
2462                                            if (orderByComparator.isAscending() ^ previous) {
2463                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2464                                            }
2465                                            else {
2466                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2467                                            }
2468                                    }
2469                                    else {
2470                                            if (orderByComparator.isAscending() ^ previous) {
2471                                                    query.append(ORDER_BY_ASC);
2472                                            }
2473                                            else {
2474                                                    query.append(ORDER_BY_DESC);
2475                                            }
2476                                    }
2477                            }
2478                    }
2479    
2480                    else {
2481                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
2482                    }
2483    
2484                    String sql = query.toString();
2485    
2486                    Query q = session.createQuery(sql);
2487    
2488                    q.setFirstResult(0);
2489                    q.setMaxResults(2);
2490    
2491                    QueryPos qPos = QueryPos.getInstance(q);
2492    
2493                    qPos.add(companyId);
2494    
2495                    if (orderByComparator != null) {
2496                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
2497    
2498                            for (Object value : values) {
2499                                    qPos.add(value);
2500                            }
2501                    }
2502    
2503                    List<Layout> list = q.list();
2504    
2505                    if (list.size() == 2) {
2506                            return list.get(1);
2507                    }
2508                    else {
2509                            return null;
2510                    }
2511            }
2512    
2513            /**
2514             * Returns the layout where iconImageId = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutException} if it could not be found.
2515             *
2516             * @param iconImageId the icon image ID
2517             * @return the matching layout
2518             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2519             * @throws SystemException if a system exception occurred
2520             */
2521            public Layout findByIconImageId(long iconImageId)
2522                    throws NoSuchLayoutException, SystemException {
2523                    Layout layout = fetchByIconImageId(iconImageId);
2524    
2525                    if (layout == null) {
2526                            StringBundler msg = new StringBundler(4);
2527    
2528                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2529    
2530                            msg.append("iconImageId=");
2531                            msg.append(iconImageId);
2532    
2533                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2534    
2535                            if (_log.isWarnEnabled()) {
2536                                    _log.warn(msg.toString());
2537                            }
2538    
2539                            throw new NoSuchLayoutException(msg.toString());
2540                    }
2541    
2542                    return layout;
2543            }
2544    
2545            /**
2546             * Returns the layout where iconImageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2547             *
2548             * @param iconImageId the icon image ID
2549             * @return the matching layout, or <code>null</code> if a matching layout could not be found
2550             * @throws SystemException if a system exception occurred
2551             */
2552            public Layout fetchByIconImageId(long iconImageId)
2553                    throws SystemException {
2554                    return fetchByIconImageId(iconImageId, true);
2555            }
2556    
2557            /**
2558             * Returns the layout where iconImageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2559             *
2560             * @param iconImageId the icon image ID
2561             * @param retrieveFromCache whether to use the finder cache
2562             * @return the matching layout, or <code>null</code> if a matching layout could not be found
2563             * @throws SystemException if a system exception occurred
2564             */
2565            public Layout fetchByIconImageId(long iconImageId, boolean retrieveFromCache)
2566                    throws SystemException {
2567                    Object[] finderArgs = new Object[] { iconImageId };
2568    
2569                    Object result = null;
2570    
2571                    if (retrieveFromCache) {
2572                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2573                                            finderArgs, this);
2574                    }
2575    
2576                    if (result == null) {
2577                            StringBundler query = new StringBundler(3);
2578    
2579                            query.append(_SQL_SELECT_LAYOUT_WHERE);
2580    
2581                            query.append(_FINDER_COLUMN_ICONIMAGEID_ICONIMAGEID_2);
2582    
2583                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
2584    
2585                            String sql = query.toString();
2586    
2587                            Session session = null;
2588    
2589                            try {
2590                                    session = openSession();
2591    
2592                                    Query q = session.createQuery(sql);
2593    
2594                                    QueryPos qPos = QueryPos.getInstance(q);
2595    
2596                                    qPos.add(iconImageId);
2597    
2598                                    List<Layout> list = q.list();
2599    
2600                                    result = list;
2601    
2602                                    Layout layout = null;
2603    
2604                                    if (list.isEmpty()) {
2605                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2606                                                    finderArgs, list);
2607                                    }
2608                                    else {
2609                                            layout = list.get(0);
2610    
2611                                            cacheResult(layout);
2612    
2613                                            if ((layout.getIconImageId() != iconImageId)) {
2614                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2615                                                            finderArgs, layout);
2616                                            }
2617                                    }
2618    
2619                                    return layout;
2620                            }
2621                            catch (Exception e) {
2622                                    throw processException(e);
2623                            }
2624                            finally {
2625                                    if (result == null) {
2626                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2627                                                    finderArgs);
2628                                    }
2629    
2630                                    closeSession(session);
2631                            }
2632                    }
2633                    else {
2634                            if (result instanceof List<?>) {
2635                                    return null;
2636                            }
2637                            else {
2638                                    return (Layout)result;
2639                            }
2640                    }
2641            }
2642    
2643            /**
2644             * Returns all the layouts where groupId = &#63; and privateLayout = &#63;.
2645             *
2646             * @param groupId the group ID
2647             * @param privateLayout the private layout
2648             * @return the matching layouts
2649             * @throws SystemException if a system exception occurred
2650             */
2651            public List<Layout> findByG_P(long groupId, boolean privateLayout)
2652                    throws SystemException {
2653                    return findByG_P(groupId, privateLayout, QueryUtil.ALL_POS,
2654                            QueryUtil.ALL_POS, null);
2655            }
2656    
2657            /**
2658             * Returns a range of all the layouts where groupId = &#63; and privateLayout = &#63;.
2659             *
2660             * <p>
2661             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2662             * </p>
2663             *
2664             * @param groupId the group ID
2665             * @param privateLayout the private layout
2666             * @param start the lower bound of the range of layouts
2667             * @param end the upper bound of the range of layouts (not inclusive)
2668             * @return the range of matching layouts
2669             * @throws SystemException if a system exception occurred
2670             */
2671            public List<Layout> findByG_P(long groupId, boolean privateLayout,
2672                    int start, int end) throws SystemException {
2673                    return findByG_P(groupId, privateLayout, start, end, null);
2674            }
2675    
2676            /**
2677             * Returns an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63;.
2678             *
2679             * <p>
2680             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2681             * </p>
2682             *
2683             * @param groupId the group ID
2684             * @param privateLayout the private layout
2685             * @param start the lower bound of the range of layouts
2686             * @param end the upper bound of the range of layouts (not inclusive)
2687             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2688             * @return the ordered range of matching layouts
2689             * @throws SystemException if a system exception occurred
2690             */
2691            public List<Layout> findByG_P(long groupId, boolean privateLayout,
2692                    int start, int end, OrderByComparator orderByComparator)
2693                    throws SystemException {
2694                    FinderPath finderPath = null;
2695                    Object[] finderArgs = null;
2696    
2697                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2698                                    (orderByComparator == null)) {
2699                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
2700                            finderArgs = new Object[] { groupId, privateLayout };
2701                    }
2702                    else {
2703                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
2704                            finderArgs = new Object[] {
2705                                            groupId, privateLayout,
2706                                            
2707                                            start, end, orderByComparator
2708                                    };
2709                    }
2710    
2711                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(finderPath,
2712                                    finderArgs, this);
2713    
2714                    if (list == null) {
2715                            StringBundler query = null;
2716    
2717                            if (orderByComparator != null) {
2718                                    query = new StringBundler(4 +
2719                                                    (orderByComparator.getOrderByFields().length * 3));
2720                            }
2721                            else {
2722                                    query = new StringBundler(4);
2723                            }
2724    
2725                            query.append(_SQL_SELECT_LAYOUT_WHERE);
2726    
2727                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2728    
2729                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
2730    
2731                            if (orderByComparator != null) {
2732                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2733                                            orderByComparator);
2734                            }
2735    
2736                            else {
2737                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
2738                            }
2739    
2740                            String sql = query.toString();
2741    
2742                            Session session = null;
2743    
2744                            try {
2745                                    session = openSession();
2746    
2747                                    Query q = session.createQuery(sql);
2748    
2749                                    QueryPos qPos = QueryPos.getInstance(q);
2750    
2751                                    qPos.add(groupId);
2752    
2753                                    qPos.add(privateLayout);
2754    
2755                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
2756                            }
2757                            catch (Exception e) {
2758                                    throw processException(e);
2759                            }
2760                            finally {
2761                                    if (list == null) {
2762                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2763                                    }
2764                                    else {
2765                                            cacheResult(list);
2766    
2767                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2768                                    }
2769    
2770                                    closeSession(session);
2771                            }
2772                    }
2773    
2774                    return list;
2775            }
2776    
2777            /**
2778             * Returns the first layout in the ordered set where groupId = &#63; and privateLayout = &#63;.
2779             *
2780             * <p>
2781             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2782             * </p>
2783             *
2784             * @param groupId the group ID
2785             * @param privateLayout the private layout
2786             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2787             * @return the first matching layout
2788             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2789             * @throws SystemException if a system exception occurred
2790             */
2791            public Layout findByG_P_First(long groupId, boolean privateLayout,
2792                    OrderByComparator orderByComparator)
2793                    throws NoSuchLayoutException, SystemException {
2794                    List<Layout> list = findByG_P(groupId, privateLayout, 0, 1,
2795                                    orderByComparator);
2796    
2797                    if (list.isEmpty()) {
2798                            StringBundler msg = new StringBundler(6);
2799    
2800                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2801    
2802                            msg.append("groupId=");
2803                            msg.append(groupId);
2804    
2805                            msg.append(", privateLayout=");
2806                            msg.append(privateLayout);
2807    
2808                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2809    
2810                            throw new NoSuchLayoutException(msg.toString());
2811                    }
2812                    else {
2813                            return list.get(0);
2814                    }
2815            }
2816    
2817            /**
2818             * Returns the last layout in the ordered set where groupId = &#63; and privateLayout = &#63;.
2819             *
2820             * <p>
2821             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2822             * </p>
2823             *
2824             * @param groupId the group ID
2825             * @param privateLayout the private layout
2826             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2827             * @return the last matching layout
2828             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2829             * @throws SystemException if a system exception occurred
2830             */
2831            public Layout findByG_P_Last(long groupId, boolean privateLayout,
2832                    OrderByComparator orderByComparator)
2833                    throws NoSuchLayoutException, SystemException {
2834                    int count = countByG_P(groupId, privateLayout);
2835    
2836                    List<Layout> list = findByG_P(groupId, privateLayout, count - 1, count,
2837                                    orderByComparator);
2838    
2839                    if (list.isEmpty()) {
2840                            StringBundler msg = new StringBundler(6);
2841    
2842                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2843    
2844                            msg.append("groupId=");
2845                            msg.append(groupId);
2846    
2847                            msg.append(", privateLayout=");
2848                            msg.append(privateLayout);
2849    
2850                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2851    
2852                            throw new NoSuchLayoutException(msg.toString());
2853                    }
2854                    else {
2855                            return list.get(0);
2856                    }
2857            }
2858    
2859            /**
2860             * Returns the layouts before and after the current layout in the ordered set where groupId = &#63; and privateLayout = &#63;.
2861             *
2862             * <p>
2863             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2864             * </p>
2865             *
2866             * @param plid the primary key of the current layout
2867             * @param groupId the group ID
2868             * @param privateLayout the private layout
2869             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2870             * @return the previous, current, and next layout
2871             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
2872             * @throws SystemException if a system exception occurred
2873             */
2874            public Layout[] findByG_P_PrevAndNext(long plid, long groupId,
2875                    boolean privateLayout, OrderByComparator orderByComparator)
2876                    throws NoSuchLayoutException, SystemException {
2877                    Layout layout = findByPrimaryKey(plid);
2878    
2879                    Session session = null;
2880    
2881                    try {
2882                            session = openSession();
2883    
2884                            Layout[] array = new LayoutImpl[3];
2885    
2886                            array[0] = getByG_P_PrevAndNext(session, layout, groupId,
2887                                            privateLayout, orderByComparator, true);
2888    
2889                            array[1] = layout;
2890    
2891                            array[2] = getByG_P_PrevAndNext(session, layout, groupId,
2892                                            privateLayout, orderByComparator, false);
2893    
2894                            return array;
2895                    }
2896                    catch (Exception e) {
2897                            throw processException(e);
2898                    }
2899                    finally {
2900                            closeSession(session);
2901                    }
2902            }
2903    
2904            protected Layout getByG_P_PrevAndNext(Session session, Layout layout,
2905                    long groupId, boolean privateLayout,
2906                    OrderByComparator orderByComparator, boolean previous) {
2907                    StringBundler query = null;
2908    
2909                    if (orderByComparator != null) {
2910                            query = new StringBundler(6 +
2911                                            (orderByComparator.getOrderByFields().length * 6));
2912                    }
2913                    else {
2914                            query = new StringBundler(3);
2915                    }
2916    
2917                    query.append(_SQL_SELECT_LAYOUT_WHERE);
2918    
2919                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2920    
2921                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
2922    
2923                    if (orderByComparator != null) {
2924                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2925    
2926                            if (orderByConditionFields.length > 0) {
2927                                    query.append(WHERE_AND);
2928                            }
2929    
2930                            for (int i = 0; i < orderByConditionFields.length; i++) {
2931                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2932                                    query.append(orderByConditionFields[i]);
2933    
2934                                    if ((i + 1) < orderByConditionFields.length) {
2935                                            if (orderByComparator.isAscending() ^ previous) {
2936                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2937                                            }
2938                                            else {
2939                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2940                                            }
2941                                    }
2942                                    else {
2943                                            if (orderByComparator.isAscending() ^ previous) {
2944                                                    query.append(WHERE_GREATER_THAN);
2945                                            }
2946                                            else {
2947                                                    query.append(WHERE_LESSER_THAN);
2948                                            }
2949                                    }
2950                            }
2951    
2952                            query.append(ORDER_BY_CLAUSE);
2953    
2954                            String[] orderByFields = orderByComparator.getOrderByFields();
2955    
2956                            for (int i = 0; i < orderByFields.length; i++) {
2957                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2958                                    query.append(orderByFields[i]);
2959    
2960                                    if ((i + 1) < orderByFields.length) {
2961                                            if (orderByComparator.isAscending() ^ previous) {
2962                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2963                                            }
2964                                            else {
2965                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2966                                            }
2967                                    }
2968                                    else {
2969                                            if (orderByComparator.isAscending() ^ previous) {
2970                                                    query.append(ORDER_BY_ASC);
2971                                            }
2972                                            else {
2973                                                    query.append(ORDER_BY_DESC);
2974                                            }
2975                                    }
2976                            }
2977                    }
2978    
2979                    else {
2980                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
2981                    }
2982    
2983                    String sql = query.toString();
2984    
2985                    Query q = session.createQuery(sql);
2986    
2987                    q.setFirstResult(0);
2988                    q.setMaxResults(2);
2989    
2990                    QueryPos qPos = QueryPos.getInstance(q);
2991    
2992                    qPos.add(groupId);
2993    
2994                    qPos.add(privateLayout);
2995    
2996                    if (orderByComparator != null) {
2997                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
2998    
2999                            for (Object value : values) {
3000                                    qPos.add(value);
3001                            }
3002                    }
3003    
3004                    List<Layout> list = q.list();
3005    
3006                    if (list.size() == 2) {
3007                            return list.get(1);
3008                    }
3009                    else {
3010                            return null;
3011                    }
3012            }
3013    
3014            /**
3015             * Returns all the layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
3016             *
3017             * @param groupId the group ID
3018             * @param privateLayout the private layout
3019             * @return the matching layouts that the user has permission to view
3020             * @throws SystemException if a system exception occurred
3021             */
3022            public List<Layout> filterFindByG_P(long groupId, boolean privateLayout)
3023                    throws SystemException {
3024                    return filterFindByG_P(groupId, privateLayout, QueryUtil.ALL_POS,
3025                            QueryUtil.ALL_POS, null);
3026            }
3027    
3028            /**
3029             * Returns a range of all the layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
3030             *
3031             * <p>
3032             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3033             * </p>
3034             *
3035             * @param groupId the group ID
3036             * @param privateLayout the private layout
3037             * @param start the lower bound of the range of layouts
3038             * @param end the upper bound of the range of layouts (not inclusive)
3039             * @return the range of matching layouts that the user has permission to view
3040             * @throws SystemException if a system exception occurred
3041             */
3042            public List<Layout> filterFindByG_P(long groupId, boolean privateLayout,
3043                    int start, int end) throws SystemException {
3044                    return filterFindByG_P(groupId, privateLayout, start, end, null);
3045            }
3046    
3047            /**
3048             * Returns an ordered range of all the layouts that the user has permissions to view where groupId = &#63; and privateLayout = &#63;.
3049             *
3050             * <p>
3051             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3052             * </p>
3053             *
3054             * @param groupId the group ID
3055             * @param privateLayout the private layout
3056             * @param start the lower bound of the range of layouts
3057             * @param end the upper bound of the range of layouts (not inclusive)
3058             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3059             * @return the ordered range of matching layouts that the user has permission to view
3060             * @throws SystemException if a system exception occurred
3061             */
3062            public List<Layout> filterFindByG_P(long groupId, boolean privateLayout,
3063                    int start, int end, OrderByComparator orderByComparator)
3064                    throws SystemException {
3065                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3066                            return findByG_P(groupId, privateLayout, start, end,
3067                                    orderByComparator);
3068                    }
3069    
3070                    StringBundler query = null;
3071    
3072                    if (orderByComparator != null) {
3073                            query = new StringBundler(4 +
3074                                            (orderByComparator.getOrderByFields().length * 3));
3075                    }
3076                    else {
3077                            query = new StringBundler(4);
3078                    }
3079    
3080                    if (getDB().isSupportsInlineDistinct()) {
3081                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
3082                    }
3083                    else {
3084                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
3085                    }
3086    
3087                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3088    
3089                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
3090    
3091                    if (!getDB().isSupportsInlineDistinct()) {
3092                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
3093                    }
3094    
3095                    if (orderByComparator != null) {
3096                            if (getDB().isSupportsInlineDistinct()) {
3097                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3098                                            orderByComparator);
3099                            }
3100                            else {
3101                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3102                                            orderByComparator);
3103                            }
3104                    }
3105    
3106                    else {
3107                            if (getDB().isSupportsInlineDistinct()) {
3108                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
3109                            }
3110                            else {
3111                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
3112                            }
3113                    }
3114    
3115                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3116                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
3117                                    groupId);
3118    
3119                    Session session = null;
3120    
3121                    try {
3122                            session = openSession();
3123    
3124                            SQLQuery q = session.createSQLQuery(sql);
3125    
3126                            if (getDB().isSupportsInlineDistinct()) {
3127                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
3128                            }
3129                            else {
3130                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
3131                            }
3132    
3133                            QueryPos qPos = QueryPos.getInstance(q);
3134    
3135                            qPos.add(groupId);
3136    
3137                            qPos.add(privateLayout);
3138    
3139                            return (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
3140                    }
3141                    catch (Exception e) {
3142                            throw processException(e);
3143                    }
3144                    finally {
3145                            closeSession(session);
3146                    }
3147            }
3148    
3149            /**
3150             * Returns the layouts before and after the current layout in the ordered set of layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
3151             *
3152             * @param plid the primary key of the current layout
3153             * @param groupId the group ID
3154             * @param privateLayout the private layout
3155             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3156             * @return the previous, current, and next layout
3157             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
3158             * @throws SystemException if a system exception occurred
3159             */
3160            public Layout[] filterFindByG_P_PrevAndNext(long plid, long groupId,
3161                    boolean privateLayout, OrderByComparator orderByComparator)
3162                    throws NoSuchLayoutException, SystemException {
3163                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3164                            return findByG_P_PrevAndNext(plid, groupId, privateLayout,
3165                                    orderByComparator);
3166                    }
3167    
3168                    Layout layout = findByPrimaryKey(plid);
3169    
3170                    Session session = null;
3171    
3172                    try {
3173                            session = openSession();
3174    
3175                            Layout[] array = new LayoutImpl[3];
3176    
3177                            array[0] = filterGetByG_P_PrevAndNext(session, layout, groupId,
3178                                            privateLayout, orderByComparator, true);
3179    
3180                            array[1] = layout;
3181    
3182                            array[2] = filterGetByG_P_PrevAndNext(session, layout, groupId,
3183                                            privateLayout, orderByComparator, false);
3184    
3185                            return array;
3186                    }
3187                    catch (Exception e) {
3188                            throw processException(e);
3189                    }
3190                    finally {
3191                            closeSession(session);
3192                    }
3193            }
3194    
3195            protected Layout filterGetByG_P_PrevAndNext(Session session, Layout layout,
3196                    long groupId, boolean privateLayout,
3197                    OrderByComparator orderByComparator, boolean previous) {
3198                    StringBundler query = null;
3199    
3200                    if (orderByComparator != null) {
3201                            query = new StringBundler(6 +
3202                                            (orderByComparator.getOrderByFields().length * 6));
3203                    }
3204                    else {
3205                            query = new StringBundler(3);
3206                    }
3207    
3208                    if (getDB().isSupportsInlineDistinct()) {
3209                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
3210                    }
3211                    else {
3212                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
3213                    }
3214    
3215                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3216    
3217                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
3218    
3219                    if (!getDB().isSupportsInlineDistinct()) {
3220                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
3221                    }
3222    
3223                    if (orderByComparator != null) {
3224                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3225    
3226                            if (orderByConditionFields.length > 0) {
3227                                    query.append(WHERE_AND);
3228                            }
3229    
3230                            for (int i = 0; i < orderByConditionFields.length; i++) {
3231                                    if (getDB().isSupportsInlineDistinct()) {
3232                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3233                                    }
3234                                    else {
3235                                            query.append(_ORDER_BY_ENTITY_TABLE);
3236                                    }
3237    
3238                                    query.append(orderByConditionFields[i]);
3239    
3240                                    if ((i + 1) < orderByConditionFields.length) {
3241                                            if (orderByComparator.isAscending() ^ previous) {
3242                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3243                                            }
3244                                            else {
3245                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3246                                            }
3247                                    }
3248                                    else {
3249                                            if (orderByComparator.isAscending() ^ previous) {
3250                                                    query.append(WHERE_GREATER_THAN);
3251                                            }
3252                                            else {
3253                                                    query.append(WHERE_LESSER_THAN);
3254                                            }
3255                                    }
3256                            }
3257    
3258                            query.append(ORDER_BY_CLAUSE);
3259    
3260                            String[] orderByFields = orderByComparator.getOrderByFields();
3261    
3262                            for (int i = 0; i < orderByFields.length; i++) {
3263                                    if (getDB().isSupportsInlineDistinct()) {
3264                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3265                                    }
3266                                    else {
3267                                            query.append(_ORDER_BY_ENTITY_TABLE);
3268                                    }
3269    
3270                                    query.append(orderByFields[i]);
3271    
3272                                    if ((i + 1) < orderByFields.length) {
3273                                            if (orderByComparator.isAscending() ^ previous) {
3274                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3275                                            }
3276                                            else {
3277                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3278                                            }
3279                                    }
3280                                    else {
3281                                            if (orderByComparator.isAscending() ^ previous) {
3282                                                    query.append(ORDER_BY_ASC);
3283                                            }
3284                                            else {
3285                                                    query.append(ORDER_BY_DESC);
3286                                            }
3287                                    }
3288                            }
3289                    }
3290    
3291                    else {
3292                            if (getDB().isSupportsInlineDistinct()) {
3293                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
3294                            }
3295                            else {
3296                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
3297                            }
3298                    }
3299    
3300                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3301                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
3302                                    groupId);
3303    
3304                    SQLQuery q = session.createSQLQuery(sql);
3305    
3306                    q.setFirstResult(0);
3307                    q.setMaxResults(2);
3308    
3309                    if (getDB().isSupportsInlineDistinct()) {
3310                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
3311                    }
3312                    else {
3313                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
3314                    }
3315    
3316                    QueryPos qPos = QueryPos.getInstance(q);
3317    
3318                    qPos.add(groupId);
3319    
3320                    qPos.add(privateLayout);
3321    
3322                    if (orderByComparator != null) {
3323                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
3324    
3325                            for (Object value : values) {
3326                                    qPos.add(value);
3327                            }
3328                    }
3329    
3330                    List<Layout> list = q.list();
3331    
3332                    if (list.size() == 2) {
3333                            return list.get(1);
3334                    }
3335                    else {
3336                            return null;
3337                    }
3338            }
3339    
3340            /**
3341             * Returns the layout where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutException} if it could not be found.
3342             *
3343             * @param groupId the group ID
3344             * @param privateLayout the private layout
3345             * @param layoutId the layout ID
3346             * @return the matching layout
3347             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
3348             * @throws SystemException if a system exception occurred
3349             */
3350            public Layout findByG_P_L(long groupId, boolean privateLayout, long layoutId)
3351                    throws NoSuchLayoutException, SystemException {
3352                    Layout layout = fetchByG_P_L(groupId, privateLayout, layoutId);
3353    
3354                    if (layout == null) {
3355                            StringBundler msg = new StringBundler(8);
3356    
3357                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3358    
3359                            msg.append("groupId=");
3360                            msg.append(groupId);
3361    
3362                            msg.append(", privateLayout=");
3363                            msg.append(privateLayout);
3364    
3365                            msg.append(", layoutId=");
3366                            msg.append(layoutId);
3367    
3368                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3369    
3370                            if (_log.isWarnEnabled()) {
3371                                    _log.warn(msg.toString());
3372                            }
3373    
3374                            throw new NoSuchLayoutException(msg.toString());
3375                    }
3376    
3377                    return layout;
3378            }
3379    
3380            /**
3381             * Returns the layout where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
3382             *
3383             * @param groupId the group ID
3384             * @param privateLayout the private layout
3385             * @param layoutId the layout ID
3386             * @return the matching layout, or <code>null</code> if a matching layout could not be found
3387             * @throws SystemException if a system exception occurred
3388             */
3389            public Layout fetchByG_P_L(long groupId, boolean privateLayout,
3390                    long layoutId) throws SystemException {
3391                    return fetchByG_P_L(groupId, privateLayout, layoutId, true);
3392            }
3393    
3394            /**
3395             * Returns the layout where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
3396             *
3397             * @param groupId the group ID
3398             * @param privateLayout the private layout
3399             * @param layoutId the layout ID
3400             * @param retrieveFromCache whether to use the finder cache
3401             * @return the matching layout, or <code>null</code> if a matching layout could not be found
3402             * @throws SystemException if a system exception occurred
3403             */
3404            public Layout fetchByG_P_L(long groupId, boolean privateLayout,
3405                    long layoutId, boolean retrieveFromCache) throws SystemException {
3406                    Object[] finderArgs = new Object[] { groupId, privateLayout, layoutId };
3407    
3408                    Object result = null;
3409    
3410                    if (retrieveFromCache) {
3411                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_L,
3412                                            finderArgs, this);
3413                    }
3414    
3415                    if (result == null) {
3416                            StringBundler query = new StringBundler(5);
3417    
3418                            query.append(_SQL_SELECT_LAYOUT_WHERE);
3419    
3420                            query.append(_FINDER_COLUMN_G_P_L_GROUPID_2);
3421    
3422                            query.append(_FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2);
3423    
3424                            query.append(_FINDER_COLUMN_G_P_L_LAYOUTID_2);
3425    
3426                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
3427    
3428                            String sql = query.toString();
3429    
3430                            Session session = null;
3431    
3432                            try {
3433                                    session = openSession();
3434    
3435                                    Query q = session.createQuery(sql);
3436    
3437                                    QueryPos qPos = QueryPos.getInstance(q);
3438    
3439                                    qPos.add(groupId);
3440    
3441                                    qPos.add(privateLayout);
3442    
3443                                    qPos.add(layoutId);
3444    
3445                                    List<Layout> list = q.list();
3446    
3447                                    result = list;
3448    
3449                                    Layout layout = null;
3450    
3451                                    if (list.isEmpty()) {
3452                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L,
3453                                                    finderArgs, list);
3454                                    }
3455                                    else {
3456                                            layout = list.get(0);
3457    
3458                                            cacheResult(layout);
3459    
3460                                            if ((layout.getGroupId() != groupId) ||
3461                                                            (layout.getPrivateLayout() != privateLayout) ||
3462                                                            (layout.getLayoutId() != layoutId)) {
3463                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L,
3464                                                            finderArgs, layout);
3465                                            }
3466                                    }
3467    
3468                                    return layout;
3469                            }
3470                            catch (Exception e) {
3471                                    throw processException(e);
3472                            }
3473                            finally {
3474                                    if (result == null) {
3475                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_L,
3476                                                    finderArgs);
3477                                    }
3478    
3479                                    closeSession(session);
3480                            }
3481                    }
3482                    else {
3483                            if (result instanceof List<?>) {
3484                                    return null;
3485                            }
3486                            else {
3487                                    return (Layout)result;
3488                            }
3489                    }
3490            }
3491    
3492            /**
3493             * Returns all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
3494             *
3495             * @param groupId the group ID
3496             * @param privateLayout the private layout
3497             * @param parentLayoutId the parent layout ID
3498             * @return the matching layouts
3499             * @throws SystemException if a system exception occurred
3500             */
3501            public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
3502                    long parentLayoutId) throws SystemException {
3503                    return findByG_P_P(groupId, privateLayout, parentLayoutId,
3504                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3505            }
3506    
3507            /**
3508             * Returns a range of all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
3509             *
3510             * <p>
3511             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3512             * </p>
3513             *
3514             * @param groupId the group ID
3515             * @param privateLayout the private layout
3516             * @param parentLayoutId the parent layout ID
3517             * @param start the lower bound of the range of layouts
3518             * @param end the upper bound of the range of layouts (not inclusive)
3519             * @return the range of matching layouts
3520             * @throws SystemException if a system exception occurred
3521             */
3522            public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
3523                    long parentLayoutId, int start, int end) throws SystemException {
3524                    return findByG_P_P(groupId, privateLayout, parentLayoutId, start, end,
3525                            null);
3526            }
3527    
3528            /**
3529             * Returns an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
3530             *
3531             * <p>
3532             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3533             * </p>
3534             *
3535             * @param groupId the group ID
3536             * @param privateLayout the private layout
3537             * @param parentLayoutId the parent layout ID
3538             * @param start the lower bound of the range of layouts
3539             * @param end the upper bound of the range of layouts (not inclusive)
3540             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3541             * @return the ordered range of matching layouts
3542             * @throws SystemException if a system exception occurred
3543             */
3544            public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
3545                    long parentLayoutId, int start, int end,
3546                    OrderByComparator orderByComparator) throws SystemException {
3547                    FinderPath finderPath = null;
3548                    Object[] finderArgs = null;
3549    
3550                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3551                                    (orderByComparator == null)) {
3552                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_P;
3553                            finderArgs = new Object[] { groupId, privateLayout, parentLayoutId };
3554                    }
3555                    else {
3556                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_P;
3557                            finderArgs = new Object[] {
3558                                            groupId, privateLayout, parentLayoutId,
3559                                            
3560                                            start, end, orderByComparator
3561                                    };
3562                    }
3563    
3564                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(finderPath,
3565                                    finderArgs, this);
3566    
3567                    if (list == null) {
3568                            StringBundler query = null;
3569    
3570                            if (orderByComparator != null) {
3571                                    query = new StringBundler(5 +
3572                                                    (orderByComparator.getOrderByFields().length * 3));
3573                            }
3574                            else {
3575                                    query = new StringBundler(5);
3576                            }
3577    
3578                            query.append(_SQL_SELECT_LAYOUT_WHERE);
3579    
3580                            query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
3581    
3582                            query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
3583    
3584                            query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
3585    
3586                            if (orderByComparator != null) {
3587                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3588                                            orderByComparator);
3589                            }
3590    
3591                            else {
3592                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
3593                            }
3594    
3595                            String sql = query.toString();
3596    
3597                            Session session = null;
3598    
3599                            try {
3600                                    session = openSession();
3601    
3602                                    Query q = session.createQuery(sql);
3603    
3604                                    QueryPos qPos = QueryPos.getInstance(q);
3605    
3606                                    qPos.add(groupId);
3607    
3608                                    qPos.add(privateLayout);
3609    
3610                                    qPos.add(parentLayoutId);
3611    
3612                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
3613                            }
3614                            catch (Exception e) {
3615                                    throw processException(e);
3616                            }
3617                            finally {
3618                                    if (list == null) {
3619                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3620                                    }
3621                                    else {
3622                                            cacheResult(list);
3623    
3624                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3625                                    }
3626    
3627                                    closeSession(session);
3628                            }
3629                    }
3630    
3631                    return list;
3632            }
3633    
3634            /**
3635             * Returns the first layout in the ordered set where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
3636             *
3637             * <p>
3638             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3639             * </p>
3640             *
3641             * @param groupId the group ID
3642             * @param privateLayout the private layout
3643             * @param parentLayoutId the parent layout ID
3644             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3645             * @return the first matching layout
3646             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
3647             * @throws SystemException if a system exception occurred
3648             */
3649            public Layout findByG_P_P_First(long groupId, boolean privateLayout,
3650                    long parentLayoutId, OrderByComparator orderByComparator)
3651                    throws NoSuchLayoutException, SystemException {
3652                    List<Layout> list = findByG_P_P(groupId, privateLayout, parentLayoutId,
3653                                    0, 1, orderByComparator);
3654    
3655                    if (list.isEmpty()) {
3656                            StringBundler msg = new StringBundler(8);
3657    
3658                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3659    
3660                            msg.append("groupId=");
3661                            msg.append(groupId);
3662    
3663                            msg.append(", privateLayout=");
3664                            msg.append(privateLayout);
3665    
3666                            msg.append(", parentLayoutId=");
3667                            msg.append(parentLayoutId);
3668    
3669                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3670    
3671                            throw new NoSuchLayoutException(msg.toString());
3672                    }
3673                    else {
3674                            return list.get(0);
3675                    }
3676            }
3677    
3678            /**
3679             * Returns the last layout in the ordered set where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
3680             *
3681             * <p>
3682             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3683             * </p>
3684             *
3685             * @param groupId the group ID
3686             * @param privateLayout the private layout
3687             * @param parentLayoutId the parent layout ID
3688             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3689             * @return the last matching layout
3690             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
3691             * @throws SystemException if a system exception occurred
3692             */
3693            public Layout findByG_P_P_Last(long groupId, boolean privateLayout,
3694                    long parentLayoutId, OrderByComparator orderByComparator)
3695                    throws NoSuchLayoutException, SystemException {
3696                    int count = countByG_P_P(groupId, privateLayout, parentLayoutId);
3697    
3698                    List<Layout> list = findByG_P_P(groupId, privateLayout, parentLayoutId,
3699                                    count - 1, count, orderByComparator);
3700    
3701                    if (list.isEmpty()) {
3702                            StringBundler msg = new StringBundler(8);
3703    
3704                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3705    
3706                            msg.append("groupId=");
3707                            msg.append(groupId);
3708    
3709                            msg.append(", privateLayout=");
3710                            msg.append(privateLayout);
3711    
3712                            msg.append(", parentLayoutId=");
3713                            msg.append(parentLayoutId);
3714    
3715                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3716    
3717                            throw new NoSuchLayoutException(msg.toString());
3718                    }
3719                    else {
3720                            return list.get(0);
3721                    }
3722            }
3723    
3724            /**
3725             * Returns the layouts before and after the current layout in the ordered set where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
3726             *
3727             * <p>
3728             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3729             * </p>
3730             *
3731             * @param plid the primary key of the current layout
3732             * @param groupId the group ID
3733             * @param privateLayout the private layout
3734             * @param parentLayoutId the parent layout ID
3735             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3736             * @return the previous, current, and next layout
3737             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
3738             * @throws SystemException if a system exception occurred
3739             */
3740            public Layout[] findByG_P_P_PrevAndNext(long plid, long groupId,
3741                    boolean privateLayout, long parentLayoutId,
3742                    OrderByComparator orderByComparator)
3743                    throws NoSuchLayoutException, SystemException {
3744                    Layout layout = findByPrimaryKey(plid);
3745    
3746                    Session session = null;
3747    
3748                    try {
3749                            session = openSession();
3750    
3751                            Layout[] array = new LayoutImpl[3];
3752    
3753                            array[0] = getByG_P_P_PrevAndNext(session, layout, groupId,
3754                                            privateLayout, parentLayoutId, orderByComparator, true);
3755    
3756                            array[1] = layout;
3757    
3758                            array[2] = getByG_P_P_PrevAndNext(session, layout, groupId,
3759                                            privateLayout, parentLayoutId, orderByComparator, false);
3760    
3761                            return array;
3762                    }
3763                    catch (Exception e) {
3764                            throw processException(e);
3765                    }
3766                    finally {
3767                            closeSession(session);
3768                    }
3769            }
3770    
3771            protected Layout getByG_P_P_PrevAndNext(Session session, Layout layout,
3772                    long groupId, boolean privateLayout, long parentLayoutId,
3773                    OrderByComparator orderByComparator, boolean previous) {
3774                    StringBundler query = null;
3775    
3776                    if (orderByComparator != null) {
3777                            query = new StringBundler(6 +
3778                                            (orderByComparator.getOrderByFields().length * 6));
3779                    }
3780                    else {
3781                            query = new StringBundler(3);
3782                    }
3783    
3784                    query.append(_SQL_SELECT_LAYOUT_WHERE);
3785    
3786                    query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
3787    
3788                    query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
3789    
3790                    query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
3791    
3792                    if (orderByComparator != null) {
3793                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3794    
3795                            if (orderByConditionFields.length > 0) {
3796                                    query.append(WHERE_AND);
3797                            }
3798    
3799                            for (int i = 0; i < orderByConditionFields.length; i++) {
3800                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3801                                    query.append(orderByConditionFields[i]);
3802    
3803                                    if ((i + 1) < orderByConditionFields.length) {
3804                                            if (orderByComparator.isAscending() ^ previous) {
3805                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3806                                            }
3807                                            else {
3808                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3809                                            }
3810                                    }
3811                                    else {
3812                                            if (orderByComparator.isAscending() ^ previous) {
3813                                                    query.append(WHERE_GREATER_THAN);
3814                                            }
3815                                            else {
3816                                                    query.append(WHERE_LESSER_THAN);
3817                                            }
3818                                    }
3819                            }
3820    
3821                            query.append(ORDER_BY_CLAUSE);
3822    
3823                            String[] orderByFields = orderByComparator.getOrderByFields();
3824    
3825                            for (int i = 0; i < orderByFields.length; i++) {
3826                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3827                                    query.append(orderByFields[i]);
3828    
3829                                    if ((i + 1) < orderByFields.length) {
3830                                            if (orderByComparator.isAscending() ^ previous) {
3831                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3832                                            }
3833                                            else {
3834                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3835                                            }
3836                                    }
3837                                    else {
3838                                            if (orderByComparator.isAscending() ^ previous) {
3839                                                    query.append(ORDER_BY_ASC);
3840                                            }
3841                                            else {
3842                                                    query.append(ORDER_BY_DESC);
3843                                            }
3844                                    }
3845                            }
3846                    }
3847    
3848                    else {
3849                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
3850                    }
3851    
3852                    String sql = query.toString();
3853    
3854                    Query q = session.createQuery(sql);
3855    
3856                    q.setFirstResult(0);
3857                    q.setMaxResults(2);
3858    
3859                    QueryPos qPos = QueryPos.getInstance(q);
3860    
3861                    qPos.add(groupId);
3862    
3863                    qPos.add(privateLayout);
3864    
3865                    qPos.add(parentLayoutId);
3866    
3867                    if (orderByComparator != null) {
3868                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
3869    
3870                            for (Object value : values) {
3871                                    qPos.add(value);
3872                            }
3873                    }
3874    
3875                    List<Layout> list = q.list();
3876    
3877                    if (list.size() == 2) {
3878                            return list.get(1);
3879                    }
3880                    else {
3881                            return null;
3882                    }
3883            }
3884    
3885            /**
3886             * Returns all the layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
3887             *
3888             * @param groupId the group ID
3889             * @param privateLayout the private layout
3890             * @param parentLayoutId the parent layout ID
3891             * @return the matching layouts that the user has permission to view
3892             * @throws SystemException if a system exception occurred
3893             */
3894            public List<Layout> filterFindByG_P_P(long groupId, boolean privateLayout,
3895                    long parentLayoutId) throws SystemException {
3896                    return filterFindByG_P_P(groupId, privateLayout, parentLayoutId,
3897                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3898            }
3899    
3900            /**
3901             * Returns a range of all the layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
3902             *
3903             * <p>
3904             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3905             * </p>
3906             *
3907             * @param groupId the group ID
3908             * @param privateLayout the private layout
3909             * @param parentLayoutId the parent layout ID
3910             * @param start the lower bound of the range of layouts
3911             * @param end the upper bound of the range of layouts (not inclusive)
3912             * @return the range of matching layouts that the user has permission to view
3913             * @throws SystemException if a system exception occurred
3914             */
3915            public List<Layout> filterFindByG_P_P(long groupId, boolean privateLayout,
3916                    long parentLayoutId, int start, int end) throws SystemException {
3917                    return filterFindByG_P_P(groupId, privateLayout, parentLayoutId, start,
3918                            end, null);
3919            }
3920    
3921            /**
3922             * Returns an ordered range of all the layouts that the user has permissions to view where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
3923             *
3924             * <p>
3925             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3926             * </p>
3927             *
3928             * @param groupId the group ID
3929             * @param privateLayout the private layout
3930             * @param parentLayoutId the parent layout ID
3931             * @param start the lower bound of the range of layouts
3932             * @param end the upper bound of the range of layouts (not inclusive)
3933             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3934             * @return the ordered range of matching layouts that the user has permission to view
3935             * @throws SystemException if a system exception occurred
3936             */
3937            public List<Layout> filterFindByG_P_P(long groupId, boolean privateLayout,
3938                    long parentLayoutId, int start, int end,
3939                    OrderByComparator orderByComparator) throws SystemException {
3940                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3941                            return findByG_P_P(groupId, privateLayout, parentLayoutId, start,
3942                                    end, orderByComparator);
3943                    }
3944    
3945                    StringBundler query = null;
3946    
3947                    if (orderByComparator != null) {
3948                            query = new StringBundler(5 +
3949                                            (orderByComparator.getOrderByFields().length * 3));
3950                    }
3951                    else {
3952                            query = new StringBundler(5);
3953                    }
3954    
3955                    if (getDB().isSupportsInlineDistinct()) {
3956                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
3957                    }
3958                    else {
3959                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
3960                    }
3961    
3962                    query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
3963    
3964                    query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
3965    
3966                    query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
3967    
3968                    if (!getDB().isSupportsInlineDistinct()) {
3969                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
3970                    }
3971    
3972                    if (orderByComparator != null) {
3973                            if (getDB().isSupportsInlineDistinct()) {
3974                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3975                                            orderByComparator);
3976                            }
3977                            else {
3978                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3979                                            orderByComparator);
3980                            }
3981                    }
3982    
3983                    else {
3984                            if (getDB().isSupportsInlineDistinct()) {
3985                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
3986                            }
3987                            else {
3988                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
3989                            }
3990                    }
3991    
3992                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3993                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
3994                                    groupId);
3995    
3996                    Session session = null;
3997    
3998                    try {
3999                            session = openSession();
4000    
4001                            SQLQuery q = session.createSQLQuery(sql);
4002    
4003                            if (getDB().isSupportsInlineDistinct()) {
4004                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
4005                            }
4006                            else {
4007                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
4008                            }
4009    
4010                            QueryPos qPos = QueryPos.getInstance(q);
4011    
4012                            qPos.add(groupId);
4013    
4014                            qPos.add(privateLayout);
4015    
4016                            qPos.add(parentLayoutId);
4017    
4018                            return (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
4019                    }
4020                    catch (Exception e) {
4021                            throw processException(e);
4022                    }
4023                    finally {
4024                            closeSession(session);
4025                    }
4026            }
4027    
4028            /**
4029             * Returns the layouts before and after the current layout in the ordered set of layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
4030             *
4031             * @param plid the primary key of the current layout
4032             * @param groupId the group ID
4033             * @param privateLayout the private layout
4034             * @param parentLayoutId the parent layout ID
4035             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4036             * @return the previous, current, and next layout
4037             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
4038             * @throws SystemException if a system exception occurred
4039             */
4040            public Layout[] filterFindByG_P_P_PrevAndNext(long plid, long groupId,
4041                    boolean privateLayout, long parentLayoutId,
4042                    OrderByComparator orderByComparator)
4043                    throws NoSuchLayoutException, SystemException {
4044                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4045                            return findByG_P_P_PrevAndNext(plid, groupId, privateLayout,
4046                                    parentLayoutId, orderByComparator);
4047                    }
4048    
4049                    Layout layout = findByPrimaryKey(plid);
4050    
4051                    Session session = null;
4052    
4053                    try {
4054                            session = openSession();
4055    
4056                            Layout[] array = new LayoutImpl[3];
4057    
4058                            array[0] = filterGetByG_P_P_PrevAndNext(session, layout, groupId,
4059                                            privateLayout, parentLayoutId, orderByComparator, true);
4060    
4061                            array[1] = layout;
4062    
4063                            array[2] = filterGetByG_P_P_PrevAndNext(session, layout, groupId,
4064                                            privateLayout, parentLayoutId, orderByComparator, false);
4065    
4066                            return array;
4067                    }
4068                    catch (Exception e) {
4069                            throw processException(e);
4070                    }
4071                    finally {
4072                            closeSession(session);
4073                    }
4074            }
4075    
4076            protected Layout filterGetByG_P_P_PrevAndNext(Session session,
4077                    Layout layout, long groupId, boolean privateLayout,
4078                    long parentLayoutId, OrderByComparator orderByComparator,
4079                    boolean previous) {
4080                    StringBundler query = null;
4081    
4082                    if (orderByComparator != null) {
4083                            query = new StringBundler(6 +
4084                                            (orderByComparator.getOrderByFields().length * 6));
4085                    }
4086                    else {
4087                            query = new StringBundler(3);
4088                    }
4089    
4090                    if (getDB().isSupportsInlineDistinct()) {
4091                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
4092                    }
4093                    else {
4094                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
4095                    }
4096    
4097                    query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
4098    
4099                    query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
4100    
4101                    query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
4102    
4103                    if (!getDB().isSupportsInlineDistinct()) {
4104                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
4105                    }
4106    
4107                    if (orderByComparator != null) {
4108                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4109    
4110                            if (orderByConditionFields.length > 0) {
4111                                    query.append(WHERE_AND);
4112                            }
4113    
4114                            for (int i = 0; i < orderByConditionFields.length; i++) {
4115                                    if (getDB().isSupportsInlineDistinct()) {
4116                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4117                                    }
4118                                    else {
4119                                            query.append(_ORDER_BY_ENTITY_TABLE);
4120                                    }
4121    
4122                                    query.append(orderByConditionFields[i]);
4123    
4124                                    if ((i + 1) < orderByConditionFields.length) {
4125                                            if (orderByComparator.isAscending() ^ previous) {
4126                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4127                                            }
4128                                            else {
4129                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4130                                            }
4131                                    }
4132                                    else {
4133                                            if (orderByComparator.isAscending() ^ previous) {
4134                                                    query.append(WHERE_GREATER_THAN);
4135                                            }
4136                                            else {
4137                                                    query.append(WHERE_LESSER_THAN);
4138                                            }
4139                                    }
4140                            }
4141    
4142                            query.append(ORDER_BY_CLAUSE);
4143    
4144                            String[] orderByFields = orderByComparator.getOrderByFields();
4145    
4146                            for (int i = 0; i < orderByFields.length; i++) {
4147                                    if (getDB().isSupportsInlineDistinct()) {
4148                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4149                                    }
4150                                    else {
4151                                            query.append(_ORDER_BY_ENTITY_TABLE);
4152                                    }
4153    
4154                                    query.append(orderByFields[i]);
4155    
4156                                    if ((i + 1) < orderByFields.length) {
4157                                            if (orderByComparator.isAscending() ^ previous) {
4158                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4159                                            }
4160                                            else {
4161                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4162                                            }
4163                                    }
4164                                    else {
4165                                            if (orderByComparator.isAscending() ^ previous) {
4166                                                    query.append(ORDER_BY_ASC);
4167                                            }
4168                                            else {
4169                                                    query.append(ORDER_BY_DESC);
4170                                            }
4171                                    }
4172                            }
4173                    }
4174    
4175                    else {
4176                            if (getDB().isSupportsInlineDistinct()) {
4177                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
4178                            }
4179                            else {
4180                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
4181                            }
4182                    }
4183    
4184                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4185                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
4186                                    groupId);
4187    
4188                    SQLQuery q = session.createSQLQuery(sql);
4189    
4190                    q.setFirstResult(0);
4191                    q.setMaxResults(2);
4192    
4193                    if (getDB().isSupportsInlineDistinct()) {
4194                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
4195                    }
4196                    else {
4197                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
4198                    }
4199    
4200                    QueryPos qPos = QueryPos.getInstance(q);
4201    
4202                    qPos.add(groupId);
4203    
4204                    qPos.add(privateLayout);
4205    
4206                    qPos.add(parentLayoutId);
4207    
4208                    if (orderByComparator != null) {
4209                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
4210    
4211                            for (Object value : values) {
4212                                    qPos.add(value);
4213                            }
4214                    }
4215    
4216                    List<Layout> list = q.list();
4217    
4218                    if (list.size() == 2) {
4219                            return list.get(1);
4220                    }
4221                    else {
4222                            return null;
4223                    }
4224            }
4225    
4226            /**
4227             * Returns the layout where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutException} if it could not be found.
4228             *
4229             * @param groupId the group ID
4230             * @param privateLayout the private layout
4231             * @param friendlyURL the friendly u r l
4232             * @return the matching layout
4233             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
4234             * @throws SystemException if a system exception occurred
4235             */
4236            public Layout findByG_P_F(long groupId, boolean privateLayout,
4237                    String friendlyURL) throws NoSuchLayoutException, SystemException {
4238                    Layout layout = fetchByG_P_F(groupId, privateLayout, friendlyURL);
4239    
4240                    if (layout == null) {
4241                            StringBundler msg = new StringBundler(8);
4242    
4243                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4244    
4245                            msg.append("groupId=");
4246                            msg.append(groupId);
4247    
4248                            msg.append(", privateLayout=");
4249                            msg.append(privateLayout);
4250    
4251                            msg.append(", friendlyURL=");
4252                            msg.append(friendlyURL);
4253    
4254                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4255    
4256                            if (_log.isWarnEnabled()) {
4257                                    _log.warn(msg.toString());
4258                            }
4259    
4260                            throw new NoSuchLayoutException(msg.toString());
4261                    }
4262    
4263                    return layout;
4264            }
4265    
4266            /**
4267             * Returns the layout where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
4268             *
4269             * @param groupId the group ID
4270             * @param privateLayout the private layout
4271             * @param friendlyURL the friendly u r l
4272             * @return the matching layout, or <code>null</code> if a matching layout could not be found
4273             * @throws SystemException if a system exception occurred
4274             */
4275            public Layout fetchByG_P_F(long groupId, boolean privateLayout,
4276                    String friendlyURL) throws SystemException {
4277                    return fetchByG_P_F(groupId, privateLayout, friendlyURL, true);
4278            }
4279    
4280            /**
4281             * Returns the layout where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
4282             *
4283             * @param groupId the group ID
4284             * @param privateLayout the private layout
4285             * @param friendlyURL the friendly u r l
4286             * @param retrieveFromCache whether to use the finder cache
4287             * @return the matching layout, or <code>null</code> if a matching layout could not be found
4288             * @throws SystemException if a system exception occurred
4289             */
4290            public Layout fetchByG_P_F(long groupId, boolean privateLayout,
4291                    String friendlyURL, boolean retrieveFromCache)
4292                    throws SystemException {
4293                    Object[] finderArgs = new Object[] { groupId, privateLayout, friendlyURL };
4294    
4295                    Object result = null;
4296    
4297                    if (retrieveFromCache) {
4298                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_F,
4299                                            finderArgs, this);
4300                    }
4301    
4302                    if (result == null) {
4303                            StringBundler query = new StringBundler(5);
4304    
4305                            query.append(_SQL_SELECT_LAYOUT_WHERE);
4306    
4307                            query.append(_FINDER_COLUMN_G_P_F_GROUPID_2);
4308    
4309                            query.append(_FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2);
4310    
4311                            if (friendlyURL == null) {
4312                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_1);
4313                            }
4314                            else {
4315                                    if (friendlyURL.equals(StringPool.BLANK)) {
4316                                            query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_3);
4317                                    }
4318                                    else {
4319                                            query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_2);
4320                                    }
4321                            }
4322    
4323                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
4324    
4325                            String sql = query.toString();
4326    
4327                            Session session = null;
4328    
4329                            try {
4330                                    session = openSession();
4331    
4332                                    Query q = session.createQuery(sql);
4333    
4334                                    QueryPos qPos = QueryPos.getInstance(q);
4335    
4336                                    qPos.add(groupId);
4337    
4338                                    qPos.add(privateLayout);
4339    
4340                                    if (friendlyURL != null) {
4341                                            qPos.add(friendlyURL);
4342                                    }
4343    
4344                                    List<Layout> list = q.list();
4345    
4346                                    result = list;
4347    
4348                                    Layout layout = null;
4349    
4350                                    if (list.isEmpty()) {
4351                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_F,
4352                                                    finderArgs, list);
4353                                    }
4354                                    else {
4355                                            layout = list.get(0);
4356    
4357                                            cacheResult(layout);
4358    
4359                                            if ((layout.getGroupId() != groupId) ||
4360                                                            (layout.getPrivateLayout() != privateLayout) ||
4361                                                            (layout.getFriendlyURL() == null) ||
4362                                                            !layout.getFriendlyURL().equals(friendlyURL)) {
4363                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_F,
4364                                                            finderArgs, layout);
4365                                            }
4366                                    }
4367    
4368                                    return layout;
4369                            }
4370                            catch (Exception e) {
4371                                    throw processException(e);
4372                            }
4373                            finally {
4374                                    if (result == null) {
4375                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_F,
4376                                                    finderArgs);
4377                                    }
4378    
4379                                    closeSession(session);
4380                            }
4381                    }
4382                    else {
4383                            if (result instanceof List<?>) {
4384                                    return null;
4385                            }
4386                            else {
4387                                    return (Layout)result;
4388                            }
4389                    }
4390            }
4391    
4392            /**
4393             * Returns all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
4394             *
4395             * @param groupId the group ID
4396             * @param privateLayout the private layout
4397             * @param type the type
4398             * @return the matching layouts
4399             * @throws SystemException if a system exception occurred
4400             */
4401            public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
4402                    String type) throws SystemException {
4403                    return findByG_P_T(groupId, privateLayout, type, QueryUtil.ALL_POS,
4404                            QueryUtil.ALL_POS, null);
4405            }
4406    
4407            /**
4408             * Returns a range of all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
4409             *
4410             * <p>
4411             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4412             * </p>
4413             *
4414             * @param groupId the group ID
4415             * @param privateLayout the private layout
4416             * @param type the type
4417             * @param start the lower bound of the range of layouts
4418             * @param end the upper bound of the range of layouts (not inclusive)
4419             * @return the range of matching layouts
4420             * @throws SystemException if a system exception occurred
4421             */
4422            public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
4423                    String type, int start, int end) throws SystemException {
4424                    return findByG_P_T(groupId, privateLayout, type, start, end, null);
4425            }
4426    
4427            /**
4428             * Returns an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
4429             *
4430             * <p>
4431             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4432             * </p>
4433             *
4434             * @param groupId the group ID
4435             * @param privateLayout the private layout
4436             * @param type the type
4437             * @param start the lower bound of the range of layouts
4438             * @param end the upper bound of the range of layouts (not inclusive)
4439             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4440             * @return the ordered range of matching layouts
4441             * @throws SystemException if a system exception occurred
4442             */
4443            public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
4444                    String type, int start, int end, OrderByComparator orderByComparator)
4445                    throws SystemException {
4446                    FinderPath finderPath = null;
4447                    Object[] finderArgs = null;
4448    
4449                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4450                                    (orderByComparator == null)) {
4451                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_T;
4452                            finderArgs = new Object[] { groupId, privateLayout, type };
4453                    }
4454                    else {
4455                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_T;
4456                            finderArgs = new Object[] {
4457                                            groupId, privateLayout, type,
4458                                            
4459                                            start, end, orderByComparator
4460                                    };
4461                    }
4462    
4463                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(finderPath,
4464                                    finderArgs, this);
4465    
4466                    if (list == null) {
4467                            StringBundler query = null;
4468    
4469                            if (orderByComparator != null) {
4470                                    query = new StringBundler(5 +
4471                                                    (orderByComparator.getOrderByFields().length * 3));
4472                            }
4473                            else {
4474                                    query = new StringBundler(5);
4475                            }
4476    
4477                            query.append(_SQL_SELECT_LAYOUT_WHERE);
4478    
4479                            query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
4480    
4481                            query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
4482    
4483                            if (type == null) {
4484                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
4485                            }
4486                            else {
4487                                    if (type.equals(StringPool.BLANK)) {
4488                                            query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
4489                                    }
4490                                    else {
4491                                            query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
4492                                    }
4493                            }
4494    
4495                            if (orderByComparator != null) {
4496                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4497                                            orderByComparator);
4498                            }
4499    
4500                            else {
4501                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
4502                            }
4503    
4504                            String sql = query.toString();
4505    
4506                            Session session = null;
4507    
4508                            try {
4509                                    session = openSession();
4510    
4511                                    Query q = session.createQuery(sql);
4512    
4513                                    QueryPos qPos = QueryPos.getInstance(q);
4514    
4515                                    qPos.add(groupId);
4516    
4517                                    qPos.add(privateLayout);
4518    
4519                                    if (type != null) {
4520                                            qPos.add(type);
4521                                    }
4522    
4523                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
4524                            }
4525                            catch (Exception e) {
4526                                    throw processException(e);
4527                            }
4528                            finally {
4529                                    if (list == null) {
4530                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4531                                    }
4532                                    else {
4533                                            cacheResult(list);
4534    
4535                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4536                                    }
4537    
4538                                    closeSession(session);
4539                            }
4540                    }
4541    
4542                    return list;
4543            }
4544    
4545            /**
4546             * Returns the first layout in the ordered set where groupId = &#63; and privateLayout = &#63; and type = &#63;.
4547             *
4548             * <p>
4549             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4550             * </p>
4551             *
4552             * @param groupId the group ID
4553             * @param privateLayout the private layout
4554             * @param type the type
4555             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4556             * @return the first matching layout
4557             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
4558             * @throws SystemException if a system exception occurred
4559             */
4560            public Layout findByG_P_T_First(long groupId, boolean privateLayout,
4561                    String type, OrderByComparator orderByComparator)
4562                    throws NoSuchLayoutException, SystemException {
4563                    List<Layout> list = findByG_P_T(groupId, privateLayout, type, 0, 1,
4564                                    orderByComparator);
4565    
4566                    if (list.isEmpty()) {
4567                            StringBundler msg = new StringBundler(8);
4568    
4569                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4570    
4571                            msg.append("groupId=");
4572                            msg.append(groupId);
4573    
4574                            msg.append(", privateLayout=");
4575                            msg.append(privateLayout);
4576    
4577                            msg.append(", type=");
4578                            msg.append(type);
4579    
4580                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4581    
4582                            throw new NoSuchLayoutException(msg.toString());
4583                    }
4584                    else {
4585                            return list.get(0);
4586                    }
4587            }
4588    
4589            /**
4590             * Returns the last layout in the ordered set where groupId = &#63; and privateLayout = &#63; and type = &#63;.
4591             *
4592             * <p>
4593             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4594             * </p>
4595             *
4596             * @param groupId the group ID
4597             * @param privateLayout the private layout
4598             * @param type the type
4599             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4600             * @return the last matching layout
4601             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
4602             * @throws SystemException if a system exception occurred
4603             */
4604            public Layout findByG_P_T_Last(long groupId, boolean privateLayout,
4605                    String type, OrderByComparator orderByComparator)
4606                    throws NoSuchLayoutException, SystemException {
4607                    int count = countByG_P_T(groupId, privateLayout, type);
4608    
4609                    List<Layout> list = findByG_P_T(groupId, privateLayout, type,
4610                                    count - 1, count, orderByComparator);
4611    
4612                    if (list.isEmpty()) {
4613                            StringBundler msg = new StringBundler(8);
4614    
4615                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4616    
4617                            msg.append("groupId=");
4618                            msg.append(groupId);
4619    
4620                            msg.append(", privateLayout=");
4621                            msg.append(privateLayout);
4622    
4623                            msg.append(", type=");
4624                            msg.append(type);
4625    
4626                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4627    
4628                            throw new NoSuchLayoutException(msg.toString());
4629                    }
4630                    else {
4631                            return list.get(0);
4632                    }
4633            }
4634    
4635            /**
4636             * Returns the layouts before and after the current layout in the ordered set where groupId = &#63; and privateLayout = &#63; and type = &#63;.
4637             *
4638             * <p>
4639             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4640             * </p>
4641             *
4642             * @param plid the primary key of the current layout
4643             * @param groupId the group ID
4644             * @param privateLayout the private layout
4645             * @param type the type
4646             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4647             * @return the previous, current, and next layout
4648             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
4649             * @throws SystemException if a system exception occurred
4650             */
4651            public Layout[] findByG_P_T_PrevAndNext(long plid, long groupId,
4652                    boolean privateLayout, String type, OrderByComparator orderByComparator)
4653                    throws NoSuchLayoutException, SystemException {
4654                    Layout layout = findByPrimaryKey(plid);
4655    
4656                    Session session = null;
4657    
4658                    try {
4659                            session = openSession();
4660    
4661                            Layout[] array = new LayoutImpl[3];
4662    
4663                            array[0] = getByG_P_T_PrevAndNext(session, layout, groupId,
4664                                            privateLayout, type, orderByComparator, true);
4665    
4666                            array[1] = layout;
4667    
4668                            array[2] = getByG_P_T_PrevAndNext(session, layout, groupId,
4669                                            privateLayout, type, orderByComparator, false);
4670    
4671                            return array;
4672                    }
4673                    catch (Exception e) {
4674                            throw processException(e);
4675                    }
4676                    finally {
4677                            closeSession(session);
4678                    }
4679            }
4680    
4681            protected Layout getByG_P_T_PrevAndNext(Session session, Layout layout,
4682                    long groupId, boolean privateLayout, String type,
4683                    OrderByComparator orderByComparator, boolean previous) {
4684                    StringBundler query = null;
4685    
4686                    if (orderByComparator != null) {
4687                            query = new StringBundler(6 +
4688                                            (orderByComparator.getOrderByFields().length * 6));
4689                    }
4690                    else {
4691                            query = new StringBundler(3);
4692                    }
4693    
4694                    query.append(_SQL_SELECT_LAYOUT_WHERE);
4695    
4696                    query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
4697    
4698                    query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
4699    
4700                    if (type == null) {
4701                            query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
4702                    }
4703                    else {
4704                            if (type.equals(StringPool.BLANK)) {
4705                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
4706                            }
4707                            else {
4708                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
4709                            }
4710                    }
4711    
4712                    if (orderByComparator != null) {
4713                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4714    
4715                            if (orderByConditionFields.length > 0) {
4716                                    query.append(WHERE_AND);
4717                            }
4718    
4719                            for (int i = 0; i < orderByConditionFields.length; i++) {
4720                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4721                                    query.append(orderByConditionFields[i]);
4722    
4723                                    if ((i + 1) < orderByConditionFields.length) {
4724                                            if (orderByComparator.isAscending() ^ previous) {
4725                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4726                                            }
4727                                            else {
4728                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4729                                            }
4730                                    }
4731                                    else {
4732                                            if (orderByComparator.isAscending() ^ previous) {
4733                                                    query.append(WHERE_GREATER_THAN);
4734                                            }
4735                                            else {
4736                                                    query.append(WHERE_LESSER_THAN);
4737                                            }
4738                                    }
4739                            }
4740    
4741                            query.append(ORDER_BY_CLAUSE);
4742    
4743                            String[] orderByFields = orderByComparator.getOrderByFields();
4744    
4745                            for (int i = 0; i < orderByFields.length; i++) {
4746                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4747                                    query.append(orderByFields[i]);
4748    
4749                                    if ((i + 1) < orderByFields.length) {
4750                                            if (orderByComparator.isAscending() ^ previous) {
4751                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4752                                            }
4753                                            else {
4754                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4755                                            }
4756                                    }
4757                                    else {
4758                                            if (orderByComparator.isAscending() ^ previous) {
4759                                                    query.append(ORDER_BY_ASC);
4760                                            }
4761                                            else {
4762                                                    query.append(ORDER_BY_DESC);
4763                                            }
4764                                    }
4765                            }
4766                    }
4767    
4768                    else {
4769                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
4770                    }
4771    
4772                    String sql = query.toString();
4773    
4774                    Query q = session.createQuery(sql);
4775    
4776                    q.setFirstResult(0);
4777                    q.setMaxResults(2);
4778    
4779                    QueryPos qPos = QueryPos.getInstance(q);
4780    
4781                    qPos.add(groupId);
4782    
4783                    qPos.add(privateLayout);
4784    
4785                    if (type != null) {
4786                            qPos.add(type);
4787                    }
4788    
4789                    if (orderByComparator != null) {
4790                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
4791    
4792                            for (Object value : values) {
4793                                    qPos.add(value);
4794                            }
4795                    }
4796    
4797                    List<Layout> list = q.list();
4798    
4799                    if (list.size() == 2) {
4800                            return list.get(1);
4801                    }
4802                    else {
4803                            return null;
4804                    }
4805            }
4806    
4807            /**
4808             * Returns all the layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and type = &#63;.
4809             *
4810             * @param groupId the group ID
4811             * @param privateLayout the private layout
4812             * @param type the type
4813             * @return the matching layouts that the user has permission to view
4814             * @throws SystemException if a system exception occurred
4815             */
4816            public List<Layout> filterFindByG_P_T(long groupId, boolean privateLayout,
4817                    String type) throws SystemException {
4818                    return filterFindByG_P_T(groupId, privateLayout, type,
4819                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4820            }
4821    
4822            /**
4823             * Returns a range of all the layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and type = &#63;.
4824             *
4825             * <p>
4826             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4827             * </p>
4828             *
4829             * @param groupId the group ID
4830             * @param privateLayout the private layout
4831             * @param type the type
4832             * @param start the lower bound of the range of layouts
4833             * @param end the upper bound of the range of layouts (not inclusive)
4834             * @return the range of matching layouts that the user has permission to view
4835             * @throws SystemException if a system exception occurred
4836             */
4837            public List<Layout> filterFindByG_P_T(long groupId, boolean privateLayout,
4838                    String type, int start, int end) throws SystemException {
4839                    return filterFindByG_P_T(groupId, privateLayout, type, start, end, null);
4840            }
4841    
4842            /**
4843             * Returns an ordered range of all the layouts that the user has permissions to view where groupId = &#63; and privateLayout = &#63; and type = &#63;.
4844             *
4845             * <p>
4846             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4847             * </p>
4848             *
4849             * @param groupId the group ID
4850             * @param privateLayout the private layout
4851             * @param type the type
4852             * @param start the lower bound of the range of layouts
4853             * @param end the upper bound of the range of layouts (not inclusive)
4854             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4855             * @return the ordered range of matching layouts that the user has permission to view
4856             * @throws SystemException if a system exception occurred
4857             */
4858            public List<Layout> filterFindByG_P_T(long groupId, boolean privateLayout,
4859                    String type, int start, int end, OrderByComparator orderByComparator)
4860                    throws SystemException {
4861                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4862                            return findByG_P_T(groupId, privateLayout, type, start, end,
4863                                    orderByComparator);
4864                    }
4865    
4866                    StringBundler query = null;
4867    
4868                    if (orderByComparator != null) {
4869                            query = new StringBundler(5 +
4870                                            (orderByComparator.getOrderByFields().length * 3));
4871                    }
4872                    else {
4873                            query = new StringBundler(5);
4874                    }
4875    
4876                    if (getDB().isSupportsInlineDistinct()) {
4877                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
4878                    }
4879                    else {
4880                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
4881                    }
4882    
4883                    query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
4884    
4885                    query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
4886    
4887                    if (type == null) {
4888                            query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
4889                    }
4890                    else {
4891                            if (type.equals(StringPool.BLANK)) {
4892                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
4893                            }
4894                            else {
4895                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
4896                            }
4897                    }
4898    
4899                    if (!getDB().isSupportsInlineDistinct()) {
4900                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
4901                    }
4902    
4903                    if (orderByComparator != null) {
4904                            if (getDB().isSupportsInlineDistinct()) {
4905                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4906                                            orderByComparator);
4907                            }
4908                            else {
4909                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4910                                            orderByComparator);
4911                            }
4912                    }
4913    
4914                    else {
4915                            if (getDB().isSupportsInlineDistinct()) {
4916                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
4917                            }
4918                            else {
4919                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
4920                            }
4921                    }
4922    
4923                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4924                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
4925                                    groupId);
4926    
4927                    Session session = null;
4928    
4929                    try {
4930                            session = openSession();
4931    
4932                            SQLQuery q = session.createSQLQuery(sql);
4933    
4934                            if (getDB().isSupportsInlineDistinct()) {
4935                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
4936                            }
4937                            else {
4938                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
4939                            }
4940    
4941                            QueryPos qPos = QueryPos.getInstance(q);
4942    
4943                            qPos.add(groupId);
4944    
4945                            qPos.add(privateLayout);
4946    
4947                            if (type != null) {
4948                                    qPos.add(type);
4949                            }
4950    
4951                            return (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
4952                    }
4953                    catch (Exception e) {
4954                            throw processException(e);
4955                    }
4956                    finally {
4957                            closeSession(session);
4958                    }
4959            }
4960    
4961            /**
4962             * Returns the layouts before and after the current layout in the ordered set of layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and type = &#63;.
4963             *
4964             * @param plid the primary key of the current layout
4965             * @param groupId the group ID
4966             * @param privateLayout the private layout
4967             * @param type the type
4968             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4969             * @return the previous, current, and next layout
4970             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
4971             * @throws SystemException if a system exception occurred
4972             */
4973            public Layout[] filterFindByG_P_T_PrevAndNext(long plid, long groupId,
4974                    boolean privateLayout, String type, OrderByComparator orderByComparator)
4975                    throws NoSuchLayoutException, SystemException {
4976                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4977                            return findByG_P_T_PrevAndNext(plid, groupId, privateLayout, type,
4978                                    orderByComparator);
4979                    }
4980    
4981                    Layout layout = findByPrimaryKey(plid);
4982    
4983                    Session session = null;
4984    
4985                    try {
4986                            session = openSession();
4987    
4988                            Layout[] array = new LayoutImpl[3];
4989    
4990                            array[0] = filterGetByG_P_T_PrevAndNext(session, layout, groupId,
4991                                            privateLayout, type, orderByComparator, true);
4992    
4993                            array[1] = layout;
4994    
4995                            array[2] = filterGetByG_P_T_PrevAndNext(session, layout, groupId,
4996                                            privateLayout, type, orderByComparator, false);
4997    
4998                            return array;
4999                    }
5000                    catch (Exception e) {
5001                            throw processException(e);
5002                    }
5003                    finally {
5004                            closeSession(session);
5005                    }
5006            }
5007    
5008            protected Layout filterGetByG_P_T_PrevAndNext(Session session,
5009                    Layout layout, long groupId, boolean privateLayout, String type,
5010                    OrderByComparator orderByComparator, boolean previous) {
5011                    StringBundler query = null;
5012    
5013                    if (orderByComparator != null) {
5014                            query = new StringBundler(6 +
5015                                            (orderByComparator.getOrderByFields().length * 6));
5016                    }
5017                    else {
5018                            query = new StringBundler(3);
5019                    }
5020    
5021                    if (getDB().isSupportsInlineDistinct()) {
5022                            query.append(_FILTER_SQL_SELECT_LAYOUT_WHERE);
5023                    }
5024                    else {
5025                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1);
5026                    }
5027    
5028                    query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
5029    
5030                    query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
5031    
5032                    if (type == null) {
5033                            query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
5034                    }
5035                    else {
5036                            if (type.equals(StringPool.BLANK)) {
5037                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
5038                            }
5039                            else {
5040                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
5041                            }
5042                    }
5043    
5044                    if (!getDB().isSupportsInlineDistinct()) {
5045                            query.append(_FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2);
5046                    }
5047    
5048                    if (orderByComparator != null) {
5049                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5050    
5051                            if (orderByConditionFields.length > 0) {
5052                                    query.append(WHERE_AND);
5053                            }
5054    
5055                            for (int i = 0; i < orderByConditionFields.length; i++) {
5056                                    if (getDB().isSupportsInlineDistinct()) {
5057                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5058                                    }
5059                                    else {
5060                                            query.append(_ORDER_BY_ENTITY_TABLE);
5061                                    }
5062    
5063                                    query.append(orderByConditionFields[i]);
5064    
5065                                    if ((i + 1) < orderByConditionFields.length) {
5066                                            if (orderByComparator.isAscending() ^ previous) {
5067                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5068                                            }
5069                                            else {
5070                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5071                                            }
5072                                    }
5073                                    else {
5074                                            if (orderByComparator.isAscending() ^ previous) {
5075                                                    query.append(WHERE_GREATER_THAN);
5076                                            }
5077                                            else {
5078                                                    query.append(WHERE_LESSER_THAN);
5079                                            }
5080                                    }
5081                            }
5082    
5083                            query.append(ORDER_BY_CLAUSE);
5084    
5085                            String[] orderByFields = orderByComparator.getOrderByFields();
5086    
5087                            for (int i = 0; i < orderByFields.length; i++) {
5088                                    if (getDB().isSupportsInlineDistinct()) {
5089                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5090                                    }
5091                                    else {
5092                                            query.append(_ORDER_BY_ENTITY_TABLE);
5093                                    }
5094    
5095                                    query.append(orderByFields[i]);
5096    
5097                                    if ((i + 1) < orderByFields.length) {
5098                                            if (orderByComparator.isAscending() ^ previous) {
5099                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5100                                            }
5101                                            else {
5102                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5103                                            }
5104                                    }
5105                                    else {
5106                                            if (orderByComparator.isAscending() ^ previous) {
5107                                                    query.append(ORDER_BY_ASC);
5108                                            }
5109                                            else {
5110                                                    query.append(ORDER_BY_DESC);
5111                                            }
5112                                    }
5113                            }
5114                    }
5115    
5116                    else {
5117                            if (getDB().isSupportsInlineDistinct()) {
5118                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
5119                            }
5120                            else {
5121                                    query.append(LayoutModelImpl.ORDER_BY_SQL);
5122                            }
5123                    }
5124    
5125                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5126                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
5127                                    groupId);
5128    
5129                    SQLQuery q = session.createSQLQuery(sql);
5130    
5131                    q.setFirstResult(0);
5132                    q.setMaxResults(2);
5133    
5134                    if (getDB().isSupportsInlineDistinct()) {
5135                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutImpl.class);
5136                    }
5137                    else {
5138                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutImpl.class);
5139                    }
5140    
5141                    QueryPos qPos = QueryPos.getInstance(q);
5142    
5143                    qPos.add(groupId);
5144    
5145                    qPos.add(privateLayout);
5146    
5147                    if (type != null) {
5148                            qPos.add(type);
5149                    }
5150    
5151                    if (orderByComparator != null) {
5152                            Object[] values = orderByComparator.getOrderByConditionValues(layout);
5153    
5154                            for (Object value : values) {
5155                                    qPos.add(value);
5156                            }
5157                    }
5158    
5159                    List<Layout> list = q.list();
5160    
5161                    if (list.size() == 2) {
5162                            return list.get(1);
5163                    }
5164                    else {
5165                            return null;
5166                    }
5167            }
5168    
5169            /**
5170             * Returns the layout where groupId = &#63; and privateLayout = &#63; and templateLayoutUuid = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutException} if it could not be found.
5171             *
5172             * @param groupId the group ID
5173             * @param privateLayout the private layout
5174             * @param templateLayoutUuid the template layout uuid
5175             * @return the matching layout
5176             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
5177             * @throws SystemException if a system exception occurred
5178             */
5179            public Layout findByG_P_TLU(long groupId, boolean privateLayout,
5180                    String templateLayoutUuid)
5181                    throws NoSuchLayoutException, SystemException {
5182                    Layout layout = fetchByG_P_TLU(groupId, privateLayout,
5183                                    templateLayoutUuid);
5184    
5185                    if (layout == null) {
5186                            StringBundler msg = new StringBundler(8);
5187    
5188                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5189    
5190                            msg.append("groupId=");
5191                            msg.append(groupId);
5192    
5193                            msg.append(", privateLayout=");
5194                            msg.append(privateLayout);
5195    
5196                            msg.append(", templateLayoutUuid=");
5197                            msg.append(templateLayoutUuid);
5198    
5199                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5200    
5201                            if (_log.isWarnEnabled()) {
5202                                    _log.warn(msg.toString());
5203                            }
5204    
5205                            throw new NoSuchLayoutException(msg.toString());
5206                    }
5207    
5208                    return layout;
5209            }
5210    
5211            /**
5212             * Returns the layout where groupId = &#63; and privateLayout = &#63; and templateLayoutUuid = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
5213             *
5214             * @param groupId the group ID
5215             * @param privateLayout the private layout
5216             * @param templateLayoutUuid the template layout uuid
5217             * @return the matching layout, or <code>null</code> if a matching layout could not be found
5218             * @throws SystemException if a system exception occurred
5219             */
5220            public Layout fetchByG_P_TLU(long groupId, boolean privateLayout,
5221                    String templateLayoutUuid) throws SystemException {
5222                    return fetchByG_P_TLU(groupId, privateLayout, templateLayoutUuid, true);
5223            }
5224    
5225            /**
5226             * Returns the layout where groupId = &#63; and privateLayout = &#63; and templateLayoutUuid = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
5227             *
5228             * @param groupId the group ID
5229             * @param privateLayout the private layout
5230             * @param templateLayoutUuid the template layout uuid
5231             * @param retrieveFromCache whether to use the finder cache
5232             * @return the matching layout, or <code>null</code> if a matching layout could not be found
5233             * @throws SystemException if a system exception occurred
5234             */
5235            public Layout fetchByG_P_TLU(long groupId, boolean privateLayout,
5236                    String templateLayoutUuid, boolean retrieveFromCache)
5237                    throws SystemException {
5238                    Object[] finderArgs = new Object[] {
5239                                    groupId, privateLayout, templateLayoutUuid
5240                            };
5241    
5242                    Object result = null;
5243    
5244                    if (retrieveFromCache) {
5245                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_TLU,
5246                                            finderArgs, this);
5247                    }
5248    
5249                    if (result == null) {
5250                            StringBundler query = new StringBundler(5);
5251    
5252                            query.append(_SQL_SELECT_LAYOUT_WHERE);
5253    
5254                            query.append(_FINDER_COLUMN_G_P_TLU_GROUPID_2);
5255    
5256                            query.append(_FINDER_COLUMN_G_P_TLU_PRIVATELAYOUT_2);
5257    
5258                            if (templateLayoutUuid == null) {
5259                                    query.append(_FINDER_COLUMN_G_P_TLU_TEMPLATELAYOUTUUID_1);
5260                            }
5261                            else {
5262                                    if (templateLayoutUuid.equals(StringPool.BLANK)) {
5263                                            query.append(_FINDER_COLUMN_G_P_TLU_TEMPLATELAYOUTUUID_3);
5264                                    }
5265                                    else {
5266                                            query.append(_FINDER_COLUMN_G_P_TLU_TEMPLATELAYOUTUUID_2);
5267                                    }
5268                            }
5269    
5270                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
5271    
5272                            String sql = query.toString();
5273    
5274                            Session session = null;
5275    
5276                            try {
5277                                    session = openSession();
5278    
5279                                    Query q = session.createQuery(sql);
5280    
5281                                    QueryPos qPos = QueryPos.getInstance(q);
5282    
5283                                    qPos.add(groupId);
5284    
5285                                    qPos.add(privateLayout);
5286    
5287                                    if (templateLayoutUuid != null) {
5288                                            qPos.add(templateLayoutUuid);
5289                                    }
5290    
5291                                    List<Layout> list = q.list();
5292    
5293                                    result = list;
5294    
5295                                    Layout layout = null;
5296    
5297                                    if (list.isEmpty()) {
5298                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_TLU,
5299                                                    finderArgs, list);
5300                                    }
5301                                    else {
5302                                            layout = list.get(0);
5303    
5304                                            cacheResult(layout);
5305    
5306                                            if ((layout.getGroupId() != groupId) ||
5307                                                            (layout.getPrivateLayout() != privateLayout) ||
5308                                                            (layout.getTemplateLayoutUuid() == null) ||
5309                                                            !layout.getTemplateLayoutUuid()
5310                                                                               .equals(templateLayoutUuid)) {
5311                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_TLU,
5312                                                            finderArgs, layout);
5313                                            }
5314                                    }
5315    
5316                                    return layout;
5317                            }
5318                            catch (Exception e) {
5319                                    throw processException(e);
5320                            }
5321                            finally {
5322                                    if (result == null) {
5323                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_TLU,
5324                                                    finderArgs);
5325                                    }
5326    
5327                                    closeSession(session);
5328                            }
5329                    }
5330                    else {
5331                            if (result instanceof List<?>) {
5332                                    return null;
5333                            }
5334                            else {
5335                                    return (Layout)result;
5336                            }
5337                    }
5338            }
5339    
5340            /**
5341             * Returns all the layouts.
5342             *
5343             * @return the layouts
5344             * @throws SystemException if a system exception occurred
5345             */
5346            public List<Layout> findAll() throws SystemException {
5347                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5348            }
5349    
5350            /**
5351             * Returns a range of all the layouts.
5352             *
5353             * <p>
5354             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5355             * </p>
5356             *
5357             * @param start the lower bound of the range of layouts
5358             * @param end the upper bound of the range of layouts (not inclusive)
5359             * @return the range of layouts
5360             * @throws SystemException if a system exception occurred
5361             */
5362            public List<Layout> findAll(int start, int end) throws SystemException {
5363                    return findAll(start, end, null);
5364            }
5365    
5366            /**
5367             * Returns an ordered range of all the layouts.
5368             *
5369             * <p>
5370             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5371             * </p>
5372             *
5373             * @param start the lower bound of the range of layouts
5374             * @param end the upper bound of the range of layouts (not inclusive)
5375             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5376             * @return the ordered range of layouts
5377             * @throws SystemException if a system exception occurred
5378             */
5379            public List<Layout> findAll(int start, int end,
5380                    OrderByComparator orderByComparator) throws SystemException {
5381                    FinderPath finderPath = null;
5382                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
5383    
5384                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5385                                    (orderByComparator == null)) {
5386                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5387                            finderArgs = FINDER_ARGS_EMPTY;
5388                    }
5389                    else {
5390                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5391                            finderArgs = new Object[] { start, end, orderByComparator };
5392                    }
5393    
5394                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(finderPath,
5395                                    finderArgs, this);
5396    
5397                    if (list == null) {
5398                            StringBundler query = null;
5399                            String sql = null;
5400    
5401                            if (orderByComparator != null) {
5402                                    query = new StringBundler(2 +
5403                                                    (orderByComparator.getOrderByFields().length * 3));
5404    
5405                                    query.append(_SQL_SELECT_LAYOUT);
5406    
5407                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5408                                            orderByComparator);
5409    
5410                                    sql = query.toString();
5411                            }
5412                            else {
5413                                    sql = _SQL_SELECT_LAYOUT.concat(LayoutModelImpl.ORDER_BY_JPQL);
5414                            }
5415    
5416                            Session session = null;
5417    
5418                            try {
5419                                    session = openSession();
5420    
5421                                    Query q = session.createQuery(sql);
5422    
5423                                    if (orderByComparator == null) {
5424                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
5425                                                            end, false);
5426    
5427                                            Collections.sort(list);
5428                                    }
5429                                    else {
5430                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
5431                                                            end);
5432                                    }
5433                            }
5434                            catch (Exception e) {
5435                                    throw processException(e);
5436                            }
5437                            finally {
5438                                    if (list == null) {
5439                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5440                                    }
5441                                    else {
5442                                            cacheResult(list);
5443    
5444                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5445                                    }
5446    
5447                                    closeSession(session);
5448                            }
5449                    }
5450    
5451                    return list;
5452            }
5453    
5454            /**
5455             * Removes all the layouts where uuid = &#63; from the database.
5456             *
5457             * @param uuid the uuid
5458             * @throws SystemException if a system exception occurred
5459             */
5460            public void removeByUuid(String uuid) throws SystemException {
5461                    for (Layout layout : findByUuid(uuid)) {
5462                            layoutPersistence.remove(layout);
5463                    }
5464            }
5465    
5466            /**
5467             * Removes the layout where uuid = &#63; and groupId = &#63; from the database.
5468             *
5469             * @param uuid the uuid
5470             * @param groupId the group ID
5471             * @throws SystemException if a system exception occurred
5472             */
5473            public void removeByUUID_G(String uuid, long groupId)
5474                    throws NoSuchLayoutException, SystemException {
5475                    Layout layout = findByUUID_G(uuid, groupId);
5476    
5477                    layoutPersistence.remove(layout);
5478            }
5479    
5480            /**
5481             * Removes all the layouts where groupId = &#63; from the database.
5482             *
5483             * @param groupId the group ID
5484             * @throws SystemException if a system exception occurred
5485             */
5486            public void removeByGroupId(long groupId) throws SystemException {
5487                    for (Layout layout : findByGroupId(groupId)) {
5488                            layoutPersistence.remove(layout);
5489                    }
5490            }
5491    
5492            /**
5493             * Removes all the layouts where companyId = &#63; from the database.
5494             *
5495             * @param companyId the company ID
5496             * @throws SystemException if a system exception occurred
5497             */
5498            public void removeByCompanyId(long companyId) throws SystemException {
5499                    for (Layout layout : findByCompanyId(companyId)) {
5500                            layoutPersistence.remove(layout);
5501                    }
5502            }
5503    
5504            /**
5505             * Removes the layout where iconImageId = &#63; from the database.
5506             *
5507             * @param iconImageId the icon image ID
5508             * @throws SystemException if a system exception occurred
5509             */
5510            public void removeByIconImageId(long iconImageId)
5511                    throws NoSuchLayoutException, SystemException {
5512                    Layout layout = findByIconImageId(iconImageId);
5513    
5514                    layoutPersistence.remove(layout);
5515            }
5516    
5517            /**
5518             * Removes all the layouts where groupId = &#63; and privateLayout = &#63; from the database.
5519             *
5520             * @param groupId the group ID
5521             * @param privateLayout the private layout
5522             * @throws SystemException if a system exception occurred
5523             */
5524            public void removeByG_P(long groupId, boolean privateLayout)
5525                    throws SystemException {
5526                    for (Layout layout : findByG_P(groupId, privateLayout)) {
5527                            layoutPersistence.remove(layout);
5528                    }
5529            }
5530    
5531            /**
5532             * Removes the layout where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; from the database.
5533             *
5534             * @param groupId the group ID
5535             * @param privateLayout the private layout
5536             * @param layoutId the layout ID
5537             * @throws SystemException if a system exception occurred
5538             */
5539            public void removeByG_P_L(long groupId, boolean privateLayout, long layoutId)
5540                    throws NoSuchLayoutException, SystemException {
5541                    Layout layout = findByG_P_L(groupId, privateLayout, layoutId);
5542    
5543                    layoutPersistence.remove(layout);
5544            }
5545    
5546            /**
5547             * Removes all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63; from the database.
5548             *
5549             * @param groupId the group ID
5550             * @param privateLayout the private layout
5551             * @param parentLayoutId the parent layout ID
5552             * @throws SystemException if a system exception occurred
5553             */
5554            public void removeByG_P_P(long groupId, boolean privateLayout,
5555                    long parentLayoutId) throws SystemException {
5556                    for (Layout layout : findByG_P_P(groupId, privateLayout, parentLayoutId)) {
5557                            layoutPersistence.remove(layout);
5558                    }
5559            }
5560    
5561            /**
5562             * Removes the layout where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; from the database.
5563             *
5564             * @param groupId the group ID
5565             * @param privateLayout the private layout
5566             * @param friendlyURL the friendly u r l
5567             * @throws SystemException if a system exception occurred
5568             */
5569            public void removeByG_P_F(long groupId, boolean privateLayout,
5570                    String friendlyURL) throws NoSuchLayoutException, SystemException {
5571                    Layout layout = findByG_P_F(groupId, privateLayout, friendlyURL);
5572    
5573                    layoutPersistence.remove(layout);
5574            }
5575    
5576            /**
5577             * Removes all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63; from the database.
5578             *
5579             * @param groupId the group ID
5580             * @param privateLayout the private layout
5581             * @param type the type
5582             * @throws SystemException if a system exception occurred
5583             */
5584            public void removeByG_P_T(long groupId, boolean privateLayout, String type)
5585                    throws SystemException {
5586                    for (Layout layout : findByG_P_T(groupId, privateLayout, type)) {
5587                            layoutPersistence.remove(layout);
5588                    }
5589            }
5590    
5591            /**
5592             * Removes the layout where groupId = &#63; and privateLayout = &#63; and templateLayoutUuid = &#63; from the database.
5593             *
5594             * @param groupId the group ID
5595             * @param privateLayout the private layout
5596             * @param templateLayoutUuid the template layout uuid
5597             * @throws SystemException if a system exception occurred
5598             */
5599            public void removeByG_P_TLU(long groupId, boolean privateLayout,
5600                    String templateLayoutUuid)
5601                    throws NoSuchLayoutException, SystemException {
5602                    Layout layout = findByG_P_TLU(groupId, privateLayout, templateLayoutUuid);
5603    
5604                    layoutPersistence.remove(layout);
5605            }
5606    
5607            /**
5608             * Removes all the layouts from the database.
5609             *
5610             * @throws SystemException if a system exception occurred
5611             */
5612            public void removeAll() throws SystemException {
5613                    for (Layout layout : findAll()) {
5614                            layoutPersistence.remove(layout);
5615                    }
5616            }
5617    
5618            /**
5619             * Returns the number of layouts where uuid = &#63;.
5620             *
5621             * @param uuid the uuid
5622             * @return the number of matching layouts
5623             * @throws SystemException if a system exception occurred
5624             */
5625            public int countByUuid(String uuid) throws SystemException {
5626                    Object[] finderArgs = new Object[] { uuid };
5627    
5628                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
5629                                    finderArgs, this);
5630    
5631                    if (count == null) {
5632                            StringBundler query = new StringBundler(2);
5633    
5634                            query.append(_SQL_COUNT_LAYOUT_WHERE);
5635    
5636                            if (uuid == null) {
5637                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
5638                            }
5639                            else {
5640                                    if (uuid.equals(StringPool.BLANK)) {
5641                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
5642                                    }
5643                                    else {
5644                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
5645                                    }
5646                            }
5647    
5648                            String sql = query.toString();
5649    
5650                            Session session = null;
5651    
5652                            try {
5653                                    session = openSession();
5654    
5655                                    Query q = session.createQuery(sql);
5656    
5657                                    QueryPos qPos = QueryPos.getInstance(q);
5658    
5659                                    if (uuid != null) {
5660                                            qPos.add(uuid);
5661                                    }
5662    
5663                                    count = (Long)q.uniqueResult();
5664                            }
5665                            catch (Exception e) {
5666                                    throw processException(e);
5667                            }
5668                            finally {
5669                                    if (count == null) {
5670                                            count = Long.valueOf(0);
5671                                    }
5672    
5673                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
5674                                            finderArgs, count);
5675    
5676                                    closeSession(session);
5677                            }
5678                    }
5679    
5680                    return count.intValue();
5681            }
5682    
5683            /**
5684             * Returns the number of layouts where uuid = &#63; and groupId = &#63;.
5685             *
5686             * @param uuid the uuid
5687             * @param groupId the group ID
5688             * @return the number of matching layouts
5689             * @throws SystemException if a system exception occurred
5690             */
5691            public int countByUUID_G(String uuid, long groupId)
5692                    throws SystemException {
5693                    Object[] finderArgs = new Object[] { uuid, groupId };
5694    
5695                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
5696                                    finderArgs, this);
5697    
5698                    if (count == null) {
5699                            StringBundler query = new StringBundler(3);
5700    
5701                            query.append(_SQL_COUNT_LAYOUT_WHERE);
5702    
5703                            if (uuid == null) {
5704                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
5705                            }
5706                            else {
5707                                    if (uuid.equals(StringPool.BLANK)) {
5708                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
5709                                    }
5710                                    else {
5711                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
5712                                    }
5713                            }
5714    
5715                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
5716    
5717                            String sql = query.toString();
5718    
5719                            Session session = null;
5720    
5721                            try {
5722                                    session = openSession();
5723    
5724                                    Query q = session.createQuery(sql);
5725    
5726                                    QueryPos qPos = QueryPos.getInstance(q);
5727    
5728                                    if (uuid != null) {
5729                                            qPos.add(uuid);
5730                                    }
5731    
5732                                    qPos.add(groupId);
5733    
5734                                    count = (Long)q.uniqueResult();
5735                            }
5736                            catch (Exception e) {
5737                                    throw processException(e);
5738                            }
5739                            finally {
5740                                    if (count == null) {
5741                                            count = Long.valueOf(0);
5742                                    }
5743    
5744                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
5745                                            finderArgs, count);
5746    
5747                                    closeSession(session);
5748                            }
5749                    }
5750    
5751                    return count.intValue();
5752            }
5753    
5754            /**
5755             * Returns the number of layouts where groupId = &#63;.
5756             *
5757             * @param groupId the group ID
5758             * @return the number of matching layouts
5759             * @throws SystemException if a system exception occurred
5760             */
5761            public int countByGroupId(long groupId) throws SystemException {
5762                    Object[] finderArgs = new Object[] { groupId };
5763    
5764                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
5765                                    finderArgs, this);
5766    
5767                    if (count == null) {
5768                            StringBundler query = new StringBundler(2);
5769    
5770                            query.append(_SQL_COUNT_LAYOUT_WHERE);
5771    
5772                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
5773    
5774                            String sql = query.toString();
5775    
5776                            Session session = null;
5777    
5778                            try {
5779                                    session = openSession();
5780    
5781                                    Query q = session.createQuery(sql);
5782    
5783                                    QueryPos qPos = QueryPos.getInstance(q);
5784    
5785                                    qPos.add(groupId);
5786    
5787                                    count = (Long)q.uniqueResult();
5788                            }
5789                            catch (Exception e) {
5790                                    throw processException(e);
5791                            }
5792                            finally {
5793                                    if (count == null) {
5794                                            count = Long.valueOf(0);
5795                                    }
5796    
5797                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
5798                                            finderArgs, count);
5799    
5800                                    closeSession(session);
5801                            }
5802                    }
5803    
5804                    return count.intValue();
5805            }
5806    
5807            /**
5808             * Returns the number of layouts that the user has permission to view where groupId = &#63;.
5809             *
5810             * @param groupId the group ID
5811             * @return the number of matching layouts that the user has permission to view
5812             * @throws SystemException if a system exception occurred
5813             */
5814            public int filterCountByGroupId(long groupId) throws SystemException {
5815                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5816                            return countByGroupId(groupId);
5817                    }
5818    
5819                    StringBundler query = new StringBundler(2);
5820    
5821                    query.append(_FILTER_SQL_COUNT_LAYOUT_WHERE);
5822    
5823                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
5824    
5825                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5826                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
5827                                    groupId);
5828    
5829                    Session session = null;
5830    
5831                    try {
5832                            session = openSession();
5833    
5834                            SQLQuery q = session.createSQLQuery(sql);
5835    
5836                            q.addScalar(COUNT_COLUMN_NAME,
5837                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5838    
5839                            QueryPos qPos = QueryPos.getInstance(q);
5840    
5841                            qPos.add(groupId);
5842    
5843                            Long count = (Long)q.uniqueResult();
5844    
5845                            return count.intValue();
5846                    }
5847                    catch (Exception e) {
5848                            throw processException(e);
5849                    }
5850                    finally {
5851                            closeSession(session);
5852                    }
5853            }
5854    
5855            /**
5856             * Returns the number of layouts where companyId = &#63;.
5857             *
5858             * @param companyId the company ID
5859             * @return the number of matching layouts
5860             * @throws SystemException if a system exception occurred
5861             */
5862            public int countByCompanyId(long companyId) throws SystemException {
5863                    Object[] finderArgs = new Object[] { companyId };
5864    
5865                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
5866                                    finderArgs, this);
5867    
5868                    if (count == null) {
5869                            StringBundler query = new StringBundler(2);
5870    
5871                            query.append(_SQL_COUNT_LAYOUT_WHERE);
5872    
5873                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
5874    
5875                            String sql = query.toString();
5876    
5877                            Session session = null;
5878    
5879                            try {
5880                                    session = openSession();
5881    
5882                                    Query q = session.createQuery(sql);
5883    
5884                                    QueryPos qPos = QueryPos.getInstance(q);
5885    
5886                                    qPos.add(companyId);
5887    
5888                                    count = (Long)q.uniqueResult();
5889                            }
5890                            catch (Exception e) {
5891                                    throw processException(e);
5892                            }
5893                            finally {
5894                                    if (count == null) {
5895                                            count = Long.valueOf(0);
5896                                    }
5897    
5898                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
5899                                            finderArgs, count);
5900    
5901                                    closeSession(session);
5902                            }
5903                    }
5904    
5905                    return count.intValue();
5906            }
5907    
5908            /**
5909             * Returns the number of layouts where iconImageId = &#63;.
5910             *
5911             * @param iconImageId the icon image ID
5912             * @return the number of matching layouts
5913             * @throws SystemException if a system exception occurred
5914             */
5915            public int countByIconImageId(long iconImageId) throws SystemException {
5916                    Object[] finderArgs = new Object[] { iconImageId };
5917    
5918                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ICONIMAGEID,
5919                                    finderArgs, this);
5920    
5921                    if (count == null) {
5922                            StringBundler query = new StringBundler(2);
5923    
5924                            query.append(_SQL_COUNT_LAYOUT_WHERE);
5925    
5926                            query.append(_FINDER_COLUMN_ICONIMAGEID_ICONIMAGEID_2);
5927    
5928                            String sql = query.toString();
5929    
5930                            Session session = null;
5931    
5932                            try {
5933                                    session = openSession();
5934    
5935                                    Query q = session.createQuery(sql);
5936    
5937                                    QueryPos qPos = QueryPos.getInstance(q);
5938    
5939                                    qPos.add(iconImageId);
5940    
5941                                    count = (Long)q.uniqueResult();
5942                            }
5943                            catch (Exception e) {
5944                                    throw processException(e);
5945                            }
5946                            finally {
5947                                    if (count == null) {
5948                                            count = Long.valueOf(0);
5949                                    }
5950    
5951                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ICONIMAGEID,
5952                                            finderArgs, count);
5953    
5954                                    closeSession(session);
5955                            }
5956                    }
5957    
5958                    return count.intValue();
5959            }
5960    
5961            /**
5962             * Returns the number of layouts where groupId = &#63; and privateLayout = &#63;.
5963             *
5964             * @param groupId the group ID
5965             * @param privateLayout the private layout
5966             * @return the number of matching layouts
5967             * @throws SystemException if a system exception occurred
5968             */
5969            public int countByG_P(long groupId, boolean privateLayout)
5970                    throws SystemException {
5971                    Object[] finderArgs = new Object[] { groupId, privateLayout };
5972    
5973                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
5974                                    finderArgs, this);
5975    
5976                    if (count == null) {
5977                            StringBundler query = new StringBundler(3);
5978    
5979                            query.append(_SQL_COUNT_LAYOUT_WHERE);
5980    
5981                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
5982    
5983                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
5984    
5985                            String sql = query.toString();
5986    
5987                            Session session = null;
5988    
5989                            try {
5990                                    session = openSession();
5991    
5992                                    Query q = session.createQuery(sql);
5993    
5994                                    QueryPos qPos = QueryPos.getInstance(q);
5995    
5996                                    qPos.add(groupId);
5997    
5998                                    qPos.add(privateLayout);
5999    
6000                                    count = (Long)q.uniqueResult();
6001                            }
6002                            catch (Exception e) {
6003                                    throw processException(e);
6004                            }
6005                            finally {
6006                                    if (count == null) {
6007                                            count = Long.valueOf(0);
6008                                    }
6009    
6010                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
6011                                            count);
6012    
6013                                    closeSession(session);
6014                            }
6015                    }
6016    
6017                    return count.intValue();
6018            }
6019    
6020            /**
6021             * Returns the number of layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
6022             *
6023             * @param groupId the group ID
6024             * @param privateLayout the private layout
6025             * @return the number of matching layouts that the user has permission to view
6026             * @throws SystemException if a system exception occurred
6027             */
6028            public int filterCountByG_P(long groupId, boolean privateLayout)
6029                    throws SystemException {
6030                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6031                            return countByG_P(groupId, privateLayout);
6032                    }
6033    
6034                    StringBundler query = new StringBundler(3);
6035    
6036                    query.append(_FILTER_SQL_COUNT_LAYOUT_WHERE);
6037    
6038                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
6039    
6040                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
6041    
6042                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6043                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
6044                                    groupId);
6045    
6046                    Session session = null;
6047    
6048                    try {
6049                            session = openSession();
6050    
6051                            SQLQuery q = session.createSQLQuery(sql);
6052    
6053                            q.addScalar(COUNT_COLUMN_NAME,
6054                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6055    
6056                            QueryPos qPos = QueryPos.getInstance(q);
6057    
6058                            qPos.add(groupId);
6059    
6060                            qPos.add(privateLayout);
6061    
6062                            Long count = (Long)q.uniqueResult();
6063    
6064                            return count.intValue();
6065                    }
6066                    catch (Exception e) {
6067                            throw processException(e);
6068                    }
6069                    finally {
6070                            closeSession(session);
6071                    }
6072            }
6073    
6074            /**
6075             * Returns the number of layouts where groupId = &#63; and privateLayout = &#63; and layoutId = &#63;.
6076             *
6077             * @param groupId the group ID
6078             * @param privateLayout the private layout
6079             * @param layoutId the layout ID
6080             * @return the number of matching layouts
6081             * @throws SystemException if a system exception occurred
6082             */
6083            public int countByG_P_L(long groupId, boolean privateLayout, long layoutId)
6084                    throws SystemException {
6085                    Object[] finderArgs = new Object[] { groupId, privateLayout, layoutId };
6086    
6087                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_L,
6088                                    finderArgs, this);
6089    
6090                    if (count == null) {
6091                            StringBundler query = new StringBundler(4);
6092    
6093                            query.append(_SQL_COUNT_LAYOUT_WHERE);
6094    
6095                            query.append(_FINDER_COLUMN_G_P_L_GROUPID_2);
6096    
6097                            query.append(_FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2);
6098    
6099                            query.append(_FINDER_COLUMN_G_P_L_LAYOUTID_2);
6100    
6101                            String sql = query.toString();
6102    
6103                            Session session = null;
6104    
6105                            try {
6106                                    session = openSession();
6107    
6108                                    Query q = session.createQuery(sql);
6109    
6110                                    QueryPos qPos = QueryPos.getInstance(q);
6111    
6112                                    qPos.add(groupId);
6113    
6114                                    qPos.add(privateLayout);
6115    
6116                                    qPos.add(layoutId);
6117    
6118                                    count = (Long)q.uniqueResult();
6119                            }
6120                            catch (Exception e) {
6121                                    throw processException(e);
6122                            }
6123                            finally {
6124                                    if (count == null) {
6125                                            count = Long.valueOf(0);
6126                                    }
6127    
6128                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_L,
6129                                            finderArgs, count);
6130    
6131                                    closeSession(session);
6132                            }
6133                    }
6134    
6135                    return count.intValue();
6136            }
6137    
6138            /**
6139             * Returns the number of layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
6140             *
6141             * @param groupId the group ID
6142             * @param privateLayout the private layout
6143             * @param parentLayoutId the parent layout ID
6144             * @return the number of matching layouts
6145             * @throws SystemException if a system exception occurred
6146             */
6147            public int countByG_P_P(long groupId, boolean privateLayout,
6148                    long parentLayoutId) throws SystemException {
6149                    Object[] finderArgs = new Object[] {
6150                                    groupId, privateLayout, parentLayoutId
6151                            };
6152    
6153                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_P,
6154                                    finderArgs, this);
6155    
6156                    if (count == null) {
6157                            StringBundler query = new StringBundler(4);
6158    
6159                            query.append(_SQL_COUNT_LAYOUT_WHERE);
6160    
6161                            query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
6162    
6163                            query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
6164    
6165                            query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
6166    
6167                            String sql = query.toString();
6168    
6169                            Session session = null;
6170    
6171                            try {
6172                                    session = openSession();
6173    
6174                                    Query q = session.createQuery(sql);
6175    
6176                                    QueryPos qPos = QueryPos.getInstance(q);
6177    
6178                                    qPos.add(groupId);
6179    
6180                                    qPos.add(privateLayout);
6181    
6182                                    qPos.add(parentLayoutId);
6183    
6184                                    count = (Long)q.uniqueResult();
6185                            }
6186                            catch (Exception e) {
6187                                    throw processException(e);
6188                            }
6189                            finally {
6190                                    if (count == null) {
6191                                            count = Long.valueOf(0);
6192                                    }
6193    
6194                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_P,
6195                                            finderArgs, count);
6196    
6197                                    closeSession(session);
6198                            }
6199                    }
6200    
6201                    return count.intValue();
6202            }
6203    
6204            /**
6205             * Returns the number of layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
6206             *
6207             * @param groupId the group ID
6208             * @param privateLayout the private layout
6209             * @param parentLayoutId the parent layout ID
6210             * @return the number of matching layouts that the user has permission to view
6211             * @throws SystemException if a system exception occurred
6212             */
6213            public int filterCountByG_P_P(long groupId, boolean privateLayout,
6214                    long parentLayoutId) throws SystemException {
6215                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6216                            return countByG_P_P(groupId, privateLayout, parentLayoutId);
6217                    }
6218    
6219                    StringBundler query = new StringBundler(4);
6220    
6221                    query.append(_FILTER_SQL_COUNT_LAYOUT_WHERE);
6222    
6223                    query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
6224    
6225                    query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
6226    
6227                    query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
6228    
6229                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6230                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
6231                                    groupId);
6232    
6233                    Session session = null;
6234    
6235                    try {
6236                            session = openSession();
6237    
6238                            SQLQuery q = session.createSQLQuery(sql);
6239    
6240                            q.addScalar(COUNT_COLUMN_NAME,
6241                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6242    
6243                            QueryPos qPos = QueryPos.getInstance(q);
6244    
6245                            qPos.add(groupId);
6246    
6247                            qPos.add(privateLayout);
6248    
6249                            qPos.add(parentLayoutId);
6250    
6251                            Long count = (Long)q.uniqueResult();
6252    
6253                            return count.intValue();
6254                    }
6255                    catch (Exception e) {
6256                            throw processException(e);
6257                    }
6258                    finally {
6259                            closeSession(session);
6260                    }
6261            }
6262    
6263            /**
6264             * Returns the number of layouts where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63;.
6265             *
6266             * @param groupId the group ID
6267             * @param privateLayout the private layout
6268             * @param friendlyURL the friendly u r l
6269             * @return the number of matching layouts
6270             * @throws SystemException if a system exception occurred
6271             */
6272            public int countByG_P_F(long groupId, boolean privateLayout,
6273                    String friendlyURL) throws SystemException {
6274                    Object[] finderArgs = new Object[] { groupId, privateLayout, friendlyURL };
6275    
6276                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_F,
6277                                    finderArgs, this);
6278    
6279                    if (count == null) {
6280                            StringBundler query = new StringBundler(4);
6281    
6282                            query.append(_SQL_COUNT_LAYOUT_WHERE);
6283    
6284                            query.append(_FINDER_COLUMN_G_P_F_GROUPID_2);
6285    
6286                            query.append(_FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2);
6287    
6288                            if (friendlyURL == null) {
6289                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_1);
6290                            }
6291                            else {
6292                                    if (friendlyURL.equals(StringPool.BLANK)) {
6293                                            query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_3);
6294                                    }
6295                                    else {
6296                                            query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_2);
6297                                    }
6298                            }
6299    
6300                            String sql = query.toString();
6301    
6302                            Session session = null;
6303    
6304                            try {
6305                                    session = openSession();
6306    
6307                                    Query q = session.createQuery(sql);
6308    
6309                                    QueryPos qPos = QueryPos.getInstance(q);
6310    
6311                                    qPos.add(groupId);
6312    
6313                                    qPos.add(privateLayout);
6314    
6315                                    if (friendlyURL != null) {
6316                                            qPos.add(friendlyURL);
6317                                    }
6318    
6319                                    count = (Long)q.uniqueResult();
6320                            }
6321                            catch (Exception e) {
6322                                    throw processException(e);
6323                            }
6324                            finally {
6325                                    if (count == null) {
6326                                            count = Long.valueOf(0);
6327                                    }
6328    
6329                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_F,
6330                                            finderArgs, count);
6331    
6332                                    closeSession(session);
6333                            }
6334                    }
6335    
6336                    return count.intValue();
6337            }
6338    
6339            /**
6340             * Returns the number of layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
6341             *
6342             * @param groupId the group ID
6343             * @param privateLayout the private layout
6344             * @param type the type
6345             * @return the number of matching layouts
6346             * @throws SystemException if a system exception occurred
6347             */
6348            public int countByG_P_T(long groupId, boolean privateLayout, String type)
6349                    throws SystemException {
6350                    Object[] finderArgs = new Object[] { groupId, privateLayout, type };
6351    
6352                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_T,
6353                                    finderArgs, this);
6354    
6355                    if (count == null) {
6356                            StringBundler query = new StringBundler(4);
6357    
6358                            query.append(_SQL_COUNT_LAYOUT_WHERE);
6359    
6360                            query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
6361    
6362                            query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
6363    
6364                            if (type == null) {
6365                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
6366                            }
6367                            else {
6368                                    if (type.equals(StringPool.BLANK)) {
6369                                            query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
6370                                    }
6371                                    else {
6372                                            query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
6373                                    }
6374                            }
6375    
6376                            String sql = query.toString();
6377    
6378                            Session session = null;
6379    
6380                            try {
6381                                    session = openSession();
6382    
6383                                    Query q = session.createQuery(sql);
6384    
6385                                    QueryPos qPos = QueryPos.getInstance(q);
6386    
6387                                    qPos.add(groupId);
6388    
6389                                    qPos.add(privateLayout);
6390    
6391                                    if (type != null) {
6392                                            qPos.add(type);
6393                                    }
6394    
6395                                    count = (Long)q.uniqueResult();
6396                            }
6397                            catch (Exception e) {
6398                                    throw processException(e);
6399                            }
6400                            finally {
6401                                    if (count == null) {
6402                                            count = Long.valueOf(0);
6403                                    }
6404    
6405                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_T,
6406                                            finderArgs, count);
6407    
6408                                    closeSession(session);
6409                            }
6410                    }
6411    
6412                    return count.intValue();
6413            }
6414    
6415            /**
6416             * Returns the number of layouts that the user has permission to view where groupId = &#63; and privateLayout = &#63; and type = &#63;.
6417             *
6418             * @param groupId the group ID
6419             * @param privateLayout the private layout
6420             * @param type the type
6421             * @return the number of matching layouts that the user has permission to view
6422             * @throws SystemException if a system exception occurred
6423             */
6424            public int filterCountByG_P_T(long groupId, boolean privateLayout,
6425                    String type) throws SystemException {
6426                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6427                            return countByG_P_T(groupId, privateLayout, type);
6428                    }
6429    
6430                    StringBundler query = new StringBundler(4);
6431    
6432                    query.append(_FILTER_SQL_COUNT_LAYOUT_WHERE);
6433    
6434                    query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
6435    
6436                    query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
6437    
6438                    if (type == null) {
6439                            query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
6440                    }
6441                    else {
6442                            if (type.equals(StringPool.BLANK)) {
6443                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
6444                            }
6445                            else {
6446                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
6447                            }
6448                    }
6449    
6450                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6451                                    Layout.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
6452                                    groupId);
6453    
6454                    Session session = null;
6455    
6456                    try {
6457                            session = openSession();
6458    
6459                            SQLQuery q = session.createSQLQuery(sql);
6460    
6461                            q.addScalar(COUNT_COLUMN_NAME,
6462                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6463    
6464                            QueryPos qPos = QueryPos.getInstance(q);
6465    
6466                            qPos.add(groupId);
6467    
6468                            qPos.add(privateLayout);
6469    
6470                            if (type != null) {
6471                                    qPos.add(type);
6472                            }
6473    
6474                            Long count = (Long)q.uniqueResult();
6475    
6476                            return count.intValue();
6477                    }
6478                    catch (Exception e) {
6479                            throw processException(e);
6480                    }
6481                    finally {
6482                            closeSession(session);
6483                    }
6484            }
6485    
6486            /**
6487             * Returns the number of layouts where groupId = &#63; and privateLayout = &#63; and templateLayoutUuid = &#63;.
6488             *
6489             * @param groupId the group ID
6490             * @param privateLayout the private layout
6491             * @param templateLayoutUuid the template layout uuid
6492             * @return the number of matching layouts
6493             * @throws SystemException if a system exception occurred
6494             */
6495            public int countByG_P_TLU(long groupId, boolean privateLayout,
6496                    String templateLayoutUuid) throws SystemException {
6497                    Object[] finderArgs = new Object[] {
6498                                    groupId, privateLayout, templateLayoutUuid
6499                            };
6500    
6501                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_TLU,
6502                                    finderArgs, this);
6503    
6504                    if (count == null) {
6505                            StringBundler query = new StringBundler(4);
6506    
6507                            query.append(_SQL_COUNT_LAYOUT_WHERE);
6508    
6509                            query.append(_FINDER_COLUMN_G_P_TLU_GROUPID_2);
6510    
6511                            query.append(_FINDER_COLUMN_G_P_TLU_PRIVATELAYOUT_2);
6512    
6513                            if (templateLayoutUuid == null) {
6514                                    query.append(_FINDER_COLUMN_G_P_TLU_TEMPLATELAYOUTUUID_1);
6515                            }
6516                            else {
6517                                    if (templateLayoutUuid.equals(StringPool.BLANK)) {
6518                                            query.append(_FINDER_COLUMN_G_P_TLU_TEMPLATELAYOUTUUID_3);
6519                                    }
6520                                    else {
6521                                            query.append(_FINDER_COLUMN_G_P_TLU_TEMPLATELAYOUTUUID_2);
6522                                    }
6523                            }
6524    
6525                            String sql = query.toString();
6526    
6527                            Session session = null;
6528    
6529                            try {
6530                                    session = openSession();
6531    
6532                                    Query q = session.createQuery(sql);
6533    
6534                                    QueryPos qPos = QueryPos.getInstance(q);
6535    
6536                                    qPos.add(groupId);
6537    
6538                                    qPos.add(privateLayout);
6539    
6540                                    if (templateLayoutUuid != null) {
6541                                            qPos.add(templateLayoutUuid);
6542                                    }
6543    
6544                                    count = (Long)q.uniqueResult();
6545                            }
6546                            catch (Exception e) {
6547                                    throw processException(e);
6548                            }
6549                            finally {
6550                                    if (count == null) {
6551                                            count = Long.valueOf(0);
6552                                    }
6553    
6554                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_TLU,
6555                                            finderArgs, count);
6556    
6557                                    closeSession(session);
6558                            }
6559                    }
6560    
6561                    return count.intValue();
6562            }
6563    
6564            /**
6565             * Returns the number of layouts.
6566             *
6567             * @return the number of layouts
6568             * @throws SystemException if a system exception occurred
6569             */
6570            public int countAll() throws SystemException {
6571                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
6572                                    FINDER_ARGS_EMPTY, this);
6573    
6574                    if (count == null) {
6575                            Session session = null;
6576    
6577                            try {
6578                                    session = openSession();
6579    
6580                                    Query q = session.createQuery(_SQL_COUNT_LAYOUT);
6581    
6582                                    count = (Long)q.uniqueResult();
6583                            }
6584                            catch (Exception e) {
6585                                    throw processException(e);
6586                            }
6587                            finally {
6588                                    if (count == null) {
6589                                            count = Long.valueOf(0);
6590                                    }
6591    
6592                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
6593                                            FINDER_ARGS_EMPTY, count);
6594    
6595                                    closeSession(session);
6596                            }
6597                    }
6598    
6599                    return count.intValue();
6600            }
6601    
6602            /**
6603             * Initializes the layout persistence.
6604             */
6605            public void afterPropertiesSet() {
6606                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
6607                                            com.liferay.portal.util.PropsUtil.get(
6608                                                    "value.object.listener.com.liferay.portal.model.Layout")));
6609    
6610                    if (listenerClassNames.length > 0) {
6611                            try {
6612                                    List<ModelListener<Layout>> listenersList = new ArrayList<ModelListener<Layout>>();
6613    
6614                                    for (String listenerClassName : listenerClassNames) {
6615                                            listenersList.add((ModelListener<Layout>)InstanceFactory.newInstance(
6616                                                            listenerClassName));
6617                                    }
6618    
6619                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
6620                            }
6621                            catch (Exception e) {
6622                                    _log.error(e);
6623                            }
6624                    }
6625            }
6626    
6627            public void destroy() {
6628                    EntityCacheUtil.removeCache(LayoutImpl.class.getName());
6629                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
6630                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6631            }
6632    
6633            @BeanReference(type = AccountPersistence.class)
6634            protected AccountPersistence accountPersistence;
6635            @BeanReference(type = AddressPersistence.class)
6636            protected AddressPersistence addressPersistence;
6637            @BeanReference(type = BrowserTrackerPersistence.class)
6638            protected BrowserTrackerPersistence browserTrackerPersistence;
6639            @BeanReference(type = ClassNamePersistence.class)
6640            protected ClassNamePersistence classNamePersistence;
6641            @BeanReference(type = ClusterGroupPersistence.class)
6642            protected ClusterGroupPersistence clusterGroupPersistence;
6643            @BeanReference(type = CompanyPersistence.class)
6644            protected CompanyPersistence companyPersistence;
6645            @BeanReference(type = ContactPersistence.class)
6646            protected ContactPersistence contactPersistence;
6647            @BeanReference(type = CountryPersistence.class)
6648            protected CountryPersistence countryPersistence;
6649            @BeanReference(type = EmailAddressPersistence.class)
6650            protected EmailAddressPersistence emailAddressPersistence;
6651            @BeanReference(type = GroupPersistence.class)
6652            protected GroupPersistence groupPersistence;
6653            @BeanReference(type = ImagePersistence.class)
6654            protected ImagePersistence imagePersistence;
6655            @BeanReference(type = LayoutPersistence.class)
6656            protected LayoutPersistence layoutPersistence;
6657            @BeanReference(type = LayoutBranchPersistence.class)
6658            protected LayoutBranchPersistence layoutBranchPersistence;
6659            @BeanReference(type = LayoutPrototypePersistence.class)
6660            protected LayoutPrototypePersistence layoutPrototypePersistence;
6661            @BeanReference(type = LayoutRevisionPersistence.class)
6662            protected LayoutRevisionPersistence layoutRevisionPersistence;
6663            @BeanReference(type = LayoutSetPersistence.class)
6664            protected LayoutSetPersistence layoutSetPersistence;
6665            @BeanReference(type = LayoutSetBranchPersistence.class)
6666            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
6667            @BeanReference(type = LayoutSetPrototypePersistence.class)
6668            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
6669            @BeanReference(type = ListTypePersistence.class)
6670            protected ListTypePersistence listTypePersistence;
6671            @BeanReference(type = LockPersistence.class)
6672            protected LockPersistence lockPersistence;
6673            @BeanReference(type = MembershipRequestPersistence.class)
6674            protected MembershipRequestPersistence membershipRequestPersistence;
6675            @BeanReference(type = OrganizationPersistence.class)
6676            protected OrganizationPersistence organizationPersistence;
6677            @BeanReference(type = OrgGroupPermissionPersistence.class)
6678            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
6679            @BeanReference(type = OrgGroupRolePersistence.class)
6680            protected OrgGroupRolePersistence orgGroupRolePersistence;
6681            @BeanReference(type = OrgLaborPersistence.class)
6682            protected OrgLaborPersistence orgLaborPersistence;
6683            @BeanReference(type = PasswordPolicyPersistence.class)
6684            protected PasswordPolicyPersistence passwordPolicyPersistence;
6685            @BeanReference(type = PasswordPolicyRelPersistence.class)
6686            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
6687            @BeanReference(type = PasswordTrackerPersistence.class)
6688            protected PasswordTrackerPersistence passwordTrackerPersistence;
6689            @BeanReference(type = PermissionPersistence.class)
6690            protected PermissionPersistence permissionPersistence;
6691            @BeanReference(type = PhonePersistence.class)
6692            protected PhonePersistence phonePersistence;
6693            @BeanReference(type = PluginSettingPersistence.class)
6694            protected PluginSettingPersistence pluginSettingPersistence;
6695            @BeanReference(type = PortalPreferencesPersistence.class)
6696            protected PortalPreferencesPersistence portalPreferencesPersistence;
6697            @BeanReference(type = PortletPersistence.class)
6698            protected PortletPersistence portletPersistence;
6699            @BeanReference(type = PortletItemPersistence.class)
6700            protected PortletItemPersistence portletItemPersistence;
6701            @BeanReference(type = PortletPreferencesPersistence.class)
6702            protected PortletPreferencesPersistence portletPreferencesPersistence;
6703            @BeanReference(type = RegionPersistence.class)
6704            protected RegionPersistence regionPersistence;
6705            @BeanReference(type = ReleasePersistence.class)
6706            protected ReleasePersistence releasePersistence;
6707            @BeanReference(type = RepositoryPersistence.class)
6708            protected RepositoryPersistence repositoryPersistence;
6709            @BeanReference(type = RepositoryEntryPersistence.class)
6710            protected RepositoryEntryPersistence repositoryEntryPersistence;
6711            @BeanReference(type = ResourcePersistence.class)
6712            protected ResourcePersistence resourcePersistence;
6713            @BeanReference(type = ResourceActionPersistence.class)
6714            protected ResourceActionPersistence resourceActionPersistence;
6715            @BeanReference(type = ResourceBlockPersistence.class)
6716            protected ResourceBlockPersistence resourceBlockPersistence;
6717            @BeanReference(type = ResourceBlockPermissionPersistence.class)
6718            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
6719            @BeanReference(type = ResourceCodePersistence.class)
6720            protected ResourceCodePersistence resourceCodePersistence;
6721            @BeanReference(type = ResourcePermissionPersistence.class)
6722            protected ResourcePermissionPersistence resourcePermissionPersistence;
6723            @BeanReference(type = ResourceTypePermissionPersistence.class)
6724            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
6725            @BeanReference(type = RolePersistence.class)
6726            protected RolePersistence rolePersistence;
6727            @BeanReference(type = ServiceComponentPersistence.class)
6728            protected ServiceComponentPersistence serviceComponentPersistence;
6729            @BeanReference(type = ShardPersistence.class)
6730            protected ShardPersistence shardPersistence;
6731            @BeanReference(type = SubscriptionPersistence.class)
6732            protected SubscriptionPersistence subscriptionPersistence;
6733            @BeanReference(type = TeamPersistence.class)
6734            protected TeamPersistence teamPersistence;
6735            @BeanReference(type = TicketPersistence.class)
6736            protected TicketPersistence ticketPersistence;
6737            @BeanReference(type = UserPersistence.class)
6738            protected UserPersistence userPersistence;
6739            @BeanReference(type = UserGroupPersistence.class)
6740            protected UserGroupPersistence userGroupPersistence;
6741            @BeanReference(type = UserGroupGroupRolePersistence.class)
6742            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
6743            @BeanReference(type = UserGroupRolePersistence.class)
6744            protected UserGroupRolePersistence userGroupRolePersistence;
6745            @BeanReference(type = UserIdMapperPersistence.class)
6746            protected UserIdMapperPersistence userIdMapperPersistence;
6747            @BeanReference(type = UserNotificationEventPersistence.class)
6748            protected UserNotificationEventPersistence userNotificationEventPersistence;
6749            @BeanReference(type = UserTrackerPersistence.class)
6750            protected UserTrackerPersistence userTrackerPersistence;
6751            @BeanReference(type = UserTrackerPathPersistence.class)
6752            protected UserTrackerPathPersistence userTrackerPathPersistence;
6753            @BeanReference(type = VirtualHostPersistence.class)
6754            protected VirtualHostPersistence virtualHostPersistence;
6755            @BeanReference(type = WebDAVPropsPersistence.class)
6756            protected WebDAVPropsPersistence webDAVPropsPersistence;
6757            @BeanReference(type = WebsitePersistence.class)
6758            protected WebsitePersistence websitePersistence;
6759            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
6760            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
6761            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
6762            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
6763            @BeanReference(type = ExpandoValuePersistence.class)
6764            protected ExpandoValuePersistence expandoValuePersistence;
6765            @BeanReference(type = JournalArticlePersistence.class)
6766            protected JournalArticlePersistence journalArticlePersistence;
6767            @BeanReference(type = JournalContentSearchPersistence.class)
6768            protected JournalContentSearchPersistence journalContentSearchPersistence;
6769            @BeanReference(type = MBMessagePersistence.class)
6770            protected MBMessagePersistence mbMessagePersistence;
6771            @BeanReference(type = RatingsStatsPersistence.class)
6772            protected RatingsStatsPersistence ratingsStatsPersistence;
6773            private static final String _SQL_SELECT_LAYOUT = "SELECT layout FROM Layout layout";
6774            private static final String _SQL_SELECT_LAYOUT_WHERE = "SELECT layout FROM Layout layout WHERE ";
6775            private static final String _SQL_COUNT_LAYOUT = "SELECT COUNT(layout) FROM Layout layout";
6776            private static final String _SQL_COUNT_LAYOUT_WHERE = "SELECT COUNT(layout) FROM Layout layout WHERE ";
6777            private static final String _FINDER_COLUMN_UUID_UUID_1 = "layout.uuid IS NULL";
6778            private static final String _FINDER_COLUMN_UUID_UUID_2 = "layout.uuid = ?";
6779            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(layout.uuid IS NULL OR layout.uuid = ?)";
6780            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "layout.uuid IS NULL AND ";
6781            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "layout.uuid = ? AND ";
6782            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(layout.uuid IS NULL OR layout.uuid = ?) AND ";
6783            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "layout.groupId = ?";
6784            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "layout.groupId = ?";
6785            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "layout.companyId = ?";
6786            private static final String _FINDER_COLUMN_ICONIMAGEID_ICONIMAGEID_2 = "layout.iconImageId = ?";
6787            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "layout.groupId = ? AND ";
6788            private static final String _FINDER_COLUMN_G_P_PRIVATELAYOUT_2 = "layout.privateLayout = ?";
6789            private static final String _FINDER_COLUMN_G_P_L_GROUPID_2 = "layout.groupId = ? AND ";
6790            private static final String _FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
6791            private static final String _FINDER_COLUMN_G_P_L_LAYOUTID_2 = "layout.layoutId = ?";
6792            private static final String _FINDER_COLUMN_G_P_P_GROUPID_2 = "layout.groupId = ? AND ";
6793            private static final String _FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
6794            private static final String _FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2 = "layout.parentLayoutId = ?";
6795            private static final String _FINDER_COLUMN_G_P_F_GROUPID_2 = "layout.groupId = ? AND ";
6796            private static final String _FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
6797            private static final String _FINDER_COLUMN_G_P_F_FRIENDLYURL_1 = "layout.friendlyURL IS NULL";
6798            private static final String _FINDER_COLUMN_G_P_F_FRIENDLYURL_2 = "layout.friendlyURL = ?";
6799            private static final String _FINDER_COLUMN_G_P_F_FRIENDLYURL_3 = "(layout.friendlyURL IS NULL OR layout.friendlyURL = ?)";
6800            private static final String _FINDER_COLUMN_G_P_T_GROUPID_2 = "layout.groupId = ? AND ";
6801            private static final String _FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
6802            private static final String _FINDER_COLUMN_G_P_T_TYPE_1 = "layout.type IS NULL";
6803            private static final String _FINDER_COLUMN_G_P_T_TYPE_2 = "layout.type = ?";
6804            private static final String _FINDER_COLUMN_G_P_T_TYPE_3 = "(layout.type IS NULL OR layout.type = ?)";
6805            private static final String _FINDER_COLUMN_G_P_TLU_GROUPID_2 = "layout.groupId = ? AND ";
6806            private static final String _FINDER_COLUMN_G_P_TLU_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
6807            private static final String _FINDER_COLUMN_G_P_TLU_TEMPLATELAYOUTUUID_1 = "layout.templateLayoutUuid IS NULL";
6808            private static final String _FINDER_COLUMN_G_P_TLU_TEMPLATELAYOUTUUID_2 = "layout.templateLayoutUuid = ?";
6809            private static final String _FINDER_COLUMN_G_P_TLU_TEMPLATELAYOUTUUID_3 = "(layout.templateLayoutUuid IS NULL OR layout.templateLayoutUuid = ?)";
6810            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "layout.plid";
6811            private static final String _FILTER_SQL_SELECT_LAYOUT_WHERE = "SELECT DISTINCT {layout.*} FROM Layout layout WHERE ";
6812            private static final String _FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_1 =
6813                    "SELECT {Layout.*} FROM (SELECT DISTINCT layout.plid FROM Layout layout WHERE ";
6814            private static final String _FILTER_SQL_SELECT_LAYOUT_NO_INLINE_DISTINCT_WHERE_2 =
6815                    ") TEMP_TABLE INNER JOIN Layout ON TEMP_TABLE.plid = Layout.plid";
6816            private static final String _FILTER_SQL_COUNT_LAYOUT_WHERE = "SELECT COUNT(DISTINCT layout.plid) AS COUNT_VALUE FROM Layout layout WHERE ";
6817            private static final String _FILTER_ENTITY_ALIAS = "layout";
6818            private static final String _FILTER_ENTITY_TABLE = "Layout";
6819            private static final String _ORDER_BY_ENTITY_ALIAS = "layout.";
6820            private static final String _ORDER_BY_ENTITY_TABLE = "Layout.";
6821            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Layout exists with the primary key ";
6822            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Layout exists with the key {";
6823            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
6824            private static Log _log = LogFactoryUtil.getLog(LayoutPersistenceImpl.class);
6825            private static Layout _nullLayout = new LayoutImpl() {
6826                            @Override
6827                            public Object clone() {
6828                                    return this;
6829                            }
6830    
6831                            @Override
6832                            public CacheModel<Layout> toCacheModel() {
6833                                    return _nullLayoutCacheModel;
6834                            }
6835                    };
6836    
6837            private static CacheModel<Layout> _nullLayoutCacheModel = new CacheModel<Layout>() {
6838                            public Layout toEntityModel() {
6839                                    return _nullLayout;
6840                            }
6841                    };
6842    }