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