001    /**
002     * Copyright (c) 2000-2010 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.annotation.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.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.Layout;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.model.impl.LayoutImpl;
042    import com.liferay.portal.model.impl.LayoutModelImpl;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence;
046    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
047    import com.liferay.portlet.journal.service.persistence.JournalContentSearchPersistence;
048    import com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence;
049    import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
050    import com.liferay.portlet.tasks.service.persistence.TasksProposalPersistence;
051    
052    import java.io.Serializable;
053    
054    import java.util.ArrayList;
055    import java.util.Collections;
056    import java.util.List;
057    
058    /**
059     * The persistence for the layout service.
060     *
061     * <p>
062     * Never modify this class directly. Modify <code>service.xml</code> and rerun ServiceBuilder to regnerate this class.
063     * </p>
064     *
065     * <p>
066     * Caching information and settings can be found in <code>portal.properties</code>
067     * </p>
068     *
069     * @author Brian Wing Shun Chan
070     * @see LayoutPersistence
071     * @see LayoutUtil
072     * @generated
073     */
074    public class LayoutPersistenceImpl extends BasePersistenceImpl<Layout>
075            implements LayoutPersistence {
076            public static final String FINDER_CLASS_NAME_ENTITY = LayoutImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
078                    ".List";
079            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
080                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
081                            "findByUuid",
082                            new String[] {
083                                    String.class.getName(),
084                                    
085                            "java.lang.Integer", "java.lang.Integer",
086                                    "com.liferay.portal.kernel.util.OrderByComparator"
087                            });
088            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
089                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
090                            "countByUuid", new String[] { String.class.getName() });
091            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
092                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
093                            "fetchByUUID_G",
094                            new String[] { String.class.getName(), Long.class.getName() });
095            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
096                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
097                            "countByUUID_G",
098                            new String[] { String.class.getName(), Long.class.getName() });
099            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
100                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
101                            "findByGroupId",
102                            new String[] {
103                                    Long.class.getName(),
104                                    
105                            "java.lang.Integer", "java.lang.Integer",
106                                    "com.liferay.portal.kernel.util.OrderByComparator"
107                            });
108            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
109                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
110                            "countByGroupId", new String[] { Long.class.getName() });
111            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
112                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
113                            "findByCompanyId",
114                            new String[] {
115                                    Long.class.getName(),
116                                    
117                            "java.lang.Integer", "java.lang.Integer",
118                                    "com.liferay.portal.kernel.util.OrderByComparator"
119                            });
120            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
121                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
122                            "countByCompanyId", new String[] { Long.class.getName() });
123            public static final FinderPath FINDER_PATH_FETCH_BY_DLFOLDERID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
124                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
125                            "fetchByDLFolderId", new String[] { Long.class.getName() });
126            public static final FinderPath FINDER_PATH_COUNT_BY_DLFOLDERID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
127                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
128                            "countByDLFolderId", new String[] { Long.class.getName() });
129            public static final FinderPath FINDER_PATH_FETCH_BY_ICONIMAGEID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
130                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
131                            "fetchByIconImageId", new String[] { Long.class.getName() });
132            public static final FinderPath FINDER_PATH_COUNT_BY_ICONIMAGEID = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
133                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
134                            "countByIconImageId", new String[] { Long.class.getName() });
135            public static final FinderPath FINDER_PATH_FIND_BY_G_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
136                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
137                            "findByG_P",
138                            new String[] {
139                                    Long.class.getName(), Boolean.class.getName(),
140                                    
141                            "java.lang.Integer", "java.lang.Integer",
142                                    "com.liferay.portal.kernel.util.OrderByComparator"
143                            });
144            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
145                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
146                            "countByG_P",
147                            new String[] { Long.class.getName(), Boolean.class.getName() });
148            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_L = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
149                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
150                            "fetchByG_P_L",
151                            new String[] {
152                                    Long.class.getName(), Boolean.class.getName(),
153                                    Long.class.getName()
154                            });
155            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_L = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
156                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
157                            "countByG_P_L",
158                            new String[] {
159                                    Long.class.getName(), Boolean.class.getName(),
160                                    Long.class.getName()
161                            });
162            public static final FinderPath FINDER_PATH_FIND_BY_G_P_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
163                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
164                            "findByG_P_P",
165                            new String[] {
166                                    Long.class.getName(), Boolean.class.getName(),
167                                    Long.class.getName(),
168                                    
169                            "java.lang.Integer", "java.lang.Integer",
170                                    "com.liferay.portal.kernel.util.OrderByComparator"
171                            });
172            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_P = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
173                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
174                            "countByG_P_P",
175                            new String[] {
176                                    Long.class.getName(), Boolean.class.getName(),
177                                    Long.class.getName()
178                            });
179            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_F = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
180                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
181                            "fetchByG_P_F",
182                            new String[] {
183                                    Long.class.getName(), Boolean.class.getName(),
184                                    String.class.getName()
185                            });
186            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_F = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
187                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
188                            "countByG_P_F",
189                            new String[] {
190                                    Long.class.getName(), Boolean.class.getName(),
191                                    String.class.getName()
192                            });
193            public static final FinderPath FINDER_PATH_FIND_BY_G_P_T = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
194                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
195                            "findByG_P_T",
196                            new String[] {
197                                    Long.class.getName(), Boolean.class.getName(),
198                                    String.class.getName(),
199                                    
200                            "java.lang.Integer", "java.lang.Integer",
201                                    "com.liferay.portal.kernel.util.OrderByComparator"
202                            });
203            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_T = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
204                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
205                            "countByG_P_T",
206                            new String[] {
207                                    Long.class.getName(), Boolean.class.getName(),
208                                    String.class.getName()
209                            });
210            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
211                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
212                            "findAll", new String[0]);
213            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutModelImpl.ENTITY_CACHE_ENABLED,
214                            LayoutModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
215                            "countAll", new String[0]);
216    
217            /**
218             * Caches the layout in the entity cache if it is enabled.
219             *
220             * @param layout the layout to cache
221             */
222            public void cacheResult(Layout layout) {
223                    EntityCacheUtil.putResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
224                            LayoutImpl.class, layout.getPrimaryKey(), layout);
225    
226                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
227                            new Object[] { layout.getUuid(), new Long(layout.getGroupId()) },
228                            layout);
229    
230                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
231                            new Object[] { new Long(layout.getDlFolderId()) }, layout);
232    
233                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
234                            new Object[] { new Long(layout.getIconImageId()) }, layout);
235    
236                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L,
237                            new Object[] {
238                                    new Long(layout.getGroupId()),
239                                    Boolean.valueOf(layout.getPrivateLayout()),
240                                    new Long(layout.getLayoutId())
241                            }, layout);
242    
243                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_F,
244                            new Object[] {
245                                    new Long(layout.getGroupId()),
246                                    Boolean.valueOf(layout.getPrivateLayout()),
247                                    
248                            layout.getFriendlyURL()
249                            }, layout);
250            }
251    
252            /**
253             * Caches the layouts in the entity cache if it is enabled.
254             *
255             * @param layouts the layouts to cache
256             */
257            public void cacheResult(List<Layout> layouts) {
258                    for (Layout layout : layouts) {
259                            if (EntityCacheUtil.getResult(
260                                                    LayoutModelImpl.ENTITY_CACHE_ENABLED, LayoutImpl.class,
261                                                    layout.getPrimaryKey(), this) == null) {
262                                    cacheResult(layout);
263                            }
264                    }
265            }
266    
267            /**
268             * Clears the cache for all layouts.
269             *
270             * <p>
271             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
272             * </p>
273             */
274            public void clearCache() {
275                    CacheRegistryUtil.clear(LayoutImpl.class.getName());
276                    EntityCacheUtil.clearCache(LayoutImpl.class.getName());
277                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
278                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
279            }
280    
281            /**
282             * Clears the cache for the layout.
283             *
284             * <p>
285             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
286             * </p>
287             */
288            public void clearCache(Layout layout) {
289                    EntityCacheUtil.removeResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
290                            LayoutImpl.class, layout.getPrimaryKey());
291    
292                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
293                            new Object[] { layout.getUuid(), new Long(layout.getGroupId()) });
294    
295                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
296                            new Object[] { new Long(layout.getDlFolderId()) });
297    
298                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
299                            new Object[] { new Long(layout.getIconImageId()) });
300    
301                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_L,
302                            new Object[] {
303                                    new Long(layout.getGroupId()),
304                                    Boolean.valueOf(layout.getPrivateLayout()),
305                                    new Long(layout.getLayoutId())
306                            });
307    
308                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_F,
309                            new Object[] {
310                                    new Long(layout.getGroupId()),
311                                    Boolean.valueOf(layout.getPrivateLayout()),
312                                    
313                            layout.getFriendlyURL()
314                            });
315            }
316    
317            /**
318             * Creates a new layout with the primary key.
319             *
320             * @param plid the primary key for the new layout
321             * @return the new layout
322             */
323            public Layout create(long plid) {
324                    Layout layout = new LayoutImpl();
325    
326                    layout.setNew(true);
327                    layout.setPrimaryKey(plid);
328    
329                    String uuid = PortalUUIDUtil.generate();
330    
331                    layout.setUuid(uuid);
332    
333                    return layout;
334            }
335    
336            /**
337             * Removes the layout with the primary key from the database. Also notifies the appropriate model listeners.
338             *
339             * @param primaryKey the primary key of the layout to remove
340             * @return the layout that was removed
341             * @throws com.liferay.portal.NoSuchModelException if a layout with the primary key could not be found
342             * @throws SystemException if a system exception occurred
343             */
344            public Layout remove(Serializable primaryKey)
345                    throws NoSuchModelException, SystemException {
346                    return remove(((Long)primaryKey).longValue());
347            }
348    
349            /**
350             * Removes the layout with the primary key from the database. Also notifies the appropriate model listeners.
351             *
352             * @param plid the primary key of the layout to remove
353             * @return the layout that was removed
354             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
355             * @throws SystemException if a system exception occurred
356             */
357            public Layout remove(long plid)
358                    throws NoSuchLayoutException, SystemException {
359                    Session session = null;
360    
361                    try {
362                            session = openSession();
363    
364                            Layout layout = (Layout)session.get(LayoutImpl.class, new Long(plid));
365    
366                            if (layout == null) {
367                                    if (_log.isWarnEnabled()) {
368                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + plid);
369                                    }
370    
371                                    throw new NoSuchLayoutException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
372                                            plid);
373                            }
374    
375                            return remove(layout);
376                    }
377                    catch (NoSuchLayoutException nsee) {
378                            throw nsee;
379                    }
380                    catch (Exception e) {
381                            throw processException(e);
382                    }
383                    finally {
384                            closeSession(session);
385                    }
386            }
387    
388            protected Layout removeImpl(Layout layout) throws SystemException {
389                    layout = toUnwrappedModel(layout);
390    
391                    Session session = null;
392    
393                    try {
394                            session = openSession();
395    
396                            if (layout.isCachedModel() || BatchSessionUtil.isEnabled()) {
397                                    Object staleObject = session.get(LayoutImpl.class,
398                                                    layout.getPrimaryKeyObj());
399    
400                                    if (staleObject != null) {
401                                            session.evict(staleObject);
402                                    }
403                            }
404    
405                            session.delete(layout);
406    
407                            session.flush();
408                    }
409                    catch (Exception e) {
410                            throw processException(e);
411                    }
412                    finally {
413                            closeSession(session);
414                    }
415    
416                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
417    
418                    LayoutModelImpl layoutModelImpl = (LayoutModelImpl)layout;
419    
420                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
421                            new Object[] {
422                                    layoutModelImpl.getOriginalUuid(),
423                                    new Long(layoutModelImpl.getOriginalGroupId())
424                            });
425    
426                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
427                            new Object[] { new Long(layoutModelImpl.getOriginalDlFolderId()) });
428    
429                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
430                            new Object[] { new Long(layoutModelImpl.getOriginalIconImageId()) });
431    
432                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_L,
433                            new Object[] {
434                                    new Long(layoutModelImpl.getOriginalGroupId()),
435                                    Boolean.valueOf(layoutModelImpl.getOriginalPrivateLayout()),
436                                    new Long(layoutModelImpl.getOriginalLayoutId())
437                            });
438    
439                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_F,
440                            new Object[] {
441                                    new Long(layoutModelImpl.getOriginalGroupId()),
442                                    Boolean.valueOf(layoutModelImpl.getOriginalPrivateLayout()),
443                                    
444                            layoutModelImpl.getOriginalFriendlyURL()
445                            });
446    
447                    EntityCacheUtil.removeResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
448                            LayoutImpl.class, layout.getPrimaryKey());
449    
450                    return layout;
451            }
452    
453            public Layout updateImpl(com.liferay.portal.model.Layout layout,
454                    boolean merge) throws SystemException {
455                    layout = toUnwrappedModel(layout);
456    
457                    boolean isNew = layout.isNew();
458    
459                    LayoutModelImpl layoutModelImpl = (LayoutModelImpl)layout;
460    
461                    if (Validator.isNull(layout.getUuid())) {
462                            String uuid = PortalUUIDUtil.generate();
463    
464                            layout.setUuid(uuid);
465                    }
466    
467                    Session session = null;
468    
469                    try {
470                            session = openSession();
471    
472                            BatchSessionUtil.update(session, layout, merge);
473    
474                            layout.setNew(false);
475                    }
476                    catch (Exception e) {
477                            throw processException(e);
478                    }
479                    finally {
480                            closeSession(session);
481                    }
482    
483                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
484    
485                    EntityCacheUtil.putResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
486                            LayoutImpl.class, layout.getPrimaryKey(), layout);
487    
488                    if (!isNew &&
489                                    (!Validator.equals(layout.getUuid(),
490                                            layoutModelImpl.getOriginalUuid()) ||
491                                    (layout.getGroupId() != layoutModelImpl.getOriginalGroupId()))) {
492                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
493                                    new Object[] {
494                                            layoutModelImpl.getOriginalUuid(),
495                                            new Long(layoutModelImpl.getOriginalGroupId())
496                                    });
497                    }
498    
499                    if (isNew ||
500                                    (!Validator.equals(layout.getUuid(),
501                                            layoutModelImpl.getOriginalUuid()) ||
502                                    (layout.getGroupId() != layoutModelImpl.getOriginalGroupId()))) {
503                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
504                                    new Object[] { layout.getUuid(), new Long(layout.getGroupId()) },
505                                    layout);
506                    }
507    
508                    if (!isNew &&
509                                    (layout.getDlFolderId() != layoutModelImpl.getOriginalDlFolderId())) {
510                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
511                                    new Object[] { new Long(layoutModelImpl.getOriginalDlFolderId()) });
512                    }
513    
514                    if (isNew ||
515                                    (layout.getDlFolderId() != layoutModelImpl.getOriginalDlFolderId())) {
516                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
517                                    new Object[] { new Long(layout.getDlFolderId()) }, layout);
518                    }
519    
520                    if (!isNew &&
521                                    (layout.getIconImageId() != layoutModelImpl.getOriginalIconImageId())) {
522                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
523                                    new Object[] { new Long(layoutModelImpl.getOriginalIconImageId()) });
524                    }
525    
526                    if (isNew ||
527                                    (layout.getIconImageId() != layoutModelImpl.getOriginalIconImageId())) {
528                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
529                                    new Object[] { new Long(layout.getIconImageId()) }, layout);
530                    }
531    
532                    if (!isNew &&
533                                    ((layout.getGroupId() != layoutModelImpl.getOriginalGroupId()) ||
534                                    (layout.getPrivateLayout() != layoutModelImpl.getOriginalPrivateLayout()) ||
535                                    (layout.getLayoutId() != layoutModelImpl.getOriginalLayoutId()))) {
536                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_L,
537                                    new Object[] {
538                                            new Long(layoutModelImpl.getOriginalGroupId()),
539                                            Boolean.valueOf(layoutModelImpl.getOriginalPrivateLayout()),
540                                            new Long(layoutModelImpl.getOriginalLayoutId())
541                                    });
542                    }
543    
544                    if (isNew ||
545                                    ((layout.getGroupId() != layoutModelImpl.getOriginalGroupId()) ||
546                                    (layout.getPrivateLayout() != layoutModelImpl.getOriginalPrivateLayout()) ||
547                                    (layout.getLayoutId() != layoutModelImpl.getOriginalLayoutId()))) {
548                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L,
549                                    new Object[] {
550                                            new Long(layout.getGroupId()),
551                                            Boolean.valueOf(layout.getPrivateLayout()),
552                                            new Long(layout.getLayoutId())
553                                    }, layout);
554                    }
555    
556                    if (!isNew &&
557                                    ((layout.getGroupId() != layoutModelImpl.getOriginalGroupId()) ||
558                                    (layout.getPrivateLayout() != layoutModelImpl.getOriginalPrivateLayout()) ||
559                                    !Validator.equals(layout.getFriendlyURL(),
560                                            layoutModelImpl.getOriginalFriendlyURL()))) {
561                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_F,
562                                    new Object[] {
563                                            new Long(layoutModelImpl.getOriginalGroupId()),
564                                            Boolean.valueOf(layoutModelImpl.getOriginalPrivateLayout()),
565                                            
566                                    layoutModelImpl.getOriginalFriendlyURL()
567                                    });
568                    }
569    
570                    if (isNew ||
571                                    ((layout.getGroupId() != layoutModelImpl.getOriginalGroupId()) ||
572                                    (layout.getPrivateLayout() != layoutModelImpl.getOriginalPrivateLayout()) ||
573                                    !Validator.equals(layout.getFriendlyURL(),
574                                            layoutModelImpl.getOriginalFriendlyURL()))) {
575                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_F,
576                                    new Object[] {
577                                            new Long(layout.getGroupId()),
578                                            Boolean.valueOf(layout.getPrivateLayout()),
579                                            
580                                    layout.getFriendlyURL()
581                                    }, layout);
582                    }
583    
584                    return layout;
585            }
586    
587            protected Layout toUnwrappedModel(Layout layout) {
588                    if (layout instanceof LayoutImpl) {
589                            return layout;
590                    }
591    
592                    LayoutImpl layoutImpl = new LayoutImpl();
593    
594                    layoutImpl.setNew(layout.isNew());
595                    layoutImpl.setPrimaryKey(layout.getPrimaryKey());
596    
597                    layoutImpl.setUuid(layout.getUuid());
598                    layoutImpl.setPlid(layout.getPlid());
599                    layoutImpl.setGroupId(layout.getGroupId());
600                    layoutImpl.setCompanyId(layout.getCompanyId());
601                    layoutImpl.setPrivateLayout(layout.isPrivateLayout());
602                    layoutImpl.setLayoutId(layout.getLayoutId());
603                    layoutImpl.setParentLayoutId(layout.getParentLayoutId());
604                    layoutImpl.setName(layout.getName());
605                    layoutImpl.setTitle(layout.getTitle());
606                    layoutImpl.setDescription(layout.getDescription());
607                    layoutImpl.setType(layout.getType());
608                    layoutImpl.setTypeSettings(layout.getTypeSettings());
609                    layoutImpl.setHidden(layout.isHidden());
610                    layoutImpl.setFriendlyURL(layout.getFriendlyURL());
611                    layoutImpl.setIconImage(layout.isIconImage());
612                    layoutImpl.setIconImageId(layout.getIconImageId());
613                    layoutImpl.setThemeId(layout.getThemeId());
614                    layoutImpl.setColorSchemeId(layout.getColorSchemeId());
615                    layoutImpl.setWapThemeId(layout.getWapThemeId());
616                    layoutImpl.setWapColorSchemeId(layout.getWapColorSchemeId());
617                    layoutImpl.setCss(layout.getCss());
618                    layoutImpl.setPriority(layout.getPriority());
619                    layoutImpl.setLayoutPrototypeId(layout.getLayoutPrototypeId());
620                    layoutImpl.setDlFolderId(layout.getDlFolderId());
621    
622                    return layoutImpl;
623            }
624    
625            /**
626             * Finds the layout with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
627             *
628             * @param primaryKey the primary key of the layout to find
629             * @return the layout
630             * @throws com.liferay.portal.NoSuchModelException if a layout with the primary key could not be found
631             * @throws SystemException if a system exception occurred
632             */
633            public Layout findByPrimaryKey(Serializable primaryKey)
634                    throws NoSuchModelException, SystemException {
635                    return findByPrimaryKey(((Long)primaryKey).longValue());
636            }
637    
638            /**
639             * Finds the layout with the primary key or throws a {@link com.liferay.portal.NoSuchLayoutException} if it could not be found.
640             *
641             * @param plid the primary key of the layout to find
642             * @return the layout
643             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
644             * @throws SystemException if a system exception occurred
645             */
646            public Layout findByPrimaryKey(long plid)
647                    throws NoSuchLayoutException, SystemException {
648                    Layout layout = fetchByPrimaryKey(plid);
649    
650                    if (layout == null) {
651                            if (_log.isWarnEnabled()) {
652                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + plid);
653                            }
654    
655                            throw new NoSuchLayoutException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
656                                    plid);
657                    }
658    
659                    return layout;
660            }
661    
662            /**
663             * Finds the layout with the primary key or returns <code>null</code> if it could not be found.
664             *
665             * @param primaryKey the primary key of the layout to find
666             * @return the layout, or <code>null</code> if a layout with the primary key could not be found
667             * @throws SystemException if a system exception occurred
668             */
669            public Layout fetchByPrimaryKey(Serializable primaryKey)
670                    throws SystemException {
671                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
672            }
673    
674            /**
675             * Finds the layout with the primary key or returns <code>null</code> if it could not be found.
676             *
677             * @param plid the primary key of the layout to find
678             * @return the layout, or <code>null</code> if a layout with the primary key could not be found
679             * @throws SystemException if a system exception occurred
680             */
681            public Layout fetchByPrimaryKey(long plid) throws SystemException {
682                    Layout layout = (Layout)EntityCacheUtil.getResult(LayoutModelImpl.ENTITY_CACHE_ENABLED,
683                                    LayoutImpl.class, plid, this);
684    
685                    if (layout == null) {
686                            Session session = null;
687    
688                            try {
689                                    session = openSession();
690    
691                                    layout = (Layout)session.get(LayoutImpl.class, new Long(plid));
692                            }
693                            catch (Exception e) {
694                                    throw processException(e);
695                            }
696                            finally {
697                                    if (layout != null) {
698                                            cacheResult(layout);
699                                    }
700    
701                                    closeSession(session);
702                            }
703                    }
704    
705                    return layout;
706            }
707    
708            /**
709             * Finds all the layouts where uuid = &#63;.
710             *
711             * @param uuid the uuid to search with
712             * @return the matching layouts
713             * @throws SystemException if a system exception occurred
714             */
715            public List<Layout> findByUuid(String uuid) throws SystemException {
716                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
717            }
718    
719            /**
720             * Finds a range of all the layouts where uuid = &#63;.
721             *
722             * <p>
723             * 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.
724             * </p>
725             *
726             * @param uuid the uuid to search with
727             * @param start the lower bound of the range of layouts to return
728             * @param end the upper bound of the range of layouts to return (not inclusive)
729             * @return the range of matching layouts
730             * @throws SystemException if a system exception occurred
731             */
732            public List<Layout> findByUuid(String uuid, int start, int end)
733                    throws SystemException {
734                    return findByUuid(uuid, start, end, null);
735            }
736    
737            /**
738             * Finds an ordered range of all the layouts where uuid = &#63;.
739             *
740             * <p>
741             * 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.
742             * </p>
743             *
744             * @param uuid the uuid to search with
745             * @param start the lower bound of the range of layouts to return
746             * @param end the upper bound of the range of layouts to return (not inclusive)
747             * @param orderByComparator the comparator to order the results by
748             * @return the ordered range of matching layouts
749             * @throws SystemException if a system exception occurred
750             */
751            public List<Layout> findByUuid(String uuid, int start, int end,
752                    OrderByComparator orderByComparator) throws SystemException {
753                    Object[] finderArgs = new Object[] {
754                                    uuid,
755                                    
756                                    String.valueOf(start), String.valueOf(end),
757                                    String.valueOf(orderByComparator)
758                            };
759    
760                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
761                                    finderArgs, this);
762    
763                    if (list == null) {
764                            Session session = null;
765    
766                            try {
767                                    session = openSession();
768    
769                                    StringBundler query = null;
770    
771                                    if (orderByComparator != null) {
772                                            query = new StringBundler(3 +
773                                                            (orderByComparator.getOrderByFields().length * 3));
774                                    }
775                                    else {
776                                            query = new StringBundler(3);
777                                    }
778    
779                                    query.append(_SQL_SELECT_LAYOUT_WHERE);
780    
781                                    if (uuid == null) {
782                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
783                                    }
784                                    else {
785                                            if (uuid.equals(StringPool.BLANK)) {
786                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
787                                            }
788                                            else {
789                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
790                                            }
791                                    }
792    
793                                    if (orderByComparator != null) {
794                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
795                                                    orderByComparator);
796                                    }
797    
798                                    else {
799                                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
800                                    }
801    
802                                    String sql = query.toString();
803    
804                                    Query q = session.createQuery(sql);
805    
806                                    QueryPos qPos = QueryPos.getInstance(q);
807    
808                                    if (uuid != null) {
809                                            qPos.add(uuid);
810                                    }
811    
812                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
813                            }
814                            catch (Exception e) {
815                                    throw processException(e);
816                            }
817                            finally {
818                                    if (list == null) {
819                                            list = new ArrayList<Layout>();
820                                    }
821    
822                                    cacheResult(list);
823    
824                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
825                                            list);
826    
827                                    closeSession(session);
828                            }
829                    }
830    
831                    return list;
832            }
833    
834            /**
835             * Finds the first layout in the ordered set where uuid = &#63;.
836             *
837             * <p>
838             * 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.
839             * </p>
840             *
841             * @param uuid the uuid to search with
842             * @param orderByComparator the comparator to order the set by
843             * @return the first matching layout
844             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
845             * @throws SystemException if a system exception occurred
846             */
847            public Layout findByUuid_First(String uuid,
848                    OrderByComparator orderByComparator)
849                    throws NoSuchLayoutException, SystemException {
850                    List<Layout> list = findByUuid(uuid, 0, 1, orderByComparator);
851    
852                    if (list.isEmpty()) {
853                            StringBundler msg = new StringBundler(4);
854    
855                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
856    
857                            msg.append("uuid=");
858                            msg.append(uuid);
859    
860                            msg.append(StringPool.CLOSE_CURLY_BRACE);
861    
862                            throw new NoSuchLayoutException(msg.toString());
863                    }
864                    else {
865                            return list.get(0);
866                    }
867            }
868    
869            /**
870             * Finds the last layout in the ordered set where uuid = &#63;.
871             *
872             * <p>
873             * 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.
874             * </p>
875             *
876             * @param uuid the uuid to search with
877             * @param orderByComparator the comparator to order the set by
878             * @return the last matching layout
879             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
880             * @throws SystemException if a system exception occurred
881             */
882            public Layout findByUuid_Last(String uuid,
883                    OrderByComparator orderByComparator)
884                    throws NoSuchLayoutException, SystemException {
885                    int count = countByUuid(uuid);
886    
887                    List<Layout> list = findByUuid(uuid, count - 1, count, orderByComparator);
888    
889                    if (list.isEmpty()) {
890                            StringBundler msg = new StringBundler(4);
891    
892                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
893    
894                            msg.append("uuid=");
895                            msg.append(uuid);
896    
897                            msg.append(StringPool.CLOSE_CURLY_BRACE);
898    
899                            throw new NoSuchLayoutException(msg.toString());
900                    }
901                    else {
902                            return list.get(0);
903                    }
904            }
905    
906            /**
907             * Finds the layouts before and after the current layout in the ordered set where uuid = &#63;.
908             *
909             * <p>
910             * 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.
911             * </p>
912             *
913             * @param plid the primary key of the current layout
914             * @param uuid the uuid to search with
915             * @param orderByComparator the comparator to order the set by
916             * @return the previous, current, and next layout
917             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
918             * @throws SystemException if a system exception occurred
919             */
920            public Layout[] findByUuid_PrevAndNext(long plid, String uuid,
921                    OrderByComparator orderByComparator)
922                    throws NoSuchLayoutException, SystemException {
923                    Layout layout = findByPrimaryKey(plid);
924    
925                    Session session = null;
926    
927                    try {
928                            session = openSession();
929    
930                            Layout[] array = new LayoutImpl[3];
931    
932                            array[0] = getByUuid_PrevAndNext(session, layout, uuid,
933                                            orderByComparator, true);
934    
935                            array[1] = layout;
936    
937                            array[2] = getByUuid_PrevAndNext(session, layout, uuid,
938                                            orderByComparator, false);
939    
940                            return array;
941                    }
942                    catch (Exception e) {
943                            throw processException(e);
944                    }
945                    finally {
946                            closeSession(session);
947                    }
948            }
949    
950            protected Layout getByUuid_PrevAndNext(Session session, Layout layout,
951                    String uuid, OrderByComparator orderByComparator, boolean previous) {
952                    StringBundler query = null;
953    
954                    if (orderByComparator != null) {
955                            query = new StringBundler(6 +
956                                            (orderByComparator.getOrderByFields().length * 6));
957                    }
958                    else {
959                            query = new StringBundler(3);
960                    }
961    
962                    query.append(_SQL_SELECT_LAYOUT_WHERE);
963    
964                    if (uuid == null) {
965                            query.append(_FINDER_COLUMN_UUID_UUID_1);
966                    }
967                    else {
968                            if (uuid.equals(StringPool.BLANK)) {
969                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
970                            }
971                            else {
972                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
973                            }
974                    }
975    
976                    if (orderByComparator != null) {
977                            String[] orderByFields = orderByComparator.getOrderByFields();
978    
979                            if (orderByFields.length > 0) {
980                                    query.append(WHERE_AND);
981                            }
982    
983                            for (int i = 0; i < orderByFields.length; i++) {
984                                    query.append(_ORDER_BY_ENTITY_ALIAS);
985                                    query.append(orderByFields[i]);
986    
987                                    if ((i + 1) < orderByFields.length) {
988                                            if (orderByComparator.isAscending() ^ previous) {
989                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
990                                            }
991                                            else {
992                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
993                                            }
994                                    }
995                                    else {
996                                            if (orderByComparator.isAscending() ^ previous) {
997                                                    query.append(WHERE_GREATER_THAN);
998                                            }
999                                            else {
1000                                                    query.append(WHERE_LESSER_THAN);
1001                                            }
1002                                    }
1003                            }
1004    
1005                            query.append(ORDER_BY_CLAUSE);
1006    
1007                            for (int i = 0; i < orderByFields.length; i++) {
1008                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1009                                    query.append(orderByFields[i]);
1010    
1011                                    if ((i + 1) < orderByFields.length) {
1012                                            if (orderByComparator.isAscending() ^ previous) {
1013                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1014                                            }
1015                                            else {
1016                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1017                                            }
1018                                    }
1019                                    else {
1020                                            if (orderByComparator.isAscending() ^ previous) {
1021                                                    query.append(ORDER_BY_ASC);
1022                                            }
1023                                            else {
1024                                                    query.append(ORDER_BY_DESC);
1025                                            }
1026                                    }
1027                            }
1028                    }
1029    
1030                    else {
1031                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
1032                    }
1033    
1034                    String sql = query.toString();
1035    
1036                    Query q = session.createQuery(sql);
1037    
1038                    q.setFirstResult(0);
1039                    q.setMaxResults(2);
1040    
1041                    QueryPos qPos = QueryPos.getInstance(q);
1042    
1043                    if (uuid != null) {
1044                            qPos.add(uuid);
1045                    }
1046    
1047                    if (orderByComparator != null) {
1048                            Object[] values = orderByComparator.getOrderByValues(layout);
1049    
1050                            for (Object value : values) {
1051                                    qPos.add(value);
1052                            }
1053                    }
1054    
1055                    List<Layout> list = q.list();
1056    
1057                    if (list.size() == 2) {
1058                            return list.get(1);
1059                    }
1060                    else {
1061                            return null;
1062                    }
1063            }
1064    
1065            /**
1066             * Finds the layout where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutException} if it could not be found.
1067             *
1068             * @param uuid the uuid to search with
1069             * @param groupId the group id to search with
1070             * @return the matching layout
1071             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1072             * @throws SystemException if a system exception occurred
1073             */
1074            public Layout findByUUID_G(String uuid, long groupId)
1075                    throws NoSuchLayoutException, SystemException {
1076                    Layout layout = fetchByUUID_G(uuid, groupId);
1077    
1078                    if (layout == null) {
1079                            StringBundler msg = new StringBundler(6);
1080    
1081                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1082    
1083                            msg.append("uuid=");
1084                            msg.append(uuid);
1085    
1086                            msg.append(", groupId=");
1087                            msg.append(groupId);
1088    
1089                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1090    
1091                            if (_log.isWarnEnabled()) {
1092                                    _log.warn(msg.toString());
1093                            }
1094    
1095                            throw new NoSuchLayoutException(msg.toString());
1096                    }
1097    
1098                    return layout;
1099            }
1100    
1101            /**
1102             * Finds the layout where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1103             *
1104             * @param uuid the uuid to search with
1105             * @param groupId the group id to search with
1106             * @return the matching layout, or <code>null</code> if a matching layout could not be found
1107             * @throws SystemException if a system exception occurred
1108             */
1109            public Layout fetchByUUID_G(String uuid, long groupId)
1110                    throws SystemException {
1111                    return fetchByUUID_G(uuid, groupId, true);
1112            }
1113    
1114            /**
1115             * Finds the layout where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1116             *
1117             * @param uuid the uuid to search with
1118             * @param groupId the group id to search with
1119             * @return the matching layout, or <code>null</code> if a matching layout could not be found
1120             * @throws SystemException if a system exception occurred
1121             */
1122            public Layout fetchByUUID_G(String uuid, long groupId,
1123                    boolean retrieveFromCache) throws SystemException {
1124                    Object[] finderArgs = new Object[] { uuid, groupId };
1125    
1126                    Object result = null;
1127    
1128                    if (retrieveFromCache) {
1129                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1130                                            finderArgs, this);
1131                    }
1132    
1133                    if (result == null) {
1134                            Session session = null;
1135    
1136                            try {
1137                                    session = openSession();
1138    
1139                                    StringBundler query = new StringBundler(4);
1140    
1141                                    query.append(_SQL_SELECT_LAYOUT_WHERE);
1142    
1143                                    if (uuid == null) {
1144                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1145                                    }
1146                                    else {
1147                                            if (uuid.equals(StringPool.BLANK)) {
1148                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1149                                            }
1150                                            else {
1151                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1152                                            }
1153                                    }
1154    
1155                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1156    
1157                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
1158    
1159                                    String sql = query.toString();
1160    
1161                                    Query q = session.createQuery(sql);
1162    
1163                                    QueryPos qPos = QueryPos.getInstance(q);
1164    
1165                                    if (uuid != null) {
1166                                            qPos.add(uuid);
1167                                    }
1168    
1169                                    qPos.add(groupId);
1170    
1171                                    List<Layout> list = q.list();
1172    
1173                                    result = list;
1174    
1175                                    Layout layout = null;
1176    
1177                                    if (list.isEmpty()) {
1178                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1179                                                    finderArgs, list);
1180                                    }
1181                                    else {
1182                                            layout = list.get(0);
1183    
1184                                            cacheResult(layout);
1185    
1186                                            if ((layout.getUuid() == null) ||
1187                                                            !layout.getUuid().equals(uuid) ||
1188                                                            (layout.getGroupId() != groupId)) {
1189                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1190                                                            finderArgs, layout);
1191                                            }
1192                                    }
1193    
1194                                    return layout;
1195                            }
1196                            catch (Exception e) {
1197                                    throw processException(e);
1198                            }
1199                            finally {
1200                                    if (result == null) {
1201                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1202                                                    finderArgs, new ArrayList<Layout>());
1203                                    }
1204    
1205                                    closeSession(session);
1206                            }
1207                    }
1208                    else {
1209                            if (result instanceof List<?>) {
1210                                    return null;
1211                            }
1212                            else {
1213                                    return (Layout)result;
1214                            }
1215                    }
1216            }
1217    
1218            /**
1219             * Finds all the layouts where groupId = &#63;.
1220             *
1221             * @param groupId the group id to search with
1222             * @return the matching layouts
1223             * @throws SystemException if a system exception occurred
1224             */
1225            public List<Layout> findByGroupId(long groupId) throws SystemException {
1226                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1227            }
1228    
1229            /**
1230             * Finds a range of all the layouts where groupId = &#63;.
1231             *
1232             * <p>
1233             * 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.
1234             * </p>
1235             *
1236             * @param groupId the group id to search with
1237             * @param start the lower bound of the range of layouts to return
1238             * @param end the upper bound of the range of layouts to return (not inclusive)
1239             * @return the range of matching layouts
1240             * @throws SystemException if a system exception occurred
1241             */
1242            public List<Layout> findByGroupId(long groupId, int start, int end)
1243                    throws SystemException {
1244                    return findByGroupId(groupId, start, end, null);
1245            }
1246    
1247            /**
1248             * Finds an ordered range of all the layouts where groupId = &#63;.
1249             *
1250             * <p>
1251             * 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.
1252             * </p>
1253             *
1254             * @param groupId the group id to search with
1255             * @param start the lower bound of the range of layouts to return
1256             * @param end the upper bound of the range of layouts to return (not inclusive)
1257             * @param orderByComparator the comparator to order the results by
1258             * @return the ordered range of matching layouts
1259             * @throws SystemException if a system exception occurred
1260             */
1261            public List<Layout> findByGroupId(long groupId, int start, int end,
1262                    OrderByComparator orderByComparator) throws SystemException {
1263                    Object[] finderArgs = new Object[] {
1264                                    groupId,
1265                                    
1266                                    String.valueOf(start), String.valueOf(end),
1267                                    String.valueOf(orderByComparator)
1268                            };
1269    
1270                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1271                                    finderArgs, this);
1272    
1273                    if (list == null) {
1274                            Session session = null;
1275    
1276                            try {
1277                                    session = openSession();
1278    
1279                                    StringBundler query = null;
1280    
1281                                    if (orderByComparator != null) {
1282                                            query = new StringBundler(3 +
1283                                                            (orderByComparator.getOrderByFields().length * 3));
1284                                    }
1285                                    else {
1286                                            query = new StringBundler(3);
1287                                    }
1288    
1289                                    query.append(_SQL_SELECT_LAYOUT_WHERE);
1290    
1291                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1292    
1293                                    if (orderByComparator != null) {
1294                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1295                                                    orderByComparator);
1296                                    }
1297    
1298                                    else {
1299                                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
1300                                    }
1301    
1302                                    String sql = query.toString();
1303    
1304                                    Query q = session.createQuery(sql);
1305    
1306                                    QueryPos qPos = QueryPos.getInstance(q);
1307    
1308                                    qPos.add(groupId);
1309    
1310                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
1311                            }
1312                            catch (Exception e) {
1313                                    throw processException(e);
1314                            }
1315                            finally {
1316                                    if (list == null) {
1317                                            list = new ArrayList<Layout>();
1318                                    }
1319    
1320                                    cacheResult(list);
1321    
1322                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1323                                            finderArgs, list);
1324    
1325                                    closeSession(session);
1326                            }
1327                    }
1328    
1329                    return list;
1330            }
1331    
1332            /**
1333             * Finds the first layout in the ordered set where groupId = &#63;.
1334             *
1335             * <p>
1336             * 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.
1337             * </p>
1338             *
1339             * @param groupId the group id to search with
1340             * @param orderByComparator the comparator to order the set by
1341             * @return the first matching layout
1342             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1343             * @throws SystemException if a system exception occurred
1344             */
1345            public Layout findByGroupId_First(long groupId,
1346                    OrderByComparator orderByComparator)
1347                    throws NoSuchLayoutException, SystemException {
1348                    List<Layout> list = findByGroupId(groupId, 0, 1, orderByComparator);
1349    
1350                    if (list.isEmpty()) {
1351                            StringBundler msg = new StringBundler(4);
1352    
1353                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1354    
1355                            msg.append("groupId=");
1356                            msg.append(groupId);
1357    
1358                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1359    
1360                            throw new NoSuchLayoutException(msg.toString());
1361                    }
1362                    else {
1363                            return list.get(0);
1364                    }
1365            }
1366    
1367            /**
1368             * Finds the last layout in the ordered set where groupId = &#63;.
1369             *
1370             * <p>
1371             * 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.
1372             * </p>
1373             *
1374             * @param groupId the group id to search with
1375             * @param orderByComparator the comparator to order the set by
1376             * @return the last matching layout
1377             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1378             * @throws SystemException if a system exception occurred
1379             */
1380            public Layout findByGroupId_Last(long groupId,
1381                    OrderByComparator orderByComparator)
1382                    throws NoSuchLayoutException, SystemException {
1383                    int count = countByGroupId(groupId);
1384    
1385                    List<Layout> list = findByGroupId(groupId, count - 1, count,
1386                                    orderByComparator);
1387    
1388                    if (list.isEmpty()) {
1389                            StringBundler msg = new StringBundler(4);
1390    
1391                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1392    
1393                            msg.append("groupId=");
1394                            msg.append(groupId);
1395    
1396                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1397    
1398                            throw new NoSuchLayoutException(msg.toString());
1399                    }
1400                    else {
1401                            return list.get(0);
1402                    }
1403            }
1404    
1405            /**
1406             * Finds the layouts before and after the current layout in the ordered set where groupId = &#63;.
1407             *
1408             * <p>
1409             * 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.
1410             * </p>
1411             *
1412             * @param plid the primary key of the current layout
1413             * @param groupId the group id to search with
1414             * @param orderByComparator the comparator to order the set by
1415             * @return the previous, current, and next layout
1416             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
1417             * @throws SystemException if a system exception occurred
1418             */
1419            public Layout[] findByGroupId_PrevAndNext(long plid, long groupId,
1420                    OrderByComparator orderByComparator)
1421                    throws NoSuchLayoutException, SystemException {
1422                    Layout layout = findByPrimaryKey(plid);
1423    
1424                    Session session = null;
1425    
1426                    try {
1427                            session = openSession();
1428    
1429                            Layout[] array = new LayoutImpl[3];
1430    
1431                            array[0] = getByGroupId_PrevAndNext(session, layout, groupId,
1432                                            orderByComparator, true);
1433    
1434                            array[1] = layout;
1435    
1436                            array[2] = getByGroupId_PrevAndNext(session, layout, groupId,
1437                                            orderByComparator, false);
1438    
1439                            return array;
1440                    }
1441                    catch (Exception e) {
1442                            throw processException(e);
1443                    }
1444                    finally {
1445                            closeSession(session);
1446                    }
1447            }
1448    
1449            protected Layout getByGroupId_PrevAndNext(Session session, Layout layout,
1450                    long groupId, OrderByComparator orderByComparator, boolean previous) {
1451                    StringBundler query = null;
1452    
1453                    if (orderByComparator != null) {
1454                            query = new StringBundler(6 +
1455                                            (orderByComparator.getOrderByFields().length * 6));
1456                    }
1457                    else {
1458                            query = new StringBundler(3);
1459                    }
1460    
1461                    query.append(_SQL_SELECT_LAYOUT_WHERE);
1462    
1463                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1464    
1465                    if (orderByComparator != null) {
1466                            String[] orderByFields = orderByComparator.getOrderByFields();
1467    
1468                            if (orderByFields.length > 0) {
1469                                    query.append(WHERE_AND);
1470                            }
1471    
1472                            for (int i = 0; i < orderByFields.length; i++) {
1473                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1474                                    query.append(orderByFields[i]);
1475    
1476                                    if ((i + 1) < orderByFields.length) {
1477                                            if (orderByComparator.isAscending() ^ previous) {
1478                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1479                                            }
1480                                            else {
1481                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1482                                            }
1483                                    }
1484                                    else {
1485                                            if (orderByComparator.isAscending() ^ previous) {
1486                                                    query.append(WHERE_GREATER_THAN);
1487                                            }
1488                                            else {
1489                                                    query.append(WHERE_LESSER_THAN);
1490                                            }
1491                                    }
1492                            }
1493    
1494                            query.append(ORDER_BY_CLAUSE);
1495    
1496                            for (int i = 0; i < orderByFields.length; i++) {
1497                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1498                                    query.append(orderByFields[i]);
1499    
1500                                    if ((i + 1) < orderByFields.length) {
1501                                            if (orderByComparator.isAscending() ^ previous) {
1502                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1503                                            }
1504                                            else {
1505                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1506                                            }
1507                                    }
1508                                    else {
1509                                            if (orderByComparator.isAscending() ^ previous) {
1510                                                    query.append(ORDER_BY_ASC);
1511                                            }
1512                                            else {
1513                                                    query.append(ORDER_BY_DESC);
1514                                            }
1515                                    }
1516                            }
1517                    }
1518    
1519                    else {
1520                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
1521                    }
1522    
1523                    String sql = query.toString();
1524    
1525                    Query q = session.createQuery(sql);
1526    
1527                    q.setFirstResult(0);
1528                    q.setMaxResults(2);
1529    
1530                    QueryPos qPos = QueryPos.getInstance(q);
1531    
1532                    qPos.add(groupId);
1533    
1534                    if (orderByComparator != null) {
1535                            Object[] values = orderByComparator.getOrderByValues(layout);
1536    
1537                            for (Object value : values) {
1538                                    qPos.add(value);
1539                            }
1540                    }
1541    
1542                    List<Layout> list = q.list();
1543    
1544                    if (list.size() == 2) {
1545                            return list.get(1);
1546                    }
1547                    else {
1548                            return null;
1549                    }
1550            }
1551    
1552            /**
1553             * Finds all the layouts where companyId = &#63;.
1554             *
1555             * @param companyId the company id to search with
1556             * @return the matching layouts
1557             * @throws SystemException if a system exception occurred
1558             */
1559            public List<Layout> findByCompanyId(long companyId)
1560                    throws SystemException {
1561                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1562                            null);
1563            }
1564    
1565            /**
1566             * Finds a range of all the layouts where companyId = &#63;.
1567             *
1568             * <p>
1569             * 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.
1570             * </p>
1571             *
1572             * @param companyId the company id to search with
1573             * @param start the lower bound of the range of layouts to return
1574             * @param end the upper bound of the range of layouts to return (not inclusive)
1575             * @return the range of matching layouts
1576             * @throws SystemException if a system exception occurred
1577             */
1578            public List<Layout> findByCompanyId(long companyId, int start, int end)
1579                    throws SystemException {
1580                    return findByCompanyId(companyId, start, end, null);
1581            }
1582    
1583            /**
1584             * Finds an ordered range of all the layouts where companyId = &#63;.
1585             *
1586             * <p>
1587             * 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.
1588             * </p>
1589             *
1590             * @param companyId the company id to search with
1591             * @param start the lower bound of the range of layouts to return
1592             * @param end the upper bound of the range of layouts to return (not inclusive)
1593             * @param orderByComparator the comparator to order the results by
1594             * @return the ordered range of matching layouts
1595             * @throws SystemException if a system exception occurred
1596             */
1597            public List<Layout> findByCompanyId(long companyId, int start, int end,
1598                    OrderByComparator orderByComparator) throws SystemException {
1599                    Object[] finderArgs = new Object[] {
1600                                    companyId,
1601                                    
1602                                    String.valueOf(start), String.valueOf(end),
1603                                    String.valueOf(orderByComparator)
1604                            };
1605    
1606                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1607                                    finderArgs, this);
1608    
1609                    if (list == null) {
1610                            Session session = null;
1611    
1612                            try {
1613                                    session = openSession();
1614    
1615                                    StringBundler query = null;
1616    
1617                                    if (orderByComparator != null) {
1618                                            query = new StringBundler(3 +
1619                                                            (orderByComparator.getOrderByFields().length * 3));
1620                                    }
1621                                    else {
1622                                            query = new StringBundler(3);
1623                                    }
1624    
1625                                    query.append(_SQL_SELECT_LAYOUT_WHERE);
1626    
1627                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1628    
1629                                    if (orderByComparator != null) {
1630                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1631                                                    orderByComparator);
1632                                    }
1633    
1634                                    else {
1635                                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
1636                                    }
1637    
1638                                    String sql = query.toString();
1639    
1640                                    Query q = session.createQuery(sql);
1641    
1642                                    QueryPos qPos = QueryPos.getInstance(q);
1643    
1644                                    qPos.add(companyId);
1645    
1646                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
1647                            }
1648                            catch (Exception e) {
1649                                    throw processException(e);
1650                            }
1651                            finally {
1652                                    if (list == null) {
1653                                            list = new ArrayList<Layout>();
1654                                    }
1655    
1656                                    cacheResult(list);
1657    
1658                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1659                                            finderArgs, list);
1660    
1661                                    closeSession(session);
1662                            }
1663                    }
1664    
1665                    return list;
1666            }
1667    
1668            /**
1669             * Finds the first layout in the ordered set where companyId = &#63;.
1670             *
1671             * <p>
1672             * 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.
1673             * </p>
1674             *
1675             * @param companyId the company id to search with
1676             * @param orderByComparator the comparator to order the set by
1677             * @return the first matching layout
1678             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1679             * @throws SystemException if a system exception occurred
1680             */
1681            public Layout findByCompanyId_First(long companyId,
1682                    OrderByComparator orderByComparator)
1683                    throws NoSuchLayoutException, SystemException {
1684                    List<Layout> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1685    
1686                    if (list.isEmpty()) {
1687                            StringBundler msg = new StringBundler(4);
1688    
1689                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1690    
1691                            msg.append("companyId=");
1692                            msg.append(companyId);
1693    
1694                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1695    
1696                            throw new NoSuchLayoutException(msg.toString());
1697                    }
1698                    else {
1699                            return list.get(0);
1700                    }
1701            }
1702    
1703            /**
1704             * Finds the last layout in the ordered set where companyId = &#63;.
1705             *
1706             * <p>
1707             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1708             * </p>
1709             *
1710             * @param companyId the company id to search with
1711             * @param orderByComparator the comparator to order the set by
1712             * @return the last matching layout
1713             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1714             * @throws SystemException if a system exception occurred
1715             */
1716            public Layout findByCompanyId_Last(long companyId,
1717                    OrderByComparator orderByComparator)
1718                    throws NoSuchLayoutException, SystemException {
1719                    int count = countByCompanyId(companyId);
1720    
1721                    List<Layout> list = findByCompanyId(companyId, count - 1, count,
1722                                    orderByComparator);
1723    
1724                    if (list.isEmpty()) {
1725                            StringBundler msg = new StringBundler(4);
1726    
1727                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1728    
1729                            msg.append("companyId=");
1730                            msg.append(companyId);
1731    
1732                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1733    
1734                            throw new NoSuchLayoutException(msg.toString());
1735                    }
1736                    else {
1737                            return list.get(0);
1738                    }
1739            }
1740    
1741            /**
1742             * Finds the layouts before and after the current layout in the ordered set where companyId = &#63;.
1743             *
1744             * <p>
1745             * 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.
1746             * </p>
1747             *
1748             * @param plid the primary key of the current layout
1749             * @param companyId the company id to search with
1750             * @param orderByComparator the comparator to order the set by
1751             * @return the previous, current, and next layout
1752             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
1753             * @throws SystemException if a system exception occurred
1754             */
1755            public Layout[] findByCompanyId_PrevAndNext(long plid, long companyId,
1756                    OrderByComparator orderByComparator)
1757                    throws NoSuchLayoutException, SystemException {
1758                    Layout layout = findByPrimaryKey(plid);
1759    
1760                    Session session = null;
1761    
1762                    try {
1763                            session = openSession();
1764    
1765                            Layout[] array = new LayoutImpl[3];
1766    
1767                            array[0] = getByCompanyId_PrevAndNext(session, layout, companyId,
1768                                            orderByComparator, true);
1769    
1770                            array[1] = layout;
1771    
1772                            array[2] = getByCompanyId_PrevAndNext(session, layout, companyId,
1773                                            orderByComparator, false);
1774    
1775                            return array;
1776                    }
1777                    catch (Exception e) {
1778                            throw processException(e);
1779                    }
1780                    finally {
1781                            closeSession(session);
1782                    }
1783            }
1784    
1785            protected Layout getByCompanyId_PrevAndNext(Session session, Layout layout,
1786                    long companyId, OrderByComparator orderByComparator, boolean previous) {
1787                    StringBundler query = null;
1788    
1789                    if (orderByComparator != null) {
1790                            query = new StringBundler(6 +
1791                                            (orderByComparator.getOrderByFields().length * 6));
1792                    }
1793                    else {
1794                            query = new StringBundler(3);
1795                    }
1796    
1797                    query.append(_SQL_SELECT_LAYOUT_WHERE);
1798    
1799                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1800    
1801                    if (orderByComparator != null) {
1802                            String[] orderByFields = orderByComparator.getOrderByFields();
1803    
1804                            if (orderByFields.length > 0) {
1805                                    query.append(WHERE_AND);
1806                            }
1807    
1808                            for (int i = 0; i < orderByFields.length; i++) {
1809                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1810                                    query.append(orderByFields[i]);
1811    
1812                                    if ((i + 1) < orderByFields.length) {
1813                                            if (orderByComparator.isAscending() ^ previous) {
1814                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1815                                            }
1816                                            else {
1817                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1818                                            }
1819                                    }
1820                                    else {
1821                                            if (orderByComparator.isAscending() ^ previous) {
1822                                                    query.append(WHERE_GREATER_THAN);
1823                                            }
1824                                            else {
1825                                                    query.append(WHERE_LESSER_THAN);
1826                                            }
1827                                    }
1828                            }
1829    
1830                            query.append(ORDER_BY_CLAUSE);
1831    
1832                            for (int i = 0; i < orderByFields.length; i++) {
1833                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1834                                    query.append(orderByFields[i]);
1835    
1836                                    if ((i + 1) < orderByFields.length) {
1837                                            if (orderByComparator.isAscending() ^ previous) {
1838                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1839                                            }
1840                                            else {
1841                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1842                                            }
1843                                    }
1844                                    else {
1845                                            if (orderByComparator.isAscending() ^ previous) {
1846                                                    query.append(ORDER_BY_ASC);
1847                                            }
1848                                            else {
1849                                                    query.append(ORDER_BY_DESC);
1850                                            }
1851                                    }
1852                            }
1853                    }
1854    
1855                    else {
1856                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
1857                    }
1858    
1859                    String sql = query.toString();
1860    
1861                    Query q = session.createQuery(sql);
1862    
1863                    q.setFirstResult(0);
1864                    q.setMaxResults(2);
1865    
1866                    QueryPos qPos = QueryPos.getInstance(q);
1867    
1868                    qPos.add(companyId);
1869    
1870                    if (orderByComparator != null) {
1871                            Object[] values = orderByComparator.getOrderByValues(layout);
1872    
1873                            for (Object value : values) {
1874                                    qPos.add(value);
1875                            }
1876                    }
1877    
1878                    List<Layout> list = q.list();
1879    
1880                    if (list.size() == 2) {
1881                            return list.get(1);
1882                    }
1883                    else {
1884                            return null;
1885                    }
1886            }
1887    
1888            /**
1889             * Finds the layout where dlFolderId = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutException} if it could not be found.
1890             *
1891             * @param dlFolderId the dl folder id to search with
1892             * @return the matching layout
1893             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
1894             * @throws SystemException if a system exception occurred
1895             */
1896            public Layout findByDLFolderId(long dlFolderId)
1897                    throws NoSuchLayoutException, SystemException {
1898                    Layout layout = fetchByDLFolderId(dlFolderId);
1899    
1900                    if (layout == null) {
1901                            StringBundler msg = new StringBundler(4);
1902    
1903                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1904    
1905                            msg.append("dlFolderId=");
1906                            msg.append(dlFolderId);
1907    
1908                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1909    
1910                            if (_log.isWarnEnabled()) {
1911                                    _log.warn(msg.toString());
1912                            }
1913    
1914                            throw new NoSuchLayoutException(msg.toString());
1915                    }
1916    
1917                    return layout;
1918            }
1919    
1920            /**
1921             * Finds the layout where dlFolderId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1922             *
1923             * @param dlFolderId the dl folder id to search with
1924             * @return the matching layout, or <code>null</code> if a matching layout could not be found
1925             * @throws SystemException if a system exception occurred
1926             */
1927            public Layout fetchByDLFolderId(long dlFolderId) throws SystemException {
1928                    return fetchByDLFolderId(dlFolderId, true);
1929            }
1930    
1931            /**
1932             * Finds the layout where dlFolderId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1933             *
1934             * @param dlFolderId the dl folder id to search with
1935             * @return the matching layout, or <code>null</code> if a matching layout could not be found
1936             * @throws SystemException if a system exception occurred
1937             */
1938            public Layout fetchByDLFolderId(long dlFolderId, boolean retrieveFromCache)
1939                    throws SystemException {
1940                    Object[] finderArgs = new Object[] { dlFolderId };
1941    
1942                    Object result = null;
1943    
1944                    if (retrieveFromCache) {
1945                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
1946                                            finderArgs, this);
1947                    }
1948    
1949                    if (result == null) {
1950                            Session session = null;
1951    
1952                            try {
1953                                    session = openSession();
1954    
1955                                    StringBundler query = new StringBundler(3);
1956    
1957                                    query.append(_SQL_SELECT_LAYOUT_WHERE);
1958    
1959                                    query.append(_FINDER_COLUMN_DLFOLDERID_DLFOLDERID_2);
1960    
1961                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
1962    
1963                                    String sql = query.toString();
1964    
1965                                    Query q = session.createQuery(sql);
1966    
1967                                    QueryPos qPos = QueryPos.getInstance(q);
1968    
1969                                    qPos.add(dlFolderId);
1970    
1971                                    List<Layout> list = q.list();
1972    
1973                                    result = list;
1974    
1975                                    Layout layout = null;
1976    
1977                                    if (list.isEmpty()) {
1978                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
1979                                                    finderArgs, list);
1980                                    }
1981                                    else {
1982                                            layout = list.get(0);
1983    
1984                                            cacheResult(layout);
1985    
1986                                            if ((layout.getDlFolderId() != dlFolderId)) {
1987                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
1988                                                            finderArgs, layout);
1989                                            }
1990                                    }
1991    
1992                                    return layout;
1993                            }
1994                            catch (Exception e) {
1995                                    throw processException(e);
1996                            }
1997                            finally {
1998                                    if (result == null) {
1999                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DLFOLDERID,
2000                                                    finderArgs, new ArrayList<Layout>());
2001                                    }
2002    
2003                                    closeSession(session);
2004                            }
2005                    }
2006                    else {
2007                            if (result instanceof List<?>) {
2008                                    return null;
2009                            }
2010                            else {
2011                                    return (Layout)result;
2012                            }
2013                    }
2014            }
2015    
2016            /**
2017             * Finds the layout where iconImageId = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutException} if it could not be found.
2018             *
2019             * @param iconImageId the icon image id to search with
2020             * @return the matching layout
2021             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2022             * @throws SystemException if a system exception occurred
2023             */
2024            public Layout findByIconImageId(long iconImageId)
2025                    throws NoSuchLayoutException, SystemException {
2026                    Layout layout = fetchByIconImageId(iconImageId);
2027    
2028                    if (layout == null) {
2029                            StringBundler msg = new StringBundler(4);
2030    
2031                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2032    
2033                            msg.append("iconImageId=");
2034                            msg.append(iconImageId);
2035    
2036                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2037    
2038                            if (_log.isWarnEnabled()) {
2039                                    _log.warn(msg.toString());
2040                            }
2041    
2042                            throw new NoSuchLayoutException(msg.toString());
2043                    }
2044    
2045                    return layout;
2046            }
2047    
2048            /**
2049             * Finds the layout where iconImageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2050             *
2051             * @param iconImageId the icon image id to search with
2052             * @return the matching layout, or <code>null</code> if a matching layout could not be found
2053             * @throws SystemException if a system exception occurred
2054             */
2055            public Layout fetchByIconImageId(long iconImageId)
2056                    throws SystemException {
2057                    return fetchByIconImageId(iconImageId, true);
2058            }
2059    
2060            /**
2061             * Finds the layout where iconImageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2062             *
2063             * @param iconImageId the icon image id to search with
2064             * @return the matching layout, or <code>null</code> if a matching layout could not be found
2065             * @throws SystemException if a system exception occurred
2066             */
2067            public Layout fetchByIconImageId(long iconImageId, boolean retrieveFromCache)
2068                    throws SystemException {
2069                    Object[] finderArgs = new Object[] { iconImageId };
2070    
2071                    Object result = null;
2072    
2073                    if (retrieveFromCache) {
2074                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2075                                            finderArgs, this);
2076                    }
2077    
2078                    if (result == null) {
2079                            Session session = null;
2080    
2081                            try {
2082                                    session = openSession();
2083    
2084                                    StringBundler query = new StringBundler(3);
2085    
2086                                    query.append(_SQL_SELECT_LAYOUT_WHERE);
2087    
2088                                    query.append(_FINDER_COLUMN_ICONIMAGEID_ICONIMAGEID_2);
2089    
2090                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
2091    
2092                                    String sql = query.toString();
2093    
2094                                    Query q = session.createQuery(sql);
2095    
2096                                    QueryPos qPos = QueryPos.getInstance(q);
2097    
2098                                    qPos.add(iconImageId);
2099    
2100                                    List<Layout> list = q.list();
2101    
2102                                    result = list;
2103    
2104                                    Layout layout = null;
2105    
2106                                    if (list.isEmpty()) {
2107                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2108                                                    finderArgs, list);
2109                                    }
2110                                    else {
2111                                            layout = list.get(0);
2112    
2113                                            cacheResult(layout);
2114    
2115                                            if ((layout.getIconImageId() != iconImageId)) {
2116                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2117                                                            finderArgs, layout);
2118                                            }
2119                                    }
2120    
2121                                    return layout;
2122                            }
2123                            catch (Exception e) {
2124                                    throw processException(e);
2125                            }
2126                            finally {
2127                                    if (result == null) {
2128                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONIMAGEID,
2129                                                    finderArgs, new ArrayList<Layout>());
2130                                    }
2131    
2132                                    closeSession(session);
2133                            }
2134                    }
2135                    else {
2136                            if (result instanceof List<?>) {
2137                                    return null;
2138                            }
2139                            else {
2140                                    return (Layout)result;
2141                            }
2142                    }
2143            }
2144    
2145            /**
2146             * Finds all the layouts where groupId = &#63; and privateLayout = &#63;.
2147             *
2148             * @param groupId the group id to search with
2149             * @param privateLayout the private layout to search with
2150             * @return the matching layouts
2151             * @throws SystemException if a system exception occurred
2152             */
2153            public List<Layout> findByG_P(long groupId, boolean privateLayout)
2154                    throws SystemException {
2155                    return findByG_P(groupId, privateLayout, QueryUtil.ALL_POS,
2156                            QueryUtil.ALL_POS, null);
2157            }
2158    
2159            /**
2160             * Finds a range of all the layouts where groupId = &#63; and privateLayout = &#63;.
2161             *
2162             * <p>
2163             * 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.
2164             * </p>
2165             *
2166             * @param groupId the group id to search with
2167             * @param privateLayout the private layout to search with
2168             * @param start the lower bound of the range of layouts to return
2169             * @param end the upper bound of the range of layouts to return (not inclusive)
2170             * @return the range of matching layouts
2171             * @throws SystemException if a system exception occurred
2172             */
2173            public List<Layout> findByG_P(long groupId, boolean privateLayout,
2174                    int start, int end) throws SystemException {
2175                    return findByG_P(groupId, privateLayout, start, end, null);
2176            }
2177    
2178            /**
2179             * Finds an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63;.
2180             *
2181             * <p>
2182             * 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.
2183             * </p>
2184             *
2185             * @param groupId the group id to search with
2186             * @param privateLayout the private layout to search with
2187             * @param start the lower bound of the range of layouts to return
2188             * @param end the upper bound of the range of layouts to return (not inclusive)
2189             * @param orderByComparator the comparator to order the results by
2190             * @return the ordered range of matching layouts
2191             * @throws SystemException if a system exception occurred
2192             */
2193            public List<Layout> findByG_P(long groupId, boolean privateLayout,
2194                    int start, int end, OrderByComparator orderByComparator)
2195                    throws SystemException {
2196                    Object[] finderArgs = new Object[] {
2197                                    groupId, privateLayout,
2198                                    
2199                                    String.valueOf(start), String.valueOf(end),
2200                                    String.valueOf(orderByComparator)
2201                            };
2202    
2203                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
2204                                    finderArgs, this);
2205    
2206                    if (list == null) {
2207                            Session session = null;
2208    
2209                            try {
2210                                    session = openSession();
2211    
2212                                    StringBundler query = null;
2213    
2214                                    if (orderByComparator != null) {
2215                                            query = new StringBundler(4 +
2216                                                            (orderByComparator.getOrderByFields().length * 3));
2217                                    }
2218                                    else {
2219                                            query = new StringBundler(4);
2220                                    }
2221    
2222                                    query.append(_SQL_SELECT_LAYOUT_WHERE);
2223    
2224                                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2225    
2226                                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
2227    
2228                                    if (orderByComparator != null) {
2229                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2230                                                    orderByComparator);
2231                                    }
2232    
2233                                    else {
2234                                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
2235                                    }
2236    
2237                                    String sql = query.toString();
2238    
2239                                    Query q = session.createQuery(sql);
2240    
2241                                    QueryPos qPos = QueryPos.getInstance(q);
2242    
2243                                    qPos.add(groupId);
2244    
2245                                    qPos.add(privateLayout);
2246    
2247                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
2248                            }
2249                            catch (Exception e) {
2250                                    throw processException(e);
2251                            }
2252                            finally {
2253                                    if (list == null) {
2254                                            list = new ArrayList<Layout>();
2255                                    }
2256    
2257                                    cacheResult(list);
2258    
2259                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P, finderArgs,
2260                                            list);
2261    
2262                                    closeSession(session);
2263                            }
2264                    }
2265    
2266                    return list;
2267            }
2268    
2269            /**
2270             * Finds the first layout in the ordered set where groupId = &#63; and privateLayout = &#63;.
2271             *
2272             * <p>
2273             * 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.
2274             * </p>
2275             *
2276             * @param groupId the group id to search with
2277             * @param privateLayout the private layout to search with
2278             * @param orderByComparator the comparator to order the set by
2279             * @return the first matching layout
2280             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2281             * @throws SystemException if a system exception occurred
2282             */
2283            public Layout findByG_P_First(long groupId, boolean privateLayout,
2284                    OrderByComparator orderByComparator)
2285                    throws NoSuchLayoutException, SystemException {
2286                    List<Layout> list = findByG_P(groupId, privateLayout, 0, 1,
2287                                    orderByComparator);
2288    
2289                    if (list.isEmpty()) {
2290                            StringBundler msg = new StringBundler(6);
2291    
2292                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2293    
2294                            msg.append("groupId=");
2295                            msg.append(groupId);
2296    
2297                            msg.append(", privateLayout=");
2298                            msg.append(privateLayout);
2299    
2300                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2301    
2302                            throw new NoSuchLayoutException(msg.toString());
2303                    }
2304                    else {
2305                            return list.get(0);
2306                    }
2307            }
2308    
2309            /**
2310             * Finds the last layout in the ordered set where groupId = &#63; and privateLayout = &#63;.
2311             *
2312             * <p>
2313             * 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.
2314             * </p>
2315             *
2316             * @param groupId the group id to search with
2317             * @param privateLayout the private layout to search with
2318             * @param orderByComparator the comparator to order the set by
2319             * @return the last matching layout
2320             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2321             * @throws SystemException if a system exception occurred
2322             */
2323            public Layout findByG_P_Last(long groupId, boolean privateLayout,
2324                    OrderByComparator orderByComparator)
2325                    throws NoSuchLayoutException, SystemException {
2326                    int count = countByG_P(groupId, privateLayout);
2327    
2328                    List<Layout> list = findByG_P(groupId, privateLayout, count - 1, count,
2329                                    orderByComparator);
2330    
2331                    if (list.isEmpty()) {
2332                            StringBundler msg = new StringBundler(6);
2333    
2334                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2335    
2336                            msg.append("groupId=");
2337                            msg.append(groupId);
2338    
2339                            msg.append(", privateLayout=");
2340                            msg.append(privateLayout);
2341    
2342                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2343    
2344                            throw new NoSuchLayoutException(msg.toString());
2345                    }
2346                    else {
2347                            return list.get(0);
2348                    }
2349            }
2350    
2351            /**
2352             * Finds the layouts before and after the current layout in the ordered set where groupId = &#63; and privateLayout = &#63;.
2353             *
2354             * <p>
2355             * 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.
2356             * </p>
2357             *
2358             * @param plid the primary key of the current layout
2359             * @param groupId the group id to search with
2360             * @param privateLayout the private layout to search with
2361             * @param orderByComparator the comparator to order the set by
2362             * @return the previous, current, and next layout
2363             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
2364             * @throws SystemException if a system exception occurred
2365             */
2366            public Layout[] findByG_P_PrevAndNext(long plid, long groupId,
2367                    boolean privateLayout, OrderByComparator orderByComparator)
2368                    throws NoSuchLayoutException, SystemException {
2369                    Layout layout = findByPrimaryKey(plid);
2370    
2371                    Session session = null;
2372    
2373                    try {
2374                            session = openSession();
2375    
2376                            Layout[] array = new LayoutImpl[3];
2377    
2378                            array[0] = getByG_P_PrevAndNext(session, layout, groupId,
2379                                            privateLayout, orderByComparator, true);
2380    
2381                            array[1] = layout;
2382    
2383                            array[2] = getByG_P_PrevAndNext(session, layout, groupId,
2384                                            privateLayout, orderByComparator, false);
2385    
2386                            return array;
2387                    }
2388                    catch (Exception e) {
2389                            throw processException(e);
2390                    }
2391                    finally {
2392                            closeSession(session);
2393                    }
2394            }
2395    
2396            protected Layout getByG_P_PrevAndNext(Session session, Layout layout,
2397                    long groupId, boolean privateLayout,
2398                    OrderByComparator orderByComparator, boolean previous) {
2399                    StringBundler query = null;
2400    
2401                    if (orderByComparator != null) {
2402                            query = new StringBundler(6 +
2403                                            (orderByComparator.getOrderByFields().length * 6));
2404                    }
2405                    else {
2406                            query = new StringBundler(3);
2407                    }
2408    
2409                    query.append(_SQL_SELECT_LAYOUT_WHERE);
2410    
2411                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2412    
2413                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
2414    
2415                    if (orderByComparator != null) {
2416                            String[] orderByFields = orderByComparator.getOrderByFields();
2417    
2418                            if (orderByFields.length > 0) {
2419                                    query.append(WHERE_AND);
2420                            }
2421    
2422                            for (int i = 0; i < orderByFields.length; i++) {
2423                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2424                                    query.append(orderByFields[i]);
2425    
2426                                    if ((i + 1) < orderByFields.length) {
2427                                            if (orderByComparator.isAscending() ^ previous) {
2428                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2429                                            }
2430                                            else {
2431                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2432                                            }
2433                                    }
2434                                    else {
2435                                            if (orderByComparator.isAscending() ^ previous) {
2436                                                    query.append(WHERE_GREATER_THAN);
2437                                            }
2438                                            else {
2439                                                    query.append(WHERE_LESSER_THAN);
2440                                            }
2441                                    }
2442                            }
2443    
2444                            query.append(ORDER_BY_CLAUSE);
2445    
2446                            for (int i = 0; i < orderByFields.length; i++) {
2447                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2448                                    query.append(orderByFields[i]);
2449    
2450                                    if ((i + 1) < orderByFields.length) {
2451                                            if (orderByComparator.isAscending() ^ previous) {
2452                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2453                                            }
2454                                            else {
2455                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2456                                            }
2457                                    }
2458                                    else {
2459                                            if (orderByComparator.isAscending() ^ previous) {
2460                                                    query.append(ORDER_BY_ASC);
2461                                            }
2462                                            else {
2463                                                    query.append(ORDER_BY_DESC);
2464                                            }
2465                                    }
2466                            }
2467                    }
2468    
2469                    else {
2470                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
2471                    }
2472    
2473                    String sql = query.toString();
2474    
2475                    Query q = session.createQuery(sql);
2476    
2477                    q.setFirstResult(0);
2478                    q.setMaxResults(2);
2479    
2480                    QueryPos qPos = QueryPos.getInstance(q);
2481    
2482                    qPos.add(groupId);
2483    
2484                    qPos.add(privateLayout);
2485    
2486                    if (orderByComparator != null) {
2487                            Object[] values = orderByComparator.getOrderByValues(layout);
2488    
2489                            for (Object value : values) {
2490                                    qPos.add(value);
2491                            }
2492                    }
2493    
2494                    List<Layout> list = q.list();
2495    
2496                    if (list.size() == 2) {
2497                            return list.get(1);
2498                    }
2499                    else {
2500                            return null;
2501                    }
2502            }
2503    
2504            /**
2505             * Finds 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.
2506             *
2507             * @param groupId the group id to search with
2508             * @param privateLayout the private layout to search with
2509             * @param layoutId the layout id to search with
2510             * @return the matching layout
2511             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2512             * @throws SystemException if a system exception occurred
2513             */
2514            public Layout findByG_P_L(long groupId, boolean privateLayout, long layoutId)
2515                    throws NoSuchLayoutException, SystemException {
2516                    Layout layout = fetchByG_P_L(groupId, privateLayout, layoutId);
2517    
2518                    if (layout == null) {
2519                            StringBundler msg = new StringBundler(8);
2520    
2521                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2522    
2523                            msg.append("groupId=");
2524                            msg.append(groupId);
2525    
2526                            msg.append(", privateLayout=");
2527                            msg.append(privateLayout);
2528    
2529                            msg.append(", layoutId=");
2530                            msg.append(layoutId);
2531    
2532                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2533    
2534                            if (_log.isWarnEnabled()) {
2535                                    _log.warn(msg.toString());
2536                            }
2537    
2538                            throw new NoSuchLayoutException(msg.toString());
2539                    }
2540    
2541                    return layout;
2542            }
2543    
2544            /**
2545             * Finds 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.
2546             *
2547             * @param groupId the group id to search with
2548             * @param privateLayout the private layout to search with
2549             * @param layoutId the layout id to search with
2550             * @return the matching layout, or <code>null</code> if a matching layout could not be found
2551             * @throws SystemException if a system exception occurred
2552             */
2553            public Layout fetchByG_P_L(long groupId, boolean privateLayout,
2554                    long layoutId) throws SystemException {
2555                    return fetchByG_P_L(groupId, privateLayout, layoutId, true);
2556            }
2557    
2558            /**
2559             * Finds 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.
2560             *
2561             * @param groupId the group id to search with
2562             * @param privateLayout the private layout to search with
2563             * @param layoutId the layout id to search with
2564             * @return the matching layout, or <code>null</code> if a matching layout could not be found
2565             * @throws SystemException if a system exception occurred
2566             */
2567            public Layout fetchByG_P_L(long groupId, boolean privateLayout,
2568                    long layoutId, boolean retrieveFromCache) throws SystemException {
2569                    Object[] finderArgs = new Object[] { groupId, privateLayout, layoutId };
2570    
2571                    Object result = null;
2572    
2573                    if (retrieveFromCache) {
2574                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_L,
2575                                            finderArgs, this);
2576                    }
2577    
2578                    if (result == null) {
2579                            Session session = null;
2580    
2581                            try {
2582                                    session = openSession();
2583    
2584                                    StringBundler query = new StringBundler(5);
2585    
2586                                    query.append(_SQL_SELECT_LAYOUT_WHERE);
2587    
2588                                    query.append(_FINDER_COLUMN_G_P_L_GROUPID_2);
2589    
2590                                    query.append(_FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2);
2591    
2592                                    query.append(_FINDER_COLUMN_G_P_L_LAYOUTID_2);
2593    
2594                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
2595    
2596                                    String sql = query.toString();
2597    
2598                                    Query q = session.createQuery(sql);
2599    
2600                                    QueryPos qPos = QueryPos.getInstance(q);
2601    
2602                                    qPos.add(groupId);
2603    
2604                                    qPos.add(privateLayout);
2605    
2606                                    qPos.add(layoutId);
2607    
2608                                    List<Layout> list = q.list();
2609    
2610                                    result = list;
2611    
2612                                    Layout layout = null;
2613    
2614                                    if (list.isEmpty()) {
2615                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L,
2616                                                    finderArgs, list);
2617                                    }
2618                                    else {
2619                                            layout = list.get(0);
2620    
2621                                            cacheResult(layout);
2622    
2623                                            if ((layout.getGroupId() != groupId) ||
2624                                                            (layout.getPrivateLayout() != privateLayout) ||
2625                                                            (layout.getLayoutId() != layoutId)) {
2626                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L,
2627                                                            finderArgs, layout);
2628                                            }
2629                                    }
2630    
2631                                    return layout;
2632                            }
2633                            catch (Exception e) {
2634                                    throw processException(e);
2635                            }
2636                            finally {
2637                                    if (result == null) {
2638                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L,
2639                                                    finderArgs, new ArrayList<Layout>());
2640                                    }
2641    
2642                                    closeSession(session);
2643                            }
2644                    }
2645                    else {
2646                            if (result instanceof List<?>) {
2647                                    return null;
2648                            }
2649                            else {
2650                                    return (Layout)result;
2651                            }
2652                    }
2653            }
2654    
2655            /**
2656             * Finds all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
2657             *
2658             * @param groupId the group id to search with
2659             * @param privateLayout the private layout to search with
2660             * @param parentLayoutId the parent layout id to search with
2661             * @return the matching layouts
2662             * @throws SystemException if a system exception occurred
2663             */
2664            public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
2665                    long parentLayoutId) throws SystemException {
2666                    return findByG_P_P(groupId, privateLayout, parentLayoutId,
2667                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2668            }
2669    
2670            /**
2671             * Finds a range of all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
2672             *
2673             * <p>
2674             * 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.
2675             * </p>
2676             *
2677             * @param groupId the group id to search with
2678             * @param privateLayout the private layout to search with
2679             * @param parentLayoutId the parent layout id to search with
2680             * @param start the lower bound of the range of layouts to return
2681             * @param end the upper bound of the range of layouts to return (not inclusive)
2682             * @return the range of matching layouts
2683             * @throws SystemException if a system exception occurred
2684             */
2685            public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
2686                    long parentLayoutId, int start, int end) throws SystemException {
2687                    return findByG_P_P(groupId, privateLayout, parentLayoutId, start, end,
2688                            null);
2689            }
2690    
2691            /**
2692             * Finds an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
2693             *
2694             * <p>
2695             * 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.
2696             * </p>
2697             *
2698             * @param groupId the group id to search with
2699             * @param privateLayout the private layout to search with
2700             * @param parentLayoutId the parent layout id to search with
2701             * @param start the lower bound of the range of layouts to return
2702             * @param end the upper bound of the range of layouts to return (not inclusive)
2703             * @param orderByComparator the comparator to order the results by
2704             * @return the ordered range of matching layouts
2705             * @throws SystemException if a system exception occurred
2706             */
2707            public List<Layout> findByG_P_P(long groupId, boolean privateLayout,
2708                    long parentLayoutId, int start, int end,
2709                    OrderByComparator orderByComparator) throws SystemException {
2710                    Object[] finderArgs = new Object[] {
2711                                    groupId, privateLayout, parentLayoutId,
2712                                    
2713                                    String.valueOf(start), String.valueOf(end),
2714                                    String.valueOf(orderByComparator)
2715                            };
2716    
2717                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P_P,
2718                                    finderArgs, this);
2719    
2720                    if (list == null) {
2721                            Session session = null;
2722    
2723                            try {
2724                                    session = openSession();
2725    
2726                                    StringBundler query = null;
2727    
2728                                    if (orderByComparator != null) {
2729                                            query = new StringBundler(5 +
2730                                                            (orderByComparator.getOrderByFields().length * 3));
2731                                    }
2732                                    else {
2733                                            query = new StringBundler(5);
2734                                    }
2735    
2736                                    query.append(_SQL_SELECT_LAYOUT_WHERE);
2737    
2738                                    query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
2739    
2740                                    query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
2741    
2742                                    query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
2743    
2744                                    if (orderByComparator != null) {
2745                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2746                                                    orderByComparator);
2747                                    }
2748    
2749                                    else {
2750                                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
2751                                    }
2752    
2753                                    String sql = query.toString();
2754    
2755                                    Query q = session.createQuery(sql);
2756    
2757                                    QueryPos qPos = QueryPos.getInstance(q);
2758    
2759                                    qPos.add(groupId);
2760    
2761                                    qPos.add(privateLayout);
2762    
2763                                    qPos.add(parentLayoutId);
2764    
2765                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
2766                            }
2767                            catch (Exception e) {
2768                                    throw processException(e);
2769                            }
2770                            finally {
2771                                    if (list == null) {
2772                                            list = new ArrayList<Layout>();
2773                                    }
2774    
2775                                    cacheResult(list);
2776    
2777                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P_P,
2778                                            finderArgs, list);
2779    
2780                                    closeSession(session);
2781                            }
2782                    }
2783    
2784                    return list;
2785            }
2786    
2787            /**
2788             * Finds the first layout in the ordered set where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
2789             *
2790             * <p>
2791             * 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.
2792             * </p>
2793             *
2794             * @param groupId the group id to search with
2795             * @param privateLayout the private layout to search with
2796             * @param parentLayoutId the parent layout id to search with
2797             * @param orderByComparator the comparator to order the set by
2798             * @return the first matching layout
2799             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2800             * @throws SystemException if a system exception occurred
2801             */
2802            public Layout findByG_P_P_First(long groupId, boolean privateLayout,
2803                    long parentLayoutId, OrderByComparator orderByComparator)
2804                    throws NoSuchLayoutException, SystemException {
2805                    List<Layout> list = findByG_P_P(groupId, privateLayout, parentLayoutId,
2806                                    0, 1, orderByComparator);
2807    
2808                    if (list.isEmpty()) {
2809                            StringBundler msg = new StringBundler(8);
2810    
2811                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2812    
2813                            msg.append("groupId=");
2814                            msg.append(groupId);
2815    
2816                            msg.append(", privateLayout=");
2817                            msg.append(privateLayout);
2818    
2819                            msg.append(", parentLayoutId=");
2820                            msg.append(parentLayoutId);
2821    
2822                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2823    
2824                            throw new NoSuchLayoutException(msg.toString());
2825                    }
2826                    else {
2827                            return list.get(0);
2828                    }
2829            }
2830    
2831            /**
2832             * Finds the last layout in the ordered set where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
2833             *
2834             * <p>
2835             * 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.
2836             * </p>
2837             *
2838             * @param groupId the group id to search with
2839             * @param privateLayout the private layout to search with
2840             * @param parentLayoutId the parent layout id to search with
2841             * @param orderByComparator the comparator to order the set by
2842             * @return the last matching layout
2843             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
2844             * @throws SystemException if a system exception occurred
2845             */
2846            public Layout findByG_P_P_Last(long groupId, boolean privateLayout,
2847                    long parentLayoutId, OrderByComparator orderByComparator)
2848                    throws NoSuchLayoutException, SystemException {
2849                    int count = countByG_P_P(groupId, privateLayout, parentLayoutId);
2850    
2851                    List<Layout> list = findByG_P_P(groupId, privateLayout, parentLayoutId,
2852                                    count - 1, count, orderByComparator);
2853    
2854                    if (list.isEmpty()) {
2855                            StringBundler msg = new StringBundler(8);
2856    
2857                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2858    
2859                            msg.append("groupId=");
2860                            msg.append(groupId);
2861    
2862                            msg.append(", privateLayout=");
2863                            msg.append(privateLayout);
2864    
2865                            msg.append(", parentLayoutId=");
2866                            msg.append(parentLayoutId);
2867    
2868                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2869    
2870                            throw new NoSuchLayoutException(msg.toString());
2871                    }
2872                    else {
2873                            return list.get(0);
2874                    }
2875            }
2876    
2877            /**
2878             * Finds the layouts before and after the current layout in the ordered set where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
2879             *
2880             * <p>
2881             * 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.
2882             * </p>
2883             *
2884             * @param plid the primary key of the current layout
2885             * @param groupId the group id to search with
2886             * @param privateLayout the private layout to search with
2887             * @param parentLayoutId the parent layout id to search with
2888             * @param orderByComparator the comparator to order the set by
2889             * @return the previous, current, and next layout
2890             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
2891             * @throws SystemException if a system exception occurred
2892             */
2893            public Layout[] findByG_P_P_PrevAndNext(long plid, long groupId,
2894                    boolean privateLayout, long parentLayoutId,
2895                    OrderByComparator orderByComparator)
2896                    throws NoSuchLayoutException, SystemException {
2897                    Layout layout = findByPrimaryKey(plid);
2898    
2899                    Session session = null;
2900    
2901                    try {
2902                            session = openSession();
2903    
2904                            Layout[] array = new LayoutImpl[3];
2905    
2906                            array[0] = getByG_P_P_PrevAndNext(session, layout, groupId,
2907                                            privateLayout, parentLayoutId, orderByComparator, true);
2908    
2909                            array[1] = layout;
2910    
2911                            array[2] = getByG_P_P_PrevAndNext(session, layout, groupId,
2912                                            privateLayout, parentLayoutId, orderByComparator, false);
2913    
2914                            return array;
2915                    }
2916                    catch (Exception e) {
2917                            throw processException(e);
2918                    }
2919                    finally {
2920                            closeSession(session);
2921                    }
2922            }
2923    
2924            protected Layout getByG_P_P_PrevAndNext(Session session, Layout layout,
2925                    long groupId, boolean privateLayout, long parentLayoutId,
2926                    OrderByComparator orderByComparator, boolean previous) {
2927                    StringBundler query = null;
2928    
2929                    if (orderByComparator != null) {
2930                            query = new StringBundler(6 +
2931                                            (orderByComparator.getOrderByFields().length * 6));
2932                    }
2933                    else {
2934                            query = new StringBundler(3);
2935                    }
2936    
2937                    query.append(_SQL_SELECT_LAYOUT_WHERE);
2938    
2939                    query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
2940    
2941                    query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
2942    
2943                    query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
2944    
2945                    if (orderByComparator != null) {
2946                            String[] orderByFields = orderByComparator.getOrderByFields();
2947    
2948                            if (orderByFields.length > 0) {
2949                                    query.append(WHERE_AND);
2950                            }
2951    
2952                            for (int i = 0; i < orderByFields.length; i++) {
2953                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2954                                    query.append(orderByFields[i]);
2955    
2956                                    if ((i + 1) < orderByFields.length) {
2957                                            if (orderByComparator.isAscending() ^ previous) {
2958                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2959                                            }
2960                                            else {
2961                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2962                                            }
2963                                    }
2964                                    else {
2965                                            if (orderByComparator.isAscending() ^ previous) {
2966                                                    query.append(WHERE_GREATER_THAN);
2967                                            }
2968                                            else {
2969                                                    query.append(WHERE_LESSER_THAN);
2970                                            }
2971                                    }
2972                            }
2973    
2974                            query.append(ORDER_BY_CLAUSE);
2975    
2976                            for (int i = 0; i < orderByFields.length; i++) {
2977                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2978                                    query.append(orderByFields[i]);
2979    
2980                                    if ((i + 1) < orderByFields.length) {
2981                                            if (orderByComparator.isAscending() ^ previous) {
2982                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2983                                            }
2984                                            else {
2985                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2986                                            }
2987                                    }
2988                                    else {
2989                                            if (orderByComparator.isAscending() ^ previous) {
2990                                                    query.append(ORDER_BY_ASC);
2991                                            }
2992                                            else {
2993                                                    query.append(ORDER_BY_DESC);
2994                                            }
2995                                    }
2996                            }
2997                    }
2998    
2999                    else {
3000                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
3001                    }
3002    
3003                    String sql = query.toString();
3004    
3005                    Query q = session.createQuery(sql);
3006    
3007                    q.setFirstResult(0);
3008                    q.setMaxResults(2);
3009    
3010                    QueryPos qPos = QueryPos.getInstance(q);
3011    
3012                    qPos.add(groupId);
3013    
3014                    qPos.add(privateLayout);
3015    
3016                    qPos.add(parentLayoutId);
3017    
3018                    if (orderByComparator != null) {
3019                            Object[] values = orderByComparator.getOrderByValues(layout);
3020    
3021                            for (Object value : values) {
3022                                    qPos.add(value);
3023                            }
3024                    }
3025    
3026                    List<Layout> list = q.list();
3027    
3028                    if (list.size() == 2) {
3029                            return list.get(1);
3030                    }
3031                    else {
3032                            return null;
3033                    }
3034            }
3035    
3036            /**
3037             * Finds 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.
3038             *
3039             * @param groupId the group id to search with
3040             * @param privateLayout the private layout to search with
3041             * @param friendlyURL the friendly u r l to search with
3042             * @return the matching layout
3043             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
3044             * @throws SystemException if a system exception occurred
3045             */
3046            public Layout findByG_P_F(long groupId, boolean privateLayout,
3047                    String friendlyURL) throws NoSuchLayoutException, SystemException {
3048                    Layout layout = fetchByG_P_F(groupId, privateLayout, friendlyURL);
3049    
3050                    if (layout == null) {
3051                            StringBundler msg = new StringBundler(8);
3052    
3053                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3054    
3055                            msg.append("groupId=");
3056                            msg.append(groupId);
3057    
3058                            msg.append(", privateLayout=");
3059                            msg.append(privateLayout);
3060    
3061                            msg.append(", friendlyURL=");
3062                            msg.append(friendlyURL);
3063    
3064                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3065    
3066                            if (_log.isWarnEnabled()) {
3067                                    _log.warn(msg.toString());
3068                            }
3069    
3070                            throw new NoSuchLayoutException(msg.toString());
3071                    }
3072    
3073                    return layout;
3074            }
3075    
3076            /**
3077             * Finds 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.
3078             *
3079             * @param groupId the group id to search with
3080             * @param privateLayout the private layout to search with
3081             * @param friendlyURL the friendly u r l to search with
3082             * @return the matching layout, or <code>null</code> if a matching layout could not be found
3083             * @throws SystemException if a system exception occurred
3084             */
3085            public Layout fetchByG_P_F(long groupId, boolean privateLayout,
3086                    String friendlyURL) throws SystemException {
3087                    return fetchByG_P_F(groupId, privateLayout, friendlyURL, true);
3088            }
3089    
3090            /**
3091             * Finds 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.
3092             *
3093             * @param groupId the group id to search with
3094             * @param privateLayout the private layout to search with
3095             * @param friendlyURL the friendly u r l to search with
3096             * @return the matching layout, or <code>null</code> if a matching layout could not be found
3097             * @throws SystemException if a system exception occurred
3098             */
3099            public Layout fetchByG_P_F(long groupId, boolean privateLayout,
3100                    String friendlyURL, boolean retrieveFromCache)
3101                    throws SystemException {
3102                    Object[] finderArgs = new Object[] { groupId, privateLayout, friendlyURL };
3103    
3104                    Object result = null;
3105    
3106                    if (retrieveFromCache) {
3107                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_F,
3108                                            finderArgs, this);
3109                    }
3110    
3111                    if (result == null) {
3112                            Session session = null;
3113    
3114                            try {
3115                                    session = openSession();
3116    
3117                                    StringBundler query = new StringBundler(5);
3118    
3119                                    query.append(_SQL_SELECT_LAYOUT_WHERE);
3120    
3121                                    query.append(_FINDER_COLUMN_G_P_F_GROUPID_2);
3122    
3123                                    query.append(_FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2);
3124    
3125                                    if (friendlyURL == null) {
3126                                            query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_1);
3127                                    }
3128                                    else {
3129                                            if (friendlyURL.equals(StringPool.BLANK)) {
3130                                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_3);
3131                                            }
3132                                            else {
3133                                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_2);
3134                                            }
3135                                    }
3136    
3137                                    query.append(LayoutModelImpl.ORDER_BY_JPQL);
3138    
3139                                    String sql = query.toString();
3140    
3141                                    Query q = session.createQuery(sql);
3142    
3143                                    QueryPos qPos = QueryPos.getInstance(q);
3144    
3145                                    qPos.add(groupId);
3146    
3147                                    qPos.add(privateLayout);
3148    
3149                                    if (friendlyURL != null) {
3150                                            qPos.add(friendlyURL);
3151                                    }
3152    
3153                                    List<Layout> list = q.list();
3154    
3155                                    result = list;
3156    
3157                                    Layout layout = null;
3158    
3159                                    if (list.isEmpty()) {
3160                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_F,
3161                                                    finderArgs, list);
3162                                    }
3163                                    else {
3164                                            layout = list.get(0);
3165    
3166                                            cacheResult(layout);
3167    
3168                                            if ((layout.getGroupId() != groupId) ||
3169                                                            (layout.getPrivateLayout() != privateLayout) ||
3170                                                            (layout.getFriendlyURL() == null) ||
3171                                                            !layout.getFriendlyURL().equals(friendlyURL)) {
3172                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_F,
3173                                                            finderArgs, layout);
3174                                            }
3175                                    }
3176    
3177                                    return layout;
3178                            }
3179                            catch (Exception e) {
3180                                    throw processException(e);
3181                            }
3182                            finally {
3183                                    if (result == null) {
3184                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_F,
3185                                                    finderArgs, new ArrayList<Layout>());
3186                                    }
3187    
3188                                    closeSession(session);
3189                            }
3190                    }
3191                    else {
3192                            if (result instanceof List<?>) {
3193                                    return null;
3194                            }
3195                            else {
3196                                    return (Layout)result;
3197                            }
3198                    }
3199            }
3200    
3201            /**
3202             * Finds all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
3203             *
3204             * @param groupId the group id to search with
3205             * @param privateLayout the private layout to search with
3206             * @param type the type to search with
3207             * @return the matching layouts
3208             * @throws SystemException if a system exception occurred
3209             */
3210            public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
3211                    String type) throws SystemException {
3212                    return findByG_P_T(groupId, privateLayout, type, QueryUtil.ALL_POS,
3213                            QueryUtil.ALL_POS, null);
3214            }
3215    
3216            /**
3217             * Finds a range of all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
3218             *
3219             * <p>
3220             * 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.
3221             * </p>
3222             *
3223             * @param groupId the group id to search with
3224             * @param privateLayout the private layout to search with
3225             * @param type the type to search with
3226             * @param start the lower bound of the range of layouts to return
3227             * @param end the upper bound of the range of layouts to return (not inclusive)
3228             * @return the range of matching layouts
3229             * @throws SystemException if a system exception occurred
3230             */
3231            public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
3232                    String type, int start, int end) throws SystemException {
3233                    return findByG_P_T(groupId, privateLayout, type, start, end, null);
3234            }
3235    
3236            /**
3237             * Finds an ordered range of all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
3238             *
3239             * <p>
3240             * 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.
3241             * </p>
3242             *
3243             * @param groupId the group id to search with
3244             * @param privateLayout the private layout to search with
3245             * @param type the type to search with
3246             * @param start the lower bound of the range of layouts to return
3247             * @param end the upper bound of the range of layouts to return (not inclusive)
3248             * @param orderByComparator the comparator to order the results by
3249             * @return the ordered range of matching layouts
3250             * @throws SystemException if a system exception occurred
3251             */
3252            public List<Layout> findByG_P_T(long groupId, boolean privateLayout,
3253                    String type, int start, int end, OrderByComparator orderByComparator)
3254                    throws SystemException {
3255                    Object[] finderArgs = new Object[] {
3256                                    groupId, privateLayout, type,
3257                                    
3258                                    String.valueOf(start), String.valueOf(end),
3259                                    String.valueOf(orderByComparator)
3260                            };
3261    
3262                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P_T,
3263                                    finderArgs, this);
3264    
3265                    if (list == null) {
3266                            Session session = null;
3267    
3268                            try {
3269                                    session = openSession();
3270    
3271                                    StringBundler query = null;
3272    
3273                                    if (orderByComparator != null) {
3274                                            query = new StringBundler(5 +
3275                                                            (orderByComparator.getOrderByFields().length * 3));
3276                                    }
3277                                    else {
3278                                            query = new StringBundler(5);
3279                                    }
3280    
3281                                    query.append(_SQL_SELECT_LAYOUT_WHERE);
3282    
3283                                    query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
3284    
3285                                    query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
3286    
3287                                    if (type == null) {
3288                                            query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
3289                                    }
3290                                    else {
3291                                            if (type.equals(StringPool.BLANK)) {
3292                                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
3293                                            }
3294                                            else {
3295                                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
3296                                            }
3297                                    }
3298    
3299                                    if (orderByComparator != null) {
3300                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3301                                                    orderByComparator);
3302                                    }
3303    
3304                                    else {
3305                                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
3306                                    }
3307    
3308                                    String sql = query.toString();
3309    
3310                                    Query q = session.createQuery(sql);
3311    
3312                                    QueryPos qPos = QueryPos.getInstance(q);
3313    
3314                                    qPos.add(groupId);
3315    
3316                                    qPos.add(privateLayout);
3317    
3318                                    if (type != null) {
3319                                            qPos.add(type);
3320                                    }
3321    
3322                                    list = (List<Layout>)QueryUtil.list(q, getDialect(), start, end);
3323                            }
3324                            catch (Exception e) {
3325                                    throw processException(e);
3326                            }
3327                            finally {
3328                                    if (list == null) {
3329                                            list = new ArrayList<Layout>();
3330                                    }
3331    
3332                                    cacheResult(list);
3333    
3334                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P_T,
3335                                            finderArgs, list);
3336    
3337                                    closeSession(session);
3338                            }
3339                    }
3340    
3341                    return list;
3342            }
3343    
3344            /**
3345             * Finds the first layout in the ordered set where groupId = &#63; and privateLayout = &#63; and type = &#63;.
3346             *
3347             * <p>
3348             * 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.
3349             * </p>
3350             *
3351             * @param groupId the group id to search with
3352             * @param privateLayout the private layout to search with
3353             * @param type the type to search with
3354             * @param orderByComparator the comparator to order the set by
3355             * @return the first matching layout
3356             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
3357             * @throws SystemException if a system exception occurred
3358             */
3359            public Layout findByG_P_T_First(long groupId, boolean privateLayout,
3360                    String type, OrderByComparator orderByComparator)
3361                    throws NoSuchLayoutException, SystemException {
3362                    List<Layout> list = findByG_P_T(groupId, privateLayout, type, 0, 1,
3363                                    orderByComparator);
3364    
3365                    if (list.isEmpty()) {
3366                            StringBundler msg = new StringBundler(8);
3367    
3368                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3369    
3370                            msg.append("groupId=");
3371                            msg.append(groupId);
3372    
3373                            msg.append(", privateLayout=");
3374                            msg.append(privateLayout);
3375    
3376                            msg.append(", type=");
3377                            msg.append(type);
3378    
3379                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3380    
3381                            throw new NoSuchLayoutException(msg.toString());
3382                    }
3383                    else {
3384                            return list.get(0);
3385                    }
3386            }
3387    
3388            /**
3389             * Finds the last layout in the ordered set where groupId = &#63; and privateLayout = &#63; and type = &#63;.
3390             *
3391             * <p>
3392             * 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.
3393             * </p>
3394             *
3395             * @param groupId the group id to search with
3396             * @param privateLayout the private layout to search with
3397             * @param type the type to search with
3398             * @param orderByComparator the comparator to order the set by
3399             * @return the last matching layout
3400             * @throws com.liferay.portal.NoSuchLayoutException if a matching layout could not be found
3401             * @throws SystemException if a system exception occurred
3402             */
3403            public Layout findByG_P_T_Last(long groupId, boolean privateLayout,
3404                    String type, OrderByComparator orderByComparator)
3405                    throws NoSuchLayoutException, SystemException {
3406                    int count = countByG_P_T(groupId, privateLayout, type);
3407    
3408                    List<Layout> list = findByG_P_T(groupId, privateLayout, type,
3409                                    count - 1, count, orderByComparator);
3410    
3411                    if (list.isEmpty()) {
3412                            StringBundler msg = new StringBundler(8);
3413    
3414                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3415    
3416                            msg.append("groupId=");
3417                            msg.append(groupId);
3418    
3419                            msg.append(", privateLayout=");
3420                            msg.append(privateLayout);
3421    
3422                            msg.append(", type=");
3423                            msg.append(type);
3424    
3425                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3426    
3427                            throw new NoSuchLayoutException(msg.toString());
3428                    }
3429                    else {
3430                            return list.get(0);
3431                    }
3432            }
3433    
3434            /**
3435             * Finds the layouts before and after the current layout in the ordered set where groupId = &#63; and privateLayout = &#63; and type = &#63;.
3436             *
3437             * <p>
3438             * 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.
3439             * </p>
3440             *
3441             * @param plid the primary key of the current layout
3442             * @param groupId the group id to search with
3443             * @param privateLayout the private layout to search with
3444             * @param type the type to search with
3445             * @param orderByComparator the comparator to order the set by
3446             * @return the previous, current, and next layout
3447             * @throws com.liferay.portal.NoSuchLayoutException if a layout with the primary key could not be found
3448             * @throws SystemException if a system exception occurred
3449             */
3450            public Layout[] findByG_P_T_PrevAndNext(long plid, long groupId,
3451                    boolean privateLayout, String type, OrderByComparator orderByComparator)
3452                    throws NoSuchLayoutException, SystemException {
3453                    Layout layout = findByPrimaryKey(plid);
3454    
3455                    Session session = null;
3456    
3457                    try {
3458                            session = openSession();
3459    
3460                            Layout[] array = new LayoutImpl[3];
3461    
3462                            array[0] = getByG_P_T_PrevAndNext(session, layout, groupId,
3463                                            privateLayout, type, orderByComparator, true);
3464    
3465                            array[1] = layout;
3466    
3467                            array[2] = getByG_P_T_PrevAndNext(session, layout, groupId,
3468                                            privateLayout, type, orderByComparator, false);
3469    
3470                            return array;
3471                    }
3472                    catch (Exception e) {
3473                            throw processException(e);
3474                    }
3475                    finally {
3476                            closeSession(session);
3477                    }
3478            }
3479    
3480            protected Layout getByG_P_T_PrevAndNext(Session session, Layout layout,
3481                    long groupId, boolean privateLayout, String type,
3482                    OrderByComparator orderByComparator, boolean previous) {
3483                    StringBundler query = null;
3484    
3485                    if (orderByComparator != null) {
3486                            query = new StringBundler(6 +
3487                                            (orderByComparator.getOrderByFields().length * 6));
3488                    }
3489                    else {
3490                            query = new StringBundler(3);
3491                    }
3492    
3493                    query.append(_SQL_SELECT_LAYOUT_WHERE);
3494    
3495                    query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
3496    
3497                    query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
3498    
3499                    if (type == null) {
3500                            query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
3501                    }
3502                    else {
3503                            if (type.equals(StringPool.BLANK)) {
3504                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
3505                            }
3506                            else {
3507                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
3508                            }
3509                    }
3510    
3511                    if (orderByComparator != null) {
3512                            String[] orderByFields = orderByComparator.getOrderByFields();
3513    
3514                            if (orderByFields.length > 0) {
3515                                    query.append(WHERE_AND);
3516                            }
3517    
3518                            for (int i = 0; i < orderByFields.length; i++) {
3519                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3520                                    query.append(orderByFields[i]);
3521    
3522                                    if ((i + 1) < orderByFields.length) {
3523                                            if (orderByComparator.isAscending() ^ previous) {
3524                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3525                                            }
3526                                            else {
3527                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3528                                            }
3529                                    }
3530                                    else {
3531                                            if (orderByComparator.isAscending() ^ previous) {
3532                                                    query.append(WHERE_GREATER_THAN);
3533                                            }
3534                                            else {
3535                                                    query.append(WHERE_LESSER_THAN);
3536                                            }
3537                                    }
3538                            }
3539    
3540                            query.append(ORDER_BY_CLAUSE);
3541    
3542                            for (int i = 0; i < orderByFields.length; i++) {
3543                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3544                                    query.append(orderByFields[i]);
3545    
3546                                    if ((i + 1) < orderByFields.length) {
3547                                            if (orderByComparator.isAscending() ^ previous) {
3548                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3549                                            }
3550                                            else {
3551                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3552                                            }
3553                                    }
3554                                    else {
3555                                            if (orderByComparator.isAscending() ^ previous) {
3556                                                    query.append(ORDER_BY_ASC);
3557                                            }
3558                                            else {
3559                                                    query.append(ORDER_BY_DESC);
3560                                            }
3561                                    }
3562                            }
3563                    }
3564    
3565                    else {
3566                            query.append(LayoutModelImpl.ORDER_BY_JPQL);
3567                    }
3568    
3569                    String sql = query.toString();
3570    
3571                    Query q = session.createQuery(sql);
3572    
3573                    q.setFirstResult(0);
3574                    q.setMaxResults(2);
3575    
3576                    QueryPos qPos = QueryPos.getInstance(q);
3577    
3578                    qPos.add(groupId);
3579    
3580                    qPos.add(privateLayout);
3581    
3582                    if (type != null) {
3583                            qPos.add(type);
3584                    }
3585    
3586                    if (orderByComparator != null) {
3587                            Object[] values = orderByComparator.getOrderByValues(layout);
3588    
3589                            for (Object value : values) {
3590                                    qPos.add(value);
3591                            }
3592                    }
3593    
3594                    List<Layout> list = q.list();
3595    
3596                    if (list.size() == 2) {
3597                            return list.get(1);
3598                    }
3599                    else {
3600                            return null;
3601                    }
3602            }
3603    
3604            /**
3605             * Finds all the layouts.
3606             *
3607             * @return the layouts
3608             * @throws SystemException if a system exception occurred
3609             */
3610            public List<Layout> findAll() throws SystemException {
3611                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3612            }
3613    
3614            /**
3615             * Finds a range of all the layouts.
3616             *
3617             * <p>
3618             * 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.
3619             * </p>
3620             *
3621             * @param start the lower bound of the range of layouts to return
3622             * @param end the upper bound of the range of layouts to return (not inclusive)
3623             * @return the range of layouts
3624             * @throws SystemException if a system exception occurred
3625             */
3626            public List<Layout> findAll(int start, int end) throws SystemException {
3627                    return findAll(start, end, null);
3628            }
3629    
3630            /**
3631             * Finds an ordered range of all the layouts.
3632             *
3633             * <p>
3634             * 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.
3635             * </p>
3636             *
3637             * @param start the lower bound of the range of layouts to return
3638             * @param end the upper bound of the range of layouts to return (not inclusive)
3639             * @param orderByComparator the comparator to order the results by
3640             * @return the ordered range of layouts
3641             * @throws SystemException if a system exception occurred
3642             */
3643            public List<Layout> findAll(int start, int end,
3644                    OrderByComparator orderByComparator) throws SystemException {
3645                    Object[] finderArgs = new Object[] {
3646                                    String.valueOf(start), String.valueOf(end),
3647                                    String.valueOf(orderByComparator)
3648                            };
3649    
3650                    List<Layout> list = (List<Layout>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
3651                                    finderArgs, this);
3652    
3653                    if (list == null) {
3654                            Session session = null;
3655    
3656                            try {
3657                                    session = openSession();
3658    
3659                                    StringBundler query = null;
3660                                    String sql = null;
3661    
3662                                    if (orderByComparator != null) {
3663                                            query = new StringBundler(2 +
3664                                                            (orderByComparator.getOrderByFields().length * 3));
3665    
3666                                            query.append(_SQL_SELECT_LAYOUT);
3667    
3668                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3669                                                    orderByComparator);
3670    
3671                                            sql = query.toString();
3672                                    }
3673                                    else {
3674                                            sql = _SQL_SELECT_LAYOUT.concat(LayoutModelImpl.ORDER_BY_JPQL);
3675                                    }
3676    
3677                                    Query q = session.createQuery(sql);
3678    
3679                                    if (orderByComparator == null) {
3680                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
3681                                                            end, false);
3682    
3683                                            Collections.sort(list);
3684                                    }
3685                                    else {
3686                                            list = (List<Layout>)QueryUtil.list(q, getDialect(), start,
3687                                                            end);
3688                                    }
3689                            }
3690                            catch (Exception e) {
3691                                    throw processException(e);
3692                            }
3693                            finally {
3694                                    if (list == null) {
3695                                            list = new ArrayList<Layout>();
3696                                    }
3697    
3698                                    cacheResult(list);
3699    
3700                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
3701    
3702                                    closeSession(session);
3703                            }
3704                    }
3705    
3706                    return list;
3707            }
3708    
3709            /**
3710             * Removes all the layouts where uuid = &#63; from the database.
3711             *
3712             * @param uuid the uuid to search with
3713             * @throws SystemException if a system exception occurred
3714             */
3715            public void removeByUuid(String uuid) throws SystemException {
3716                    for (Layout layout : findByUuid(uuid)) {
3717                            remove(layout);
3718                    }
3719            }
3720    
3721            /**
3722             * Removes the layout where uuid = &#63; and groupId = &#63; from the database.
3723             *
3724             * @param uuid the uuid to search with
3725             * @param groupId the group id to search with
3726             * @throws SystemException if a system exception occurred
3727             */
3728            public void removeByUUID_G(String uuid, long groupId)
3729                    throws NoSuchLayoutException, SystemException {
3730                    Layout layout = findByUUID_G(uuid, groupId);
3731    
3732                    remove(layout);
3733            }
3734    
3735            /**
3736             * Removes all the layouts where groupId = &#63; from the database.
3737             *
3738             * @param groupId the group id to search with
3739             * @throws SystemException if a system exception occurred
3740             */
3741            public void removeByGroupId(long groupId) throws SystemException {
3742                    for (Layout layout : findByGroupId(groupId)) {
3743                            remove(layout);
3744                    }
3745            }
3746    
3747            /**
3748             * Removes all the layouts where companyId = &#63; from the database.
3749             *
3750             * @param companyId the company id to search with
3751             * @throws SystemException if a system exception occurred
3752             */
3753            public void removeByCompanyId(long companyId) throws SystemException {
3754                    for (Layout layout : findByCompanyId(companyId)) {
3755                            remove(layout);
3756                    }
3757            }
3758    
3759            /**
3760             * Removes the layout where dlFolderId = &#63; from the database.
3761             *
3762             * @param dlFolderId the dl folder id to search with
3763             * @throws SystemException if a system exception occurred
3764             */
3765            public void removeByDLFolderId(long dlFolderId)
3766                    throws NoSuchLayoutException, SystemException {
3767                    Layout layout = findByDLFolderId(dlFolderId);
3768    
3769                    remove(layout);
3770            }
3771    
3772            /**
3773             * Removes the layout where iconImageId = &#63; from the database.
3774             *
3775             * @param iconImageId the icon image id to search with
3776             * @throws SystemException if a system exception occurred
3777             */
3778            public void removeByIconImageId(long iconImageId)
3779                    throws NoSuchLayoutException, SystemException {
3780                    Layout layout = findByIconImageId(iconImageId);
3781    
3782                    remove(layout);
3783            }
3784    
3785            /**
3786             * Removes all the layouts where groupId = &#63; and privateLayout = &#63; from the database.
3787             *
3788             * @param groupId the group id to search with
3789             * @param privateLayout the private layout to search with
3790             * @throws SystemException if a system exception occurred
3791             */
3792            public void removeByG_P(long groupId, boolean privateLayout)
3793                    throws SystemException {
3794                    for (Layout layout : findByG_P(groupId, privateLayout)) {
3795                            remove(layout);
3796                    }
3797            }
3798    
3799            /**
3800             * Removes the layout where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; from the database.
3801             *
3802             * @param groupId the group id to search with
3803             * @param privateLayout the private layout to search with
3804             * @param layoutId the layout id to search with
3805             * @throws SystemException if a system exception occurred
3806             */
3807            public void removeByG_P_L(long groupId, boolean privateLayout, long layoutId)
3808                    throws NoSuchLayoutException, SystemException {
3809                    Layout layout = findByG_P_L(groupId, privateLayout, layoutId);
3810    
3811                    remove(layout);
3812            }
3813    
3814            /**
3815             * Removes all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63; from the database.
3816             *
3817             * @param groupId the group id to search with
3818             * @param privateLayout the private layout to search with
3819             * @param parentLayoutId the parent layout id to search with
3820             * @throws SystemException if a system exception occurred
3821             */
3822            public void removeByG_P_P(long groupId, boolean privateLayout,
3823                    long parentLayoutId) throws SystemException {
3824                    for (Layout layout : findByG_P_P(groupId, privateLayout, parentLayoutId)) {
3825                            remove(layout);
3826                    }
3827            }
3828    
3829            /**
3830             * Removes the layout where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63; from the database.
3831             *
3832             * @param groupId the group id to search with
3833             * @param privateLayout the private layout to search with
3834             * @param friendlyURL the friendly u r l to search with
3835             * @throws SystemException if a system exception occurred
3836             */
3837            public void removeByG_P_F(long groupId, boolean privateLayout,
3838                    String friendlyURL) throws NoSuchLayoutException, SystemException {
3839                    Layout layout = findByG_P_F(groupId, privateLayout, friendlyURL);
3840    
3841                    remove(layout);
3842            }
3843    
3844            /**
3845             * Removes all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63; from the database.
3846             *
3847             * @param groupId the group id to search with
3848             * @param privateLayout the private layout to search with
3849             * @param type the type to search with
3850             * @throws SystemException if a system exception occurred
3851             */
3852            public void removeByG_P_T(long groupId, boolean privateLayout, String type)
3853                    throws SystemException {
3854                    for (Layout layout : findByG_P_T(groupId, privateLayout, type)) {
3855                            remove(layout);
3856                    }
3857            }
3858    
3859            /**
3860             * Removes all the layouts from the database.
3861             *
3862             * @throws SystemException if a system exception occurred
3863             */
3864            public void removeAll() throws SystemException {
3865                    for (Layout layout : findAll()) {
3866                            remove(layout);
3867                    }
3868            }
3869    
3870            /**
3871             * Counts all the layouts where uuid = &#63;.
3872             *
3873             * @param uuid the uuid to search with
3874             * @return the number of matching layouts
3875             * @throws SystemException if a system exception occurred
3876             */
3877            public int countByUuid(String uuid) throws SystemException {
3878                    Object[] finderArgs = new Object[] { uuid };
3879    
3880                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
3881                                    finderArgs, this);
3882    
3883                    if (count == null) {
3884                            Session session = null;
3885    
3886                            try {
3887                                    session = openSession();
3888    
3889                                    StringBundler query = new StringBundler(2);
3890    
3891                                    query.append(_SQL_COUNT_LAYOUT_WHERE);
3892    
3893                                    if (uuid == null) {
3894                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
3895                                    }
3896                                    else {
3897                                            if (uuid.equals(StringPool.BLANK)) {
3898                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
3899                                            }
3900                                            else {
3901                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
3902                                            }
3903                                    }
3904    
3905                                    String sql = query.toString();
3906    
3907                                    Query q = session.createQuery(sql);
3908    
3909                                    QueryPos qPos = QueryPos.getInstance(q);
3910    
3911                                    if (uuid != null) {
3912                                            qPos.add(uuid);
3913                                    }
3914    
3915                                    count = (Long)q.uniqueResult();
3916                            }
3917                            catch (Exception e) {
3918                                    throw processException(e);
3919                            }
3920                            finally {
3921                                    if (count == null) {
3922                                            count = Long.valueOf(0);
3923                                    }
3924    
3925                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
3926                                            finderArgs, count);
3927    
3928                                    closeSession(session);
3929                            }
3930                    }
3931    
3932                    return count.intValue();
3933            }
3934    
3935            /**
3936             * Counts all the layouts where uuid = &#63; and groupId = &#63;.
3937             *
3938             * @param uuid the uuid to search with
3939             * @param groupId the group id to search with
3940             * @return the number of matching layouts
3941             * @throws SystemException if a system exception occurred
3942             */
3943            public int countByUUID_G(String uuid, long groupId)
3944                    throws SystemException {
3945                    Object[] finderArgs = new Object[] { uuid, groupId };
3946    
3947                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
3948                                    finderArgs, this);
3949    
3950                    if (count == null) {
3951                            Session session = null;
3952    
3953                            try {
3954                                    session = openSession();
3955    
3956                                    StringBundler query = new StringBundler(3);
3957    
3958                                    query.append(_SQL_COUNT_LAYOUT_WHERE);
3959    
3960                                    if (uuid == null) {
3961                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
3962                                    }
3963                                    else {
3964                                            if (uuid.equals(StringPool.BLANK)) {
3965                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
3966                                            }
3967                                            else {
3968                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
3969                                            }
3970                                    }
3971    
3972                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
3973    
3974                                    String sql = query.toString();
3975    
3976                                    Query q = session.createQuery(sql);
3977    
3978                                    QueryPos qPos = QueryPos.getInstance(q);
3979    
3980                                    if (uuid != null) {
3981                                            qPos.add(uuid);
3982                                    }
3983    
3984                                    qPos.add(groupId);
3985    
3986                                    count = (Long)q.uniqueResult();
3987                            }
3988                            catch (Exception e) {
3989                                    throw processException(e);
3990                            }
3991                            finally {
3992                                    if (count == null) {
3993                                            count = Long.valueOf(0);
3994                                    }
3995    
3996                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
3997                                            finderArgs, count);
3998    
3999                                    closeSession(session);
4000                            }
4001                    }
4002    
4003                    return count.intValue();
4004            }
4005    
4006            /**
4007             * Counts all the layouts where groupId = &#63;.
4008             *
4009             * @param groupId the group id to search with
4010             * @return the number of matching layouts
4011             * @throws SystemException if a system exception occurred
4012             */
4013            public int countByGroupId(long groupId) throws SystemException {
4014                    Object[] finderArgs = new Object[] { groupId };
4015    
4016                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
4017                                    finderArgs, this);
4018    
4019                    if (count == null) {
4020                            Session session = null;
4021    
4022                            try {
4023                                    session = openSession();
4024    
4025                                    StringBundler query = new StringBundler(2);
4026    
4027                                    query.append(_SQL_COUNT_LAYOUT_WHERE);
4028    
4029                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4030    
4031                                    String sql = query.toString();
4032    
4033                                    Query q = session.createQuery(sql);
4034    
4035                                    QueryPos qPos = QueryPos.getInstance(q);
4036    
4037                                    qPos.add(groupId);
4038    
4039                                    count = (Long)q.uniqueResult();
4040                            }
4041                            catch (Exception e) {
4042                                    throw processException(e);
4043                            }
4044                            finally {
4045                                    if (count == null) {
4046                                            count = Long.valueOf(0);
4047                                    }
4048    
4049                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
4050                                            finderArgs, count);
4051    
4052                                    closeSession(session);
4053                            }
4054                    }
4055    
4056                    return count.intValue();
4057            }
4058    
4059            /**
4060             * Counts all the layouts where companyId = &#63;.
4061             *
4062             * @param companyId the company id to search with
4063             * @return the number of matching layouts
4064             * @throws SystemException if a system exception occurred
4065             */
4066            public int countByCompanyId(long companyId) throws SystemException {
4067                    Object[] finderArgs = new Object[] { companyId };
4068    
4069                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
4070                                    finderArgs, this);
4071    
4072                    if (count == null) {
4073                            Session session = null;
4074    
4075                            try {
4076                                    session = openSession();
4077    
4078                                    StringBundler query = new StringBundler(2);
4079    
4080                                    query.append(_SQL_COUNT_LAYOUT_WHERE);
4081    
4082                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
4083    
4084                                    String sql = query.toString();
4085    
4086                                    Query q = session.createQuery(sql);
4087    
4088                                    QueryPos qPos = QueryPos.getInstance(q);
4089    
4090                                    qPos.add(companyId);
4091    
4092                                    count = (Long)q.uniqueResult();
4093                            }
4094                            catch (Exception e) {
4095                                    throw processException(e);
4096                            }
4097                            finally {
4098                                    if (count == null) {
4099                                            count = Long.valueOf(0);
4100                                    }
4101    
4102                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
4103                                            finderArgs, count);
4104    
4105                                    closeSession(session);
4106                            }
4107                    }
4108    
4109                    return count.intValue();
4110            }
4111    
4112            /**
4113             * Counts all the layouts where dlFolderId = &#63;.
4114             *
4115             * @param dlFolderId the dl folder id to search with
4116             * @return the number of matching layouts
4117             * @throws SystemException if a system exception occurred
4118             */
4119            public int countByDLFolderId(long dlFolderId) throws SystemException {
4120                    Object[] finderArgs = new Object[] { dlFolderId };
4121    
4122                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_DLFOLDERID,
4123                                    finderArgs, this);
4124    
4125                    if (count == null) {
4126                            Session session = null;
4127    
4128                            try {
4129                                    session = openSession();
4130    
4131                                    StringBundler query = new StringBundler(2);
4132    
4133                                    query.append(_SQL_COUNT_LAYOUT_WHERE);
4134    
4135                                    query.append(_FINDER_COLUMN_DLFOLDERID_DLFOLDERID_2);
4136    
4137                                    String sql = query.toString();
4138    
4139                                    Query q = session.createQuery(sql);
4140    
4141                                    QueryPos qPos = QueryPos.getInstance(q);
4142    
4143                                    qPos.add(dlFolderId);
4144    
4145                                    count = (Long)q.uniqueResult();
4146                            }
4147                            catch (Exception e) {
4148                                    throw processException(e);
4149                            }
4150                            finally {
4151                                    if (count == null) {
4152                                            count = Long.valueOf(0);
4153                                    }
4154    
4155                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_DLFOLDERID,
4156                                            finderArgs, count);
4157    
4158                                    closeSession(session);
4159                            }
4160                    }
4161    
4162                    return count.intValue();
4163            }
4164    
4165            /**
4166             * Counts all the layouts where iconImageId = &#63;.
4167             *
4168             * @param iconImageId the icon image id to search with
4169             * @return the number of matching layouts
4170             * @throws SystemException if a system exception occurred
4171             */
4172            public int countByIconImageId(long iconImageId) throws SystemException {
4173                    Object[] finderArgs = new Object[] { iconImageId };
4174    
4175                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ICONIMAGEID,
4176                                    finderArgs, this);
4177    
4178                    if (count == null) {
4179                            Session session = null;
4180    
4181                            try {
4182                                    session = openSession();
4183    
4184                                    StringBundler query = new StringBundler(2);
4185    
4186                                    query.append(_SQL_COUNT_LAYOUT_WHERE);
4187    
4188                                    query.append(_FINDER_COLUMN_ICONIMAGEID_ICONIMAGEID_2);
4189    
4190                                    String sql = query.toString();
4191    
4192                                    Query q = session.createQuery(sql);
4193    
4194                                    QueryPos qPos = QueryPos.getInstance(q);
4195    
4196                                    qPos.add(iconImageId);
4197    
4198                                    count = (Long)q.uniqueResult();
4199                            }
4200                            catch (Exception e) {
4201                                    throw processException(e);
4202                            }
4203                            finally {
4204                                    if (count == null) {
4205                                            count = Long.valueOf(0);
4206                                    }
4207    
4208                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ICONIMAGEID,
4209                                            finderArgs, count);
4210    
4211                                    closeSession(session);
4212                            }
4213                    }
4214    
4215                    return count.intValue();
4216            }
4217    
4218            /**
4219             * Counts all the layouts where groupId = &#63; and privateLayout = &#63;.
4220             *
4221             * @param groupId the group id to search with
4222             * @param privateLayout the private layout to search with
4223             * @return the number of matching layouts
4224             * @throws SystemException if a system exception occurred
4225             */
4226            public int countByG_P(long groupId, boolean privateLayout)
4227                    throws SystemException {
4228                    Object[] finderArgs = new Object[] { groupId, privateLayout };
4229    
4230                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
4231                                    finderArgs, this);
4232    
4233                    if (count == null) {
4234                            Session session = null;
4235    
4236                            try {
4237                                    session = openSession();
4238    
4239                                    StringBundler query = new StringBundler(3);
4240    
4241                                    query.append(_SQL_COUNT_LAYOUT_WHERE);
4242    
4243                                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4244    
4245                                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
4246    
4247                                    String sql = query.toString();
4248    
4249                                    Query q = session.createQuery(sql);
4250    
4251                                    QueryPos qPos = QueryPos.getInstance(q);
4252    
4253                                    qPos.add(groupId);
4254    
4255                                    qPos.add(privateLayout);
4256    
4257                                    count = (Long)q.uniqueResult();
4258                            }
4259                            catch (Exception e) {
4260                                    throw processException(e);
4261                            }
4262                            finally {
4263                                    if (count == null) {
4264                                            count = Long.valueOf(0);
4265                                    }
4266    
4267                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
4268                                            count);
4269    
4270                                    closeSession(session);
4271                            }
4272                    }
4273    
4274                    return count.intValue();
4275            }
4276    
4277            /**
4278             * Counts all the layouts where groupId = &#63; and privateLayout = &#63; and layoutId = &#63;.
4279             *
4280             * @param groupId the group id to search with
4281             * @param privateLayout the private layout to search with
4282             * @param layoutId the layout id to search with
4283             * @return the number of matching layouts
4284             * @throws SystemException if a system exception occurred
4285             */
4286            public int countByG_P_L(long groupId, boolean privateLayout, long layoutId)
4287                    throws SystemException {
4288                    Object[] finderArgs = new Object[] { groupId, privateLayout, layoutId };
4289    
4290                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_L,
4291                                    finderArgs, this);
4292    
4293                    if (count == null) {
4294                            Session session = null;
4295    
4296                            try {
4297                                    session = openSession();
4298    
4299                                    StringBundler query = new StringBundler(4);
4300    
4301                                    query.append(_SQL_COUNT_LAYOUT_WHERE);
4302    
4303                                    query.append(_FINDER_COLUMN_G_P_L_GROUPID_2);
4304    
4305                                    query.append(_FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2);
4306    
4307                                    query.append(_FINDER_COLUMN_G_P_L_LAYOUTID_2);
4308    
4309                                    String sql = query.toString();
4310    
4311                                    Query q = session.createQuery(sql);
4312    
4313                                    QueryPos qPos = QueryPos.getInstance(q);
4314    
4315                                    qPos.add(groupId);
4316    
4317                                    qPos.add(privateLayout);
4318    
4319                                    qPos.add(layoutId);
4320    
4321                                    count = (Long)q.uniqueResult();
4322                            }
4323                            catch (Exception e) {
4324                                    throw processException(e);
4325                            }
4326                            finally {
4327                                    if (count == null) {
4328                                            count = Long.valueOf(0);
4329                                    }
4330    
4331                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_L,
4332                                            finderArgs, count);
4333    
4334                                    closeSession(session);
4335                            }
4336                    }
4337    
4338                    return count.intValue();
4339            }
4340    
4341            /**
4342             * Counts all the layouts where groupId = &#63; and privateLayout = &#63; and parentLayoutId = &#63;.
4343             *
4344             * @param groupId the group id to search with
4345             * @param privateLayout the private layout to search with
4346             * @param parentLayoutId the parent layout id to search with
4347             * @return the number of matching layouts
4348             * @throws SystemException if a system exception occurred
4349             */
4350            public int countByG_P_P(long groupId, boolean privateLayout,
4351                    long parentLayoutId) throws SystemException {
4352                    Object[] finderArgs = new Object[] {
4353                                    groupId, privateLayout, parentLayoutId
4354                            };
4355    
4356                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_P,
4357                                    finderArgs, this);
4358    
4359                    if (count == null) {
4360                            Session session = null;
4361    
4362                            try {
4363                                    session = openSession();
4364    
4365                                    StringBundler query = new StringBundler(4);
4366    
4367                                    query.append(_SQL_COUNT_LAYOUT_WHERE);
4368    
4369                                    query.append(_FINDER_COLUMN_G_P_P_GROUPID_2);
4370    
4371                                    query.append(_FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2);
4372    
4373                                    query.append(_FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2);
4374    
4375                                    String sql = query.toString();
4376    
4377                                    Query q = session.createQuery(sql);
4378    
4379                                    QueryPos qPos = QueryPos.getInstance(q);
4380    
4381                                    qPos.add(groupId);
4382    
4383                                    qPos.add(privateLayout);
4384    
4385                                    qPos.add(parentLayoutId);
4386    
4387                                    count = (Long)q.uniqueResult();
4388                            }
4389                            catch (Exception e) {
4390                                    throw processException(e);
4391                            }
4392                            finally {
4393                                    if (count == null) {
4394                                            count = Long.valueOf(0);
4395                                    }
4396    
4397                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_P,
4398                                            finderArgs, count);
4399    
4400                                    closeSession(session);
4401                            }
4402                    }
4403    
4404                    return count.intValue();
4405            }
4406    
4407            /**
4408             * Counts all the layouts where groupId = &#63; and privateLayout = &#63; and friendlyURL = &#63;.
4409             *
4410             * @param groupId the group id to search with
4411             * @param privateLayout the private layout to search with
4412             * @param friendlyURL the friendly u r l to search with
4413             * @return the number of matching layouts
4414             * @throws SystemException if a system exception occurred
4415             */
4416            public int countByG_P_F(long groupId, boolean privateLayout,
4417                    String friendlyURL) throws SystemException {
4418                    Object[] finderArgs = new Object[] { groupId, privateLayout, friendlyURL };
4419    
4420                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_F,
4421                                    finderArgs, this);
4422    
4423                    if (count == null) {
4424                            Session session = null;
4425    
4426                            try {
4427                                    session = openSession();
4428    
4429                                    StringBundler query = new StringBundler(4);
4430    
4431                                    query.append(_SQL_COUNT_LAYOUT_WHERE);
4432    
4433                                    query.append(_FINDER_COLUMN_G_P_F_GROUPID_2);
4434    
4435                                    query.append(_FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2);
4436    
4437                                    if (friendlyURL == null) {
4438                                            query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_1);
4439                                    }
4440                                    else {
4441                                            if (friendlyURL.equals(StringPool.BLANK)) {
4442                                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_3);
4443                                            }
4444                                            else {
4445                                                    query.append(_FINDER_COLUMN_G_P_F_FRIENDLYURL_2);
4446                                            }
4447                                    }
4448    
4449                                    String sql = query.toString();
4450    
4451                                    Query q = session.createQuery(sql);
4452    
4453                                    QueryPos qPos = QueryPos.getInstance(q);
4454    
4455                                    qPos.add(groupId);
4456    
4457                                    qPos.add(privateLayout);
4458    
4459                                    if (friendlyURL != null) {
4460                                            qPos.add(friendlyURL);
4461                                    }
4462    
4463                                    count = (Long)q.uniqueResult();
4464                            }
4465                            catch (Exception e) {
4466                                    throw processException(e);
4467                            }
4468                            finally {
4469                                    if (count == null) {
4470                                            count = Long.valueOf(0);
4471                                    }
4472    
4473                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_F,
4474                                            finderArgs, count);
4475    
4476                                    closeSession(session);
4477                            }
4478                    }
4479    
4480                    return count.intValue();
4481            }
4482    
4483            /**
4484             * Counts all the layouts where groupId = &#63; and privateLayout = &#63; and type = &#63;.
4485             *
4486             * @param groupId the group id to search with
4487             * @param privateLayout the private layout to search with
4488             * @param type the type to search with
4489             * @return the number of matching layouts
4490             * @throws SystemException if a system exception occurred
4491             */
4492            public int countByG_P_T(long groupId, boolean privateLayout, String type)
4493                    throws SystemException {
4494                    Object[] finderArgs = new Object[] { groupId, privateLayout, type };
4495    
4496                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_T,
4497                                    finderArgs, this);
4498    
4499                    if (count == null) {
4500                            Session session = null;
4501    
4502                            try {
4503                                    session = openSession();
4504    
4505                                    StringBundler query = new StringBundler(4);
4506    
4507                                    query.append(_SQL_COUNT_LAYOUT_WHERE);
4508    
4509                                    query.append(_FINDER_COLUMN_G_P_T_GROUPID_2);
4510    
4511                                    query.append(_FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2);
4512    
4513                                    if (type == null) {
4514                                            query.append(_FINDER_COLUMN_G_P_T_TYPE_1);
4515                                    }
4516                                    else {
4517                                            if (type.equals(StringPool.BLANK)) {
4518                                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_3);
4519                                            }
4520                                            else {
4521                                                    query.append(_FINDER_COLUMN_G_P_T_TYPE_2);
4522                                            }
4523                                    }
4524    
4525                                    String sql = query.toString();
4526    
4527                                    Query q = session.createQuery(sql);
4528    
4529                                    QueryPos qPos = QueryPos.getInstance(q);
4530    
4531                                    qPos.add(groupId);
4532    
4533                                    qPos.add(privateLayout);
4534    
4535                                    if (type != null) {
4536                                            qPos.add(type);
4537                                    }
4538    
4539                                    count = (Long)q.uniqueResult();
4540                            }
4541                            catch (Exception e) {
4542                                    throw processException(e);
4543                            }
4544                            finally {
4545                                    if (count == null) {
4546                                            count = Long.valueOf(0);
4547                                    }
4548    
4549                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_T,
4550                                            finderArgs, count);
4551    
4552                                    closeSession(session);
4553                            }
4554                    }
4555    
4556                    return count.intValue();
4557            }
4558    
4559            /**
4560             * Counts all the layouts.
4561             *
4562             * @return the number of layouts
4563             * @throws SystemException if a system exception occurred
4564             */
4565            public int countAll() throws SystemException {
4566                    Object[] finderArgs = new Object[0];
4567    
4568                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4569                                    finderArgs, this);
4570    
4571                    if (count == null) {
4572                            Session session = null;
4573    
4574                            try {
4575                                    session = openSession();
4576    
4577                                    Query q = session.createQuery(_SQL_COUNT_LAYOUT);
4578    
4579                                    count = (Long)q.uniqueResult();
4580                            }
4581                            catch (Exception e) {
4582                                    throw processException(e);
4583                            }
4584                            finally {
4585                                    if (count == null) {
4586                                            count = Long.valueOf(0);
4587                                    }
4588    
4589                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
4590                                            count);
4591    
4592                                    closeSession(session);
4593                            }
4594                    }
4595    
4596                    return count.intValue();
4597            }
4598    
4599            /**
4600             * Initializes the layout persistence.
4601             */
4602            public void afterPropertiesSet() {
4603                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4604                                            com.liferay.portal.util.PropsUtil.get(
4605                                                    "value.object.listener.com.liferay.portal.model.Layout")));
4606    
4607                    if (listenerClassNames.length > 0) {
4608                            try {
4609                                    List<ModelListener<Layout>> listenersList = new ArrayList<ModelListener<Layout>>();
4610    
4611                                    for (String listenerClassName : listenerClassNames) {
4612                                            listenersList.add((ModelListener<Layout>)InstanceFactory.newInstance(
4613                                                            listenerClassName));
4614                                    }
4615    
4616                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4617                            }
4618                            catch (Exception e) {
4619                                    _log.error(e);
4620                            }
4621                    }
4622            }
4623    
4624            @BeanReference(type = AccountPersistence.class)
4625            protected AccountPersistence accountPersistence;
4626            @BeanReference(type = AddressPersistence.class)
4627            protected AddressPersistence addressPersistence;
4628            @BeanReference(type = BrowserTrackerPersistence.class)
4629            protected BrowserTrackerPersistence browserTrackerPersistence;
4630            @BeanReference(type = ClassNamePersistence.class)
4631            protected ClassNamePersistence classNamePersistence;
4632            @BeanReference(type = CompanyPersistence.class)
4633            protected CompanyPersistence companyPersistence;
4634            @BeanReference(type = ContactPersistence.class)
4635            protected ContactPersistence contactPersistence;
4636            @BeanReference(type = CountryPersistence.class)
4637            protected CountryPersistence countryPersistence;
4638            @BeanReference(type = EmailAddressPersistence.class)
4639            protected EmailAddressPersistence emailAddressPersistence;
4640            @BeanReference(type = GroupPersistence.class)
4641            protected GroupPersistence groupPersistence;
4642            @BeanReference(type = ImagePersistence.class)
4643            protected ImagePersistence imagePersistence;
4644            @BeanReference(type = LayoutPersistence.class)
4645            protected LayoutPersistence layoutPersistence;
4646            @BeanReference(type = LayoutPrototypePersistence.class)
4647            protected LayoutPrototypePersistence layoutPrototypePersistence;
4648            @BeanReference(type = LayoutSetPersistence.class)
4649            protected LayoutSetPersistence layoutSetPersistence;
4650            @BeanReference(type = LayoutSetPrototypePersistence.class)
4651            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
4652            @BeanReference(type = ListTypePersistence.class)
4653            protected ListTypePersistence listTypePersistence;
4654            @BeanReference(type = LockPersistence.class)
4655            protected LockPersistence lockPersistence;
4656            @BeanReference(type = MembershipRequestPersistence.class)
4657            protected MembershipRequestPersistence membershipRequestPersistence;
4658            @BeanReference(type = OrganizationPersistence.class)
4659            protected OrganizationPersistence organizationPersistence;
4660            @BeanReference(type = OrgGroupPermissionPersistence.class)
4661            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
4662            @BeanReference(type = OrgGroupRolePersistence.class)
4663            protected OrgGroupRolePersistence orgGroupRolePersistence;
4664            @BeanReference(type = OrgLaborPersistence.class)
4665            protected OrgLaborPersistence orgLaborPersistence;
4666            @BeanReference(type = PasswordPolicyPersistence.class)
4667            protected PasswordPolicyPersistence passwordPolicyPersistence;
4668            @BeanReference(type = PasswordPolicyRelPersistence.class)
4669            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
4670            @BeanReference(type = PasswordTrackerPersistence.class)
4671            protected PasswordTrackerPersistence passwordTrackerPersistence;
4672            @BeanReference(type = PermissionPersistence.class)
4673            protected PermissionPersistence permissionPersistence;
4674            @BeanReference(type = PhonePersistence.class)
4675            protected PhonePersistence phonePersistence;
4676            @BeanReference(type = PluginSettingPersistence.class)
4677            protected PluginSettingPersistence pluginSettingPersistence;
4678            @BeanReference(type = PortletPersistence.class)
4679            protected PortletPersistence portletPersistence;
4680            @BeanReference(type = PortletItemPersistence.class)
4681            protected PortletItemPersistence portletItemPersistence;
4682            @BeanReference(type = PortletPreferencesPersistence.class)
4683            protected PortletPreferencesPersistence portletPreferencesPersistence;
4684            @BeanReference(type = RegionPersistence.class)
4685            protected RegionPersistence regionPersistence;
4686            @BeanReference(type = ReleasePersistence.class)
4687            protected ReleasePersistence releasePersistence;
4688            @BeanReference(type = ResourcePersistence.class)
4689            protected ResourcePersistence resourcePersistence;
4690            @BeanReference(type = ResourceActionPersistence.class)
4691            protected ResourceActionPersistence resourceActionPersistence;
4692            @BeanReference(type = ResourceCodePersistence.class)
4693            protected ResourceCodePersistence resourceCodePersistence;
4694            @BeanReference(type = ResourcePermissionPersistence.class)
4695            protected ResourcePermissionPersistence resourcePermissionPersistence;
4696            @BeanReference(type = RolePersistence.class)
4697            protected RolePersistence rolePersistence;
4698            @BeanReference(type = ServiceComponentPersistence.class)
4699            protected ServiceComponentPersistence serviceComponentPersistence;
4700            @BeanReference(type = ShardPersistence.class)
4701            protected ShardPersistence shardPersistence;
4702            @BeanReference(type = SubscriptionPersistence.class)
4703            protected SubscriptionPersistence subscriptionPersistence;
4704            @BeanReference(type = TicketPersistence.class)
4705            protected TicketPersistence ticketPersistence;
4706            @BeanReference(type = TeamPersistence.class)
4707            protected TeamPersistence teamPersistence;
4708            @BeanReference(type = UserPersistence.class)
4709            protected UserPersistence userPersistence;
4710            @BeanReference(type = UserGroupPersistence.class)
4711            protected UserGroupPersistence userGroupPersistence;
4712            @BeanReference(type = UserGroupGroupRolePersistence.class)
4713            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
4714            @BeanReference(type = UserGroupRolePersistence.class)
4715            protected UserGroupRolePersistence userGroupRolePersistence;
4716            @BeanReference(type = UserIdMapperPersistence.class)
4717            protected UserIdMapperPersistence userIdMapperPersistence;
4718            @BeanReference(type = UserTrackerPersistence.class)
4719            protected UserTrackerPersistence userTrackerPersistence;
4720            @BeanReference(type = UserTrackerPathPersistence.class)
4721            protected UserTrackerPathPersistence userTrackerPathPersistence;
4722            @BeanReference(type = WebDAVPropsPersistence.class)
4723            protected WebDAVPropsPersistence webDAVPropsPersistence;
4724            @BeanReference(type = WebsitePersistence.class)
4725            protected WebsitePersistence websitePersistence;
4726            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
4727            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
4728            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
4729            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
4730            @BeanReference(type = DLFolderPersistence.class)
4731            protected DLFolderPersistence dlFolderPersistence;
4732            @BeanReference(type = ExpandoValuePersistence.class)
4733            protected ExpandoValuePersistence expandoValuePersistence;
4734            @BeanReference(type = JournalContentSearchPersistence.class)
4735            protected JournalContentSearchPersistence journalContentSearchPersistence;
4736            @BeanReference(type = MBMessagePersistence.class)
4737            protected MBMessagePersistence mbMessagePersistence;
4738            @BeanReference(type = RatingsStatsPersistence.class)
4739            protected RatingsStatsPersistence ratingsStatsPersistence;
4740            @BeanReference(type = TasksProposalPersistence.class)
4741            protected TasksProposalPersistence tasksProposalPersistence;
4742            private static final String _SQL_SELECT_LAYOUT = "SELECT layout FROM Layout layout";
4743            private static final String _SQL_SELECT_LAYOUT_WHERE = "SELECT layout FROM Layout layout WHERE ";
4744            private static final String _SQL_COUNT_LAYOUT = "SELECT COUNT(layout) FROM Layout layout";
4745            private static final String _SQL_COUNT_LAYOUT_WHERE = "SELECT COUNT(layout) FROM Layout layout WHERE ";
4746            private static final String _FINDER_COLUMN_UUID_UUID_1 = "layout.uuid IS NULL";
4747            private static final String _FINDER_COLUMN_UUID_UUID_2 = "layout.uuid = ?";
4748            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(layout.uuid IS NULL OR layout.uuid = ?)";
4749            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "layout.uuid IS NULL AND ";
4750            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "layout.uuid = ? AND ";
4751            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(layout.uuid IS NULL OR layout.uuid = ?) AND ";
4752            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "layout.groupId = ?";
4753            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "layout.groupId = ?";
4754            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "layout.companyId = ?";
4755            private static final String _FINDER_COLUMN_DLFOLDERID_DLFOLDERID_2 = "layout.dlFolderId = ?";
4756            private static final String _FINDER_COLUMN_ICONIMAGEID_ICONIMAGEID_2 = "layout.iconImageId = ?";
4757            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "layout.groupId = ? AND ";
4758            private static final String _FINDER_COLUMN_G_P_PRIVATELAYOUT_2 = "layout.privateLayout = ?";
4759            private static final String _FINDER_COLUMN_G_P_L_GROUPID_2 = "layout.groupId = ? AND ";
4760            private static final String _FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
4761            private static final String _FINDER_COLUMN_G_P_L_LAYOUTID_2 = "layout.layoutId = ?";
4762            private static final String _FINDER_COLUMN_G_P_P_GROUPID_2 = "layout.groupId = ? AND ";
4763            private static final String _FINDER_COLUMN_G_P_P_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
4764            private static final String _FINDER_COLUMN_G_P_P_PARENTLAYOUTID_2 = "layout.parentLayoutId = ?";
4765            private static final String _FINDER_COLUMN_G_P_F_GROUPID_2 = "layout.groupId = ? AND ";
4766            private static final String _FINDER_COLUMN_G_P_F_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
4767            private static final String _FINDER_COLUMN_G_P_F_FRIENDLYURL_1 = "layout.friendlyURL IS NULL";
4768            private static final String _FINDER_COLUMN_G_P_F_FRIENDLYURL_2 = "layout.friendlyURL = ?";
4769            private static final String _FINDER_COLUMN_G_P_F_FRIENDLYURL_3 = "(layout.friendlyURL IS NULL OR layout.friendlyURL = ?)";
4770            private static final String _FINDER_COLUMN_G_P_T_GROUPID_2 = "layout.groupId = ? AND ";
4771            private static final String _FINDER_COLUMN_G_P_T_PRIVATELAYOUT_2 = "layout.privateLayout = ? AND ";
4772            private static final String _FINDER_COLUMN_G_P_T_TYPE_1 = "layout.type IS NULL";
4773            private static final String _FINDER_COLUMN_G_P_T_TYPE_2 = "layout.type = ?";
4774            private static final String _FINDER_COLUMN_G_P_T_TYPE_3 = "(layout.type IS NULL OR layout.type = ?)";
4775            private static final String _ORDER_BY_ENTITY_ALIAS = "layout.";
4776            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Layout exists with the primary key ";
4777            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Layout exists with the key {";
4778            private static Log _log = LogFactoryUtil.getLog(LayoutPersistenceImpl.class);
4779    }