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