001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchLayoutSetException;
018    import com.liferay.portal.NoSuchModelException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.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.model.CacheModel;
039    import com.liferay.portal.model.LayoutSet;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.model.impl.LayoutSetImpl;
042    import com.liferay.portal.model.impl.LayoutSetModelImpl;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import java.io.Serializable;
046    
047    import java.util.ArrayList;
048    import java.util.Collections;
049    import java.util.List;
050    
051    /**
052     * The persistence implementation for the layout set service.
053     *
054     * <p>
055     * Caching information and settings can be found in <code>portal.properties</code>
056     * </p>
057     *
058     * @author Brian Wing Shun Chan
059     * @see LayoutSetPersistence
060     * @see LayoutSetUtil
061     * @generated
062     */
063    public class LayoutSetPersistenceImpl extends BasePersistenceImpl<LayoutSet>
064            implements LayoutSetPersistence {
065            /*
066             * NOTE FOR DEVELOPERS:
067             *
068             * Never modify or reference this class directly. Always use {@link LayoutSetUtil} to access the layout set persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
069             */
070            public static final String FINDER_CLASS_NAME_ENTITY = LayoutSetImpl.class.getName();
071            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List1";
073            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List2";
075            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
076                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, LayoutSetImpl.class,
077                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
078                            new String[] {
079                                    Long.class.getName(),
080                                    
081                            "java.lang.Integer", "java.lang.Integer",
082                                    "com.liferay.portal.kernel.util.OrderByComparator"
083                            });
084            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
085                    new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
086                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, LayoutSetImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
088                            new String[] { Long.class.getName() },
089                            LayoutSetModelImpl.GROUPID_COLUMN_BITMASK);
090            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
091                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, Long.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
093                            new String[] { Long.class.getName() });
094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID =
095                    new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
096                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, LayoutSetImpl.class,
097                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
098                            "findByLayoutSetPrototypeUuid",
099                            new String[] {
100                                    String.class.getName(),
101                                    
102                            "java.lang.Integer", "java.lang.Integer",
103                                    "com.liferay.portal.kernel.util.OrderByComparator"
104                            });
105            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID =
106                    new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
107                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, LayoutSetImpl.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
109                            "findByLayoutSetPrototypeUuid",
110                            new String[] { String.class.getName() },
111                            LayoutSetModelImpl.LAYOUTSETPROTOTYPEUUID_COLUMN_BITMASK);
112            public static final FinderPath FINDER_PATH_COUNT_BY_LAYOUTSETPROTOTYPEUUID = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
113                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, Long.class,
114                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
115                            "countByLayoutSetPrototypeUuid",
116                            new String[] { String.class.getName() });
117            public static final FinderPath FINDER_PATH_FETCH_BY_G_P = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
118                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, LayoutSetImpl.class,
119                            FINDER_CLASS_NAME_ENTITY, "fetchByG_P",
120                            new String[] { Long.class.getName(), Boolean.class.getName() },
121                            LayoutSetModelImpl.GROUPID_COLUMN_BITMASK |
122                            LayoutSetModelImpl.PRIVATELAYOUT_COLUMN_BITMASK);
123            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
124                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, Long.class,
125                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
126                            new String[] { Long.class.getName(), Boolean.class.getName() });
127            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
128                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, LayoutSetImpl.class,
129                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
130            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
131                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, LayoutSetImpl.class,
132                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
133            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
134                            LayoutSetModelImpl.FINDER_CACHE_ENABLED, Long.class,
135                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
136    
137            /**
138             * Caches the layout set in the entity cache if it is enabled.
139             *
140             * @param layoutSet the layout set
141             */
142            public void cacheResult(LayoutSet layoutSet) {
143                    EntityCacheUtil.putResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
144                            LayoutSetImpl.class, layoutSet.getPrimaryKey(), layoutSet);
145    
146                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
147                            new Object[] {
148                                    Long.valueOf(layoutSet.getGroupId()),
149                                    Boolean.valueOf(layoutSet.getPrivateLayout())
150                            }, layoutSet);
151    
152                    layoutSet.resetOriginalValues();
153            }
154    
155            /**
156             * Caches the layout sets in the entity cache if it is enabled.
157             *
158             * @param layoutSets the layout sets
159             */
160            public void cacheResult(List<LayoutSet> layoutSets) {
161                    for (LayoutSet layoutSet : layoutSets) {
162                            if (EntityCacheUtil.getResult(
163                                                    LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
164                                                    LayoutSetImpl.class, layoutSet.getPrimaryKey()) == null) {
165                                    cacheResult(layoutSet);
166                            }
167                            else {
168                                    layoutSet.resetOriginalValues();
169                            }
170                    }
171            }
172    
173            /**
174             * Clears the cache for all layout sets.
175             *
176             * <p>
177             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
178             * </p>
179             */
180            @Override
181            public void clearCache() {
182                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
183                            CacheRegistryUtil.clear(LayoutSetImpl.class.getName());
184                    }
185    
186                    EntityCacheUtil.clearCache(LayoutSetImpl.class.getName());
187    
188                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
189                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
190                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
191            }
192    
193            /**
194             * Clears the cache for the layout set.
195             *
196             * <p>
197             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
198             * </p>
199             */
200            @Override
201            public void clearCache(LayoutSet layoutSet) {
202                    EntityCacheUtil.removeResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
203                            LayoutSetImpl.class, layoutSet.getPrimaryKey());
204    
205                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
206                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
207    
208                    clearUniqueFindersCache(layoutSet);
209            }
210    
211            @Override
212            public void clearCache(List<LayoutSet> layoutSets) {
213                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
214                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
215    
216                    for (LayoutSet layoutSet : layoutSets) {
217                            EntityCacheUtil.removeResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
218                                    LayoutSetImpl.class, layoutSet.getPrimaryKey());
219    
220                            clearUniqueFindersCache(layoutSet);
221                    }
222            }
223    
224            protected void clearUniqueFindersCache(LayoutSet layoutSet) {
225                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P,
226                            new Object[] {
227                                    Long.valueOf(layoutSet.getGroupId()),
228                                    Boolean.valueOf(layoutSet.getPrivateLayout())
229                            });
230            }
231    
232            /**
233             * Creates a new layout set with the primary key. Does not add the layout set to the database.
234             *
235             * @param layoutSetId the primary key for the new layout set
236             * @return the new layout set
237             */
238            public LayoutSet create(long layoutSetId) {
239                    LayoutSet layoutSet = new LayoutSetImpl();
240    
241                    layoutSet.setNew(true);
242                    layoutSet.setPrimaryKey(layoutSetId);
243    
244                    return layoutSet;
245            }
246    
247            /**
248             * Removes the layout set with the primary key from the database. Also notifies the appropriate model listeners.
249             *
250             * @param layoutSetId the primary key of the layout set
251             * @return the layout set that was removed
252             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
253             * @throws SystemException if a system exception occurred
254             */
255            public LayoutSet remove(long layoutSetId)
256                    throws NoSuchLayoutSetException, SystemException {
257                    return remove(Long.valueOf(layoutSetId));
258            }
259    
260            /**
261             * Removes the layout set with the primary key from the database. Also notifies the appropriate model listeners.
262             *
263             * @param primaryKey the primary key of the layout set
264             * @return the layout set that was removed
265             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
266             * @throws SystemException if a system exception occurred
267             */
268            @Override
269            public LayoutSet remove(Serializable primaryKey)
270                    throws NoSuchLayoutSetException, SystemException {
271                    Session session = null;
272    
273                    try {
274                            session = openSession();
275    
276                            LayoutSet layoutSet = (LayoutSet)session.get(LayoutSetImpl.class,
277                                            primaryKey);
278    
279                            if (layoutSet == null) {
280                                    if (_log.isWarnEnabled()) {
281                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
282                                    }
283    
284                                    throw new NoSuchLayoutSetException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
285                                            primaryKey);
286                            }
287    
288                            return remove(layoutSet);
289                    }
290                    catch (NoSuchLayoutSetException nsee) {
291                            throw nsee;
292                    }
293                    catch (Exception e) {
294                            throw processException(e);
295                    }
296                    finally {
297                            closeSession(session);
298                    }
299            }
300    
301            @Override
302            protected LayoutSet removeImpl(LayoutSet layoutSet)
303                    throws SystemException {
304                    layoutSet = toUnwrappedModel(layoutSet);
305    
306                    Session session = null;
307    
308                    try {
309                            session = openSession();
310    
311                            BatchSessionUtil.delete(session, layoutSet);
312                    }
313                    catch (Exception e) {
314                            throw processException(e);
315                    }
316                    finally {
317                            closeSession(session);
318                    }
319    
320                    clearCache(layoutSet);
321    
322                    return layoutSet;
323            }
324    
325            @Override
326            public LayoutSet updateImpl(com.liferay.portal.model.LayoutSet layoutSet,
327                    boolean merge) throws SystemException {
328                    layoutSet = toUnwrappedModel(layoutSet);
329    
330                    boolean isNew = layoutSet.isNew();
331    
332                    LayoutSetModelImpl layoutSetModelImpl = (LayoutSetModelImpl)layoutSet;
333    
334                    Session session = null;
335    
336                    try {
337                            session = openSession();
338    
339                            BatchSessionUtil.update(session, layoutSet, merge);
340    
341                            layoutSet.setNew(false);
342                    }
343                    catch (Exception e) {
344                            throw processException(e);
345                    }
346                    finally {
347                            closeSession(session);
348                    }
349    
350                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
351    
352                    if (isNew || !LayoutSetModelImpl.COLUMN_BITMASK_ENABLED) {
353                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
354                    }
355                    else {
356                            if ((layoutSetModelImpl.getColumnBitmask() &
357                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
358                                    Object[] args = new Object[] {
359                                                    Long.valueOf(layoutSetModelImpl.getOriginalGroupId())
360                                            };
361    
362                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
363                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
364                                            args);
365    
366                                    args = new Object[] {
367                                                    Long.valueOf(layoutSetModelImpl.getGroupId())
368                                            };
369    
370                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
371                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
372                                            args);
373                            }
374    
375                            if ((layoutSetModelImpl.getColumnBitmask() &
376                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID.getColumnBitmask()) != 0) {
377                                    Object[] args = new Object[] {
378                                                    layoutSetModelImpl.getOriginalLayoutSetPrototypeUuid()
379                                            };
380    
381                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LAYOUTSETPROTOTYPEUUID,
382                                            args);
383                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID,
384                                            args);
385    
386                                    args = new Object[] {
387                                                    layoutSetModelImpl.getLayoutSetPrototypeUuid()
388                                            };
389    
390                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LAYOUTSETPROTOTYPEUUID,
391                                            args);
392                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID,
393                                            args);
394                            }
395                    }
396    
397                    EntityCacheUtil.putResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
398                            LayoutSetImpl.class, layoutSet.getPrimaryKey(), layoutSet);
399    
400                    if (isNew) {
401                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
402                                    new Object[] {
403                                            Long.valueOf(layoutSet.getGroupId()),
404                                            Boolean.valueOf(layoutSet.getPrivateLayout())
405                                    }, layoutSet);
406                    }
407                    else {
408                            if ((layoutSetModelImpl.getColumnBitmask() &
409                                            FINDER_PATH_FETCH_BY_G_P.getColumnBitmask()) != 0) {
410                                    Object[] args = new Object[] {
411                                                    Long.valueOf(layoutSetModelImpl.getOriginalGroupId()),
412                                                    Boolean.valueOf(layoutSetModelImpl.getOriginalPrivateLayout())
413                                            };
414    
415                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
416                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P, args);
417    
418                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
419                                            new Object[] {
420                                                    Long.valueOf(layoutSet.getGroupId()),
421                                                    Boolean.valueOf(layoutSet.getPrivateLayout())
422                                            }, layoutSet);
423                            }
424                    }
425    
426                    return layoutSet;
427            }
428    
429            protected LayoutSet toUnwrappedModel(LayoutSet layoutSet) {
430                    if (layoutSet instanceof LayoutSetImpl) {
431                            return layoutSet;
432                    }
433    
434                    LayoutSetImpl layoutSetImpl = new LayoutSetImpl();
435    
436                    layoutSetImpl.setNew(layoutSet.isNew());
437                    layoutSetImpl.setPrimaryKey(layoutSet.getPrimaryKey());
438    
439                    layoutSetImpl.setLayoutSetId(layoutSet.getLayoutSetId());
440                    layoutSetImpl.setGroupId(layoutSet.getGroupId());
441                    layoutSetImpl.setCompanyId(layoutSet.getCompanyId());
442                    layoutSetImpl.setCreateDate(layoutSet.getCreateDate());
443                    layoutSetImpl.setModifiedDate(layoutSet.getModifiedDate());
444                    layoutSetImpl.setPrivateLayout(layoutSet.isPrivateLayout());
445                    layoutSetImpl.setLogo(layoutSet.isLogo());
446                    layoutSetImpl.setLogoId(layoutSet.getLogoId());
447                    layoutSetImpl.setThemeId(layoutSet.getThemeId());
448                    layoutSetImpl.setColorSchemeId(layoutSet.getColorSchemeId());
449                    layoutSetImpl.setWapThemeId(layoutSet.getWapThemeId());
450                    layoutSetImpl.setWapColorSchemeId(layoutSet.getWapColorSchemeId());
451                    layoutSetImpl.setCss(layoutSet.getCss());
452                    layoutSetImpl.setPageCount(layoutSet.getPageCount());
453                    layoutSetImpl.setSettings(layoutSet.getSettings());
454                    layoutSetImpl.setLayoutSetPrototypeUuid(layoutSet.getLayoutSetPrototypeUuid());
455                    layoutSetImpl.setLayoutSetPrototypeLinkEnabled(layoutSet.isLayoutSetPrototypeLinkEnabled());
456    
457                    return layoutSetImpl;
458            }
459    
460            /**
461             * Returns the layout set with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
462             *
463             * @param primaryKey the primary key of the layout set
464             * @return the layout set
465             * @throws com.liferay.portal.NoSuchModelException if a layout set with the primary key could not be found
466             * @throws SystemException if a system exception occurred
467             */
468            @Override
469            public LayoutSet findByPrimaryKey(Serializable primaryKey)
470                    throws NoSuchModelException, SystemException {
471                    return findByPrimaryKey(((Long)primaryKey).longValue());
472            }
473    
474            /**
475             * Returns the layout set with the primary key or throws a {@link com.liferay.portal.NoSuchLayoutSetException} if it could not be found.
476             *
477             * @param layoutSetId the primary key of the layout set
478             * @return the layout set
479             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
480             * @throws SystemException if a system exception occurred
481             */
482            public LayoutSet findByPrimaryKey(long layoutSetId)
483                    throws NoSuchLayoutSetException, SystemException {
484                    LayoutSet layoutSet = fetchByPrimaryKey(layoutSetId);
485    
486                    if (layoutSet == null) {
487                            if (_log.isWarnEnabled()) {
488                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + layoutSetId);
489                            }
490    
491                            throw new NoSuchLayoutSetException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
492                                    layoutSetId);
493                    }
494    
495                    return layoutSet;
496            }
497    
498            /**
499             * Returns the layout set with the primary key or returns <code>null</code> if it could not be found.
500             *
501             * @param primaryKey the primary key of the layout set
502             * @return the layout set, or <code>null</code> if a layout set with the primary key could not be found
503             * @throws SystemException if a system exception occurred
504             */
505            @Override
506            public LayoutSet fetchByPrimaryKey(Serializable primaryKey)
507                    throws SystemException {
508                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
509            }
510    
511            /**
512             * Returns the layout set with the primary key or returns <code>null</code> if it could not be found.
513             *
514             * @param layoutSetId the primary key of the layout set
515             * @return the layout set, or <code>null</code> if a layout set with the primary key could not be found
516             * @throws SystemException if a system exception occurred
517             */
518            public LayoutSet fetchByPrimaryKey(long layoutSetId)
519                    throws SystemException {
520                    LayoutSet layoutSet = (LayoutSet)EntityCacheUtil.getResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
521                                    LayoutSetImpl.class, layoutSetId);
522    
523                    if (layoutSet == _nullLayoutSet) {
524                            return null;
525                    }
526    
527                    if (layoutSet == null) {
528                            Session session = null;
529    
530                            boolean hasException = false;
531    
532                            try {
533                                    session = openSession();
534    
535                                    layoutSet = (LayoutSet)session.get(LayoutSetImpl.class,
536                                                    Long.valueOf(layoutSetId));
537                            }
538                            catch (Exception e) {
539                                    hasException = true;
540    
541                                    throw processException(e);
542                            }
543                            finally {
544                                    if (layoutSet != null) {
545                                            cacheResult(layoutSet);
546                                    }
547                                    else if (!hasException) {
548                                            EntityCacheUtil.putResult(LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
549                                                    LayoutSetImpl.class, layoutSetId, _nullLayoutSet);
550                                    }
551    
552                                    closeSession(session);
553                            }
554                    }
555    
556                    return layoutSet;
557            }
558    
559            /**
560             * Returns all the layout sets where groupId = &#63;.
561             *
562             * @param groupId the group ID
563             * @return the matching layout sets
564             * @throws SystemException if a system exception occurred
565             */
566            public List<LayoutSet> findByGroupId(long groupId)
567                    throws SystemException {
568                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
569            }
570    
571            /**
572             * Returns a range of all the layout sets where groupId = &#63;.
573             *
574             * <p>
575             * 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.
576             * </p>
577             *
578             * @param groupId the group ID
579             * @param start the lower bound of the range of layout sets
580             * @param end the upper bound of the range of layout sets (not inclusive)
581             * @return the range of matching layout sets
582             * @throws SystemException if a system exception occurred
583             */
584            public List<LayoutSet> findByGroupId(long groupId, int start, int end)
585                    throws SystemException {
586                    return findByGroupId(groupId, start, end, null);
587            }
588    
589            /**
590             * Returns an ordered range of all the layout sets where groupId = &#63;.
591             *
592             * <p>
593             * 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.
594             * </p>
595             *
596             * @param groupId the group ID
597             * @param start the lower bound of the range of layout sets
598             * @param end the upper bound of the range of layout sets (not inclusive)
599             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
600             * @return the ordered range of matching layout sets
601             * @throws SystemException if a system exception occurred
602             */
603            public List<LayoutSet> findByGroupId(long groupId, int start, int end,
604                    OrderByComparator orderByComparator) throws SystemException {
605                    FinderPath finderPath = null;
606                    Object[] finderArgs = null;
607    
608                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
609                                    (orderByComparator == null)) {
610                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
611                            finderArgs = new Object[] { groupId };
612                    }
613                    else {
614                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
615                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
616                    }
617    
618                    List<LayoutSet> list = (List<LayoutSet>)FinderCacheUtil.getResult(finderPath,
619                                    finderArgs, this);
620    
621                    if ((list != null) && !list.isEmpty()) {
622                            for (LayoutSet layoutSet : list) {
623                                    if ((groupId != layoutSet.getGroupId())) {
624                                            list = null;
625    
626                                            break;
627                                    }
628                            }
629                    }
630    
631                    if (list == null) {
632                            StringBundler query = null;
633    
634                            if (orderByComparator != null) {
635                                    query = new StringBundler(3 +
636                                                    (orderByComparator.getOrderByFields().length * 3));
637                            }
638                            else {
639                                    query = new StringBundler(2);
640                            }
641    
642                            query.append(_SQL_SELECT_LAYOUTSET_WHERE);
643    
644                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
645    
646                            if (orderByComparator != null) {
647                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
648                                            orderByComparator);
649                            }
650    
651                            String sql = query.toString();
652    
653                            Session session = null;
654    
655                            try {
656                                    session = openSession();
657    
658                                    Query q = session.createQuery(sql);
659    
660                                    QueryPos qPos = QueryPos.getInstance(q);
661    
662                                    qPos.add(groupId);
663    
664                                    list = (List<LayoutSet>)QueryUtil.list(q, getDialect(), start,
665                                                    end);
666                            }
667                            catch (Exception e) {
668                                    throw processException(e);
669                            }
670                            finally {
671                                    if (list == null) {
672                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
673                                    }
674                                    else {
675                                            cacheResult(list);
676    
677                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
678                                    }
679    
680                                    closeSession(session);
681                            }
682                    }
683    
684                    return list;
685            }
686    
687            /**
688             * Returns the first layout set in the ordered set where groupId = &#63;.
689             *
690             * <p>
691             * 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.
692             * </p>
693             *
694             * @param groupId the group ID
695             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
696             * @return the first matching layout set
697             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
698             * @throws SystemException if a system exception occurred
699             */
700            public LayoutSet findByGroupId_First(long groupId,
701                    OrderByComparator orderByComparator)
702                    throws NoSuchLayoutSetException, SystemException {
703                    List<LayoutSet> list = findByGroupId(groupId, 0, 1, orderByComparator);
704    
705                    if (list.isEmpty()) {
706                            StringBundler msg = new StringBundler(4);
707    
708                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
709    
710                            msg.append("groupId=");
711                            msg.append(groupId);
712    
713                            msg.append(StringPool.CLOSE_CURLY_BRACE);
714    
715                            throw new NoSuchLayoutSetException(msg.toString());
716                    }
717                    else {
718                            return list.get(0);
719                    }
720            }
721    
722            /**
723             * Returns the last layout set in the ordered set where groupId = &#63;.
724             *
725             * <p>
726             * 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.
727             * </p>
728             *
729             * @param groupId the group ID
730             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
731             * @return the last matching layout set
732             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
733             * @throws SystemException if a system exception occurred
734             */
735            public LayoutSet findByGroupId_Last(long groupId,
736                    OrderByComparator orderByComparator)
737                    throws NoSuchLayoutSetException, SystemException {
738                    int count = countByGroupId(groupId);
739    
740                    List<LayoutSet> list = findByGroupId(groupId, count - 1, count,
741                                    orderByComparator);
742    
743                    if (list.isEmpty()) {
744                            StringBundler msg = new StringBundler(4);
745    
746                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
747    
748                            msg.append("groupId=");
749                            msg.append(groupId);
750    
751                            msg.append(StringPool.CLOSE_CURLY_BRACE);
752    
753                            throw new NoSuchLayoutSetException(msg.toString());
754                    }
755                    else {
756                            return list.get(0);
757                    }
758            }
759    
760            /**
761             * Returns the layout sets before and after the current layout set in the ordered set where groupId = &#63;.
762             *
763             * <p>
764             * 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.
765             * </p>
766             *
767             * @param layoutSetId the primary key of the current layout set
768             * @param groupId the group ID
769             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
770             * @return the previous, current, and next layout set
771             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
772             * @throws SystemException if a system exception occurred
773             */
774            public LayoutSet[] findByGroupId_PrevAndNext(long layoutSetId,
775                    long groupId, OrderByComparator orderByComparator)
776                    throws NoSuchLayoutSetException, SystemException {
777                    LayoutSet layoutSet = findByPrimaryKey(layoutSetId);
778    
779                    Session session = null;
780    
781                    try {
782                            session = openSession();
783    
784                            LayoutSet[] array = new LayoutSetImpl[3];
785    
786                            array[0] = getByGroupId_PrevAndNext(session, layoutSet, groupId,
787                                            orderByComparator, true);
788    
789                            array[1] = layoutSet;
790    
791                            array[2] = getByGroupId_PrevAndNext(session, layoutSet, groupId,
792                                            orderByComparator, false);
793    
794                            return array;
795                    }
796                    catch (Exception e) {
797                            throw processException(e);
798                    }
799                    finally {
800                            closeSession(session);
801                    }
802            }
803    
804            protected LayoutSet getByGroupId_PrevAndNext(Session session,
805                    LayoutSet layoutSet, long groupId, OrderByComparator orderByComparator,
806                    boolean previous) {
807                    StringBundler query = null;
808    
809                    if (orderByComparator != null) {
810                            query = new StringBundler(6 +
811                                            (orderByComparator.getOrderByFields().length * 6));
812                    }
813                    else {
814                            query = new StringBundler(3);
815                    }
816    
817                    query.append(_SQL_SELECT_LAYOUTSET_WHERE);
818    
819                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
820    
821                    if (orderByComparator != null) {
822                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
823    
824                            if (orderByConditionFields.length > 0) {
825                                    query.append(WHERE_AND);
826                            }
827    
828                            for (int i = 0; i < orderByConditionFields.length; i++) {
829                                    query.append(_ORDER_BY_ENTITY_ALIAS);
830                                    query.append(orderByConditionFields[i]);
831    
832                                    if ((i + 1) < orderByConditionFields.length) {
833                                            if (orderByComparator.isAscending() ^ previous) {
834                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
835                                            }
836                                            else {
837                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
838                                            }
839                                    }
840                                    else {
841                                            if (orderByComparator.isAscending() ^ previous) {
842                                                    query.append(WHERE_GREATER_THAN);
843                                            }
844                                            else {
845                                                    query.append(WHERE_LESSER_THAN);
846                                            }
847                                    }
848                            }
849    
850                            query.append(ORDER_BY_CLAUSE);
851    
852                            String[] orderByFields = orderByComparator.getOrderByFields();
853    
854                            for (int i = 0; i < orderByFields.length; i++) {
855                                    query.append(_ORDER_BY_ENTITY_ALIAS);
856                                    query.append(orderByFields[i]);
857    
858                                    if ((i + 1) < orderByFields.length) {
859                                            if (orderByComparator.isAscending() ^ previous) {
860                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
861                                            }
862                                            else {
863                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
864                                            }
865                                    }
866                                    else {
867                                            if (orderByComparator.isAscending() ^ previous) {
868                                                    query.append(ORDER_BY_ASC);
869                                            }
870                                            else {
871                                                    query.append(ORDER_BY_DESC);
872                                            }
873                                    }
874                            }
875                    }
876    
877                    String sql = query.toString();
878    
879                    Query q = session.createQuery(sql);
880    
881                    q.setFirstResult(0);
882                    q.setMaxResults(2);
883    
884                    QueryPos qPos = QueryPos.getInstance(q);
885    
886                    qPos.add(groupId);
887    
888                    if (orderByComparator != null) {
889                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSet);
890    
891                            for (Object value : values) {
892                                    qPos.add(value);
893                            }
894                    }
895    
896                    List<LayoutSet> list = q.list();
897    
898                    if (list.size() == 2) {
899                            return list.get(1);
900                    }
901                    else {
902                            return null;
903                    }
904            }
905    
906            /**
907             * Returns all the layout sets where layoutSetPrototypeUuid = &#63;.
908             *
909             * @param layoutSetPrototypeUuid the layout set prototype uuid
910             * @return the matching layout sets
911             * @throws SystemException if a system exception occurred
912             */
913            public List<LayoutSet> findByLayoutSetPrototypeUuid(
914                    String layoutSetPrototypeUuid) throws SystemException {
915                    return findByLayoutSetPrototypeUuid(layoutSetPrototypeUuid,
916                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
917            }
918    
919            /**
920             * Returns a range of all the layout sets where layoutSetPrototypeUuid = &#63;.
921             *
922             * <p>
923             * 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.
924             * </p>
925             *
926             * @param layoutSetPrototypeUuid the layout set prototype uuid
927             * @param start the lower bound of the range of layout sets
928             * @param end the upper bound of the range of layout sets (not inclusive)
929             * @return the range of matching layout sets
930             * @throws SystemException if a system exception occurred
931             */
932            public List<LayoutSet> findByLayoutSetPrototypeUuid(
933                    String layoutSetPrototypeUuid, int start, int end)
934                    throws SystemException {
935                    return findByLayoutSetPrototypeUuid(layoutSetPrototypeUuid, start, end,
936                            null);
937            }
938    
939            /**
940             * Returns an ordered range of all the layout sets where layoutSetPrototypeUuid = &#63;.
941             *
942             * <p>
943             * 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.
944             * </p>
945             *
946             * @param layoutSetPrototypeUuid the layout set prototype uuid
947             * @param start the lower bound of the range of layout sets
948             * @param end the upper bound of the range of layout sets (not inclusive)
949             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
950             * @return the ordered range of matching layout sets
951             * @throws SystemException if a system exception occurred
952             */
953            public List<LayoutSet> findByLayoutSetPrototypeUuid(
954                    String layoutSetPrototypeUuid, int start, int end,
955                    OrderByComparator orderByComparator) throws SystemException {
956                    FinderPath finderPath = null;
957                    Object[] finderArgs = null;
958    
959                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
960                                    (orderByComparator == null)) {
961                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID;
962                            finderArgs = new Object[] { layoutSetPrototypeUuid };
963                    }
964                    else {
965                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTSETPROTOTYPEUUID;
966                            finderArgs = new Object[] {
967                                            layoutSetPrototypeUuid,
968                                            
969                                            start, end, orderByComparator
970                                    };
971                    }
972    
973                    List<LayoutSet> list = (List<LayoutSet>)FinderCacheUtil.getResult(finderPath,
974                                    finderArgs, this);
975    
976                    if ((list != null) && !list.isEmpty()) {
977                            for (LayoutSet layoutSet : list) {
978                                    if (!Validator.equals(layoutSetPrototypeUuid,
979                                                            layoutSet.getLayoutSetPrototypeUuid())) {
980                                            list = null;
981    
982                                            break;
983                                    }
984                            }
985                    }
986    
987                    if (list == null) {
988                            StringBundler query = null;
989    
990                            if (orderByComparator != null) {
991                                    query = new StringBundler(3 +
992                                                    (orderByComparator.getOrderByFields().length * 3));
993                            }
994                            else {
995                                    query = new StringBundler(2);
996                            }
997    
998                            query.append(_SQL_SELECT_LAYOUTSET_WHERE);
999    
1000                            if (layoutSetPrototypeUuid == null) {
1001                                    query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_1);
1002                            }
1003                            else {
1004                                    if (layoutSetPrototypeUuid.equals(StringPool.BLANK)) {
1005                                            query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_3);
1006                                    }
1007                                    else {
1008                                            query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_2);
1009                                    }
1010                            }
1011    
1012                            if (orderByComparator != null) {
1013                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1014                                            orderByComparator);
1015                            }
1016    
1017                            String sql = query.toString();
1018    
1019                            Session session = null;
1020    
1021                            try {
1022                                    session = openSession();
1023    
1024                                    Query q = session.createQuery(sql);
1025    
1026                                    QueryPos qPos = QueryPos.getInstance(q);
1027    
1028                                    if (layoutSetPrototypeUuid != null) {
1029                                            qPos.add(layoutSetPrototypeUuid);
1030                                    }
1031    
1032                                    list = (List<LayoutSet>)QueryUtil.list(q, getDialect(), start,
1033                                                    end);
1034                            }
1035                            catch (Exception e) {
1036                                    throw processException(e);
1037                            }
1038                            finally {
1039                                    if (list == null) {
1040                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1041                                    }
1042                                    else {
1043                                            cacheResult(list);
1044    
1045                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1046                                    }
1047    
1048                                    closeSession(session);
1049                            }
1050                    }
1051    
1052                    return list;
1053            }
1054    
1055            /**
1056             * Returns the first layout set in the ordered set where layoutSetPrototypeUuid = &#63;.
1057             *
1058             * <p>
1059             * 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.
1060             * </p>
1061             *
1062             * @param layoutSetPrototypeUuid the layout set prototype uuid
1063             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1064             * @return the first matching layout set
1065             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
1066             * @throws SystemException if a system exception occurred
1067             */
1068            public LayoutSet findByLayoutSetPrototypeUuid_First(
1069                    String layoutSetPrototypeUuid, OrderByComparator orderByComparator)
1070                    throws NoSuchLayoutSetException, SystemException {
1071                    List<LayoutSet> list = findByLayoutSetPrototypeUuid(layoutSetPrototypeUuid,
1072                                    0, 1, orderByComparator);
1073    
1074                    if (list.isEmpty()) {
1075                            StringBundler msg = new StringBundler(4);
1076    
1077                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1078    
1079                            msg.append("layoutSetPrototypeUuid=");
1080                            msg.append(layoutSetPrototypeUuid);
1081    
1082                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1083    
1084                            throw new NoSuchLayoutSetException(msg.toString());
1085                    }
1086                    else {
1087                            return list.get(0);
1088                    }
1089            }
1090    
1091            /**
1092             * Returns the last layout set in the ordered set where layoutSetPrototypeUuid = &#63;.
1093             *
1094             * <p>
1095             * 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.
1096             * </p>
1097             *
1098             * @param layoutSetPrototypeUuid the layout set prototype uuid
1099             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1100             * @return the last matching layout set
1101             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
1102             * @throws SystemException if a system exception occurred
1103             */
1104            public LayoutSet findByLayoutSetPrototypeUuid_Last(
1105                    String layoutSetPrototypeUuid, OrderByComparator orderByComparator)
1106                    throws NoSuchLayoutSetException, SystemException {
1107                    int count = countByLayoutSetPrototypeUuid(layoutSetPrototypeUuid);
1108    
1109                    List<LayoutSet> list = findByLayoutSetPrototypeUuid(layoutSetPrototypeUuid,
1110                                    count - 1, count, orderByComparator);
1111    
1112                    if (list.isEmpty()) {
1113                            StringBundler msg = new StringBundler(4);
1114    
1115                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1116    
1117                            msg.append("layoutSetPrototypeUuid=");
1118                            msg.append(layoutSetPrototypeUuid);
1119    
1120                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1121    
1122                            throw new NoSuchLayoutSetException(msg.toString());
1123                    }
1124                    else {
1125                            return list.get(0);
1126                    }
1127            }
1128    
1129            /**
1130             * Returns the layout sets before and after the current layout set in the ordered set where layoutSetPrototypeUuid = &#63;.
1131             *
1132             * <p>
1133             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1134             * </p>
1135             *
1136             * @param layoutSetId the primary key of the current layout set
1137             * @param layoutSetPrototypeUuid the layout set prototype uuid
1138             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1139             * @return the previous, current, and next layout set
1140             * @throws com.liferay.portal.NoSuchLayoutSetException if a layout set with the primary key could not be found
1141             * @throws SystemException if a system exception occurred
1142             */
1143            public LayoutSet[] findByLayoutSetPrototypeUuid_PrevAndNext(
1144                    long layoutSetId, String layoutSetPrototypeUuid,
1145                    OrderByComparator orderByComparator)
1146                    throws NoSuchLayoutSetException, SystemException {
1147                    LayoutSet layoutSet = findByPrimaryKey(layoutSetId);
1148    
1149                    Session session = null;
1150    
1151                    try {
1152                            session = openSession();
1153    
1154                            LayoutSet[] array = new LayoutSetImpl[3];
1155    
1156                            array[0] = getByLayoutSetPrototypeUuid_PrevAndNext(session,
1157                                            layoutSet, layoutSetPrototypeUuid, orderByComparator, true);
1158    
1159                            array[1] = layoutSet;
1160    
1161                            array[2] = getByLayoutSetPrototypeUuid_PrevAndNext(session,
1162                                            layoutSet, layoutSetPrototypeUuid, orderByComparator, false);
1163    
1164                            return array;
1165                    }
1166                    catch (Exception e) {
1167                            throw processException(e);
1168                    }
1169                    finally {
1170                            closeSession(session);
1171                    }
1172            }
1173    
1174            protected LayoutSet getByLayoutSetPrototypeUuid_PrevAndNext(
1175                    Session session, LayoutSet layoutSet, String layoutSetPrototypeUuid,
1176                    OrderByComparator orderByComparator, boolean previous) {
1177                    StringBundler query = null;
1178    
1179                    if (orderByComparator != null) {
1180                            query = new StringBundler(6 +
1181                                            (orderByComparator.getOrderByFields().length * 6));
1182                    }
1183                    else {
1184                            query = new StringBundler(3);
1185                    }
1186    
1187                    query.append(_SQL_SELECT_LAYOUTSET_WHERE);
1188    
1189                    if (layoutSetPrototypeUuid == null) {
1190                            query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_1);
1191                    }
1192                    else {
1193                            if (layoutSetPrototypeUuid.equals(StringPool.BLANK)) {
1194                                    query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_3);
1195                            }
1196                            else {
1197                                    query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_2);
1198                            }
1199                    }
1200    
1201                    if (orderByComparator != null) {
1202                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1203    
1204                            if (orderByConditionFields.length > 0) {
1205                                    query.append(WHERE_AND);
1206                            }
1207    
1208                            for (int i = 0; i < orderByConditionFields.length; i++) {
1209                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1210                                    query.append(orderByConditionFields[i]);
1211    
1212                                    if ((i + 1) < orderByConditionFields.length) {
1213                                            if (orderByComparator.isAscending() ^ previous) {
1214                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1215                                            }
1216                                            else {
1217                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1218                                            }
1219                                    }
1220                                    else {
1221                                            if (orderByComparator.isAscending() ^ previous) {
1222                                                    query.append(WHERE_GREATER_THAN);
1223                                            }
1224                                            else {
1225                                                    query.append(WHERE_LESSER_THAN);
1226                                            }
1227                                    }
1228                            }
1229    
1230                            query.append(ORDER_BY_CLAUSE);
1231    
1232                            String[] orderByFields = orderByComparator.getOrderByFields();
1233    
1234                            for (int i = 0; i < orderByFields.length; i++) {
1235                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1236                                    query.append(orderByFields[i]);
1237    
1238                                    if ((i + 1) < orderByFields.length) {
1239                                            if (orderByComparator.isAscending() ^ previous) {
1240                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1241                                            }
1242                                            else {
1243                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1244                                            }
1245                                    }
1246                                    else {
1247                                            if (orderByComparator.isAscending() ^ previous) {
1248                                                    query.append(ORDER_BY_ASC);
1249                                            }
1250                                            else {
1251                                                    query.append(ORDER_BY_DESC);
1252                                            }
1253                                    }
1254                            }
1255                    }
1256    
1257                    String sql = query.toString();
1258    
1259                    Query q = session.createQuery(sql);
1260    
1261                    q.setFirstResult(0);
1262                    q.setMaxResults(2);
1263    
1264                    QueryPos qPos = QueryPos.getInstance(q);
1265    
1266                    if (layoutSetPrototypeUuid != null) {
1267                            qPos.add(layoutSetPrototypeUuid);
1268                    }
1269    
1270                    if (orderByComparator != null) {
1271                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSet);
1272    
1273                            for (Object value : values) {
1274                                    qPos.add(value);
1275                            }
1276                    }
1277    
1278                    List<LayoutSet> list = q.list();
1279    
1280                    if (list.size() == 2) {
1281                            return list.get(1);
1282                    }
1283                    else {
1284                            return null;
1285                    }
1286            }
1287    
1288            /**
1289             * Returns the layout set where groupId = &#63; and privateLayout = &#63; or throws a {@link com.liferay.portal.NoSuchLayoutSetException} if it could not be found.
1290             *
1291             * @param groupId the group ID
1292             * @param privateLayout the private layout
1293             * @return the matching layout set
1294             * @throws com.liferay.portal.NoSuchLayoutSetException if a matching layout set could not be found
1295             * @throws SystemException if a system exception occurred
1296             */
1297            public LayoutSet findByG_P(long groupId, boolean privateLayout)
1298                    throws NoSuchLayoutSetException, SystemException {
1299                    LayoutSet layoutSet = fetchByG_P(groupId, privateLayout);
1300    
1301                    if (layoutSet == null) {
1302                            StringBundler msg = new StringBundler(6);
1303    
1304                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1305    
1306                            msg.append("groupId=");
1307                            msg.append(groupId);
1308    
1309                            msg.append(", privateLayout=");
1310                            msg.append(privateLayout);
1311    
1312                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1313    
1314                            if (_log.isWarnEnabled()) {
1315                                    _log.warn(msg.toString());
1316                            }
1317    
1318                            throw new NoSuchLayoutSetException(msg.toString());
1319                    }
1320    
1321                    return layoutSet;
1322            }
1323    
1324            /**
1325             * Returns the layout set where groupId = &#63; and privateLayout = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1326             *
1327             * @param groupId the group ID
1328             * @param privateLayout the private layout
1329             * @return the matching layout set, or <code>null</code> if a matching layout set could not be found
1330             * @throws SystemException if a system exception occurred
1331             */
1332            public LayoutSet fetchByG_P(long groupId, boolean privateLayout)
1333                    throws SystemException {
1334                    return fetchByG_P(groupId, privateLayout, true);
1335            }
1336    
1337            /**
1338             * Returns the layout set where groupId = &#63; and privateLayout = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1339             *
1340             * @param groupId the group ID
1341             * @param privateLayout the private layout
1342             * @param retrieveFromCache whether to use the finder cache
1343             * @return the matching layout set, or <code>null</code> if a matching layout set could not be found
1344             * @throws SystemException if a system exception occurred
1345             */
1346            public LayoutSet fetchByG_P(long groupId, boolean privateLayout,
1347                    boolean retrieveFromCache) throws SystemException {
1348                    Object[] finderArgs = new Object[] { groupId, privateLayout };
1349    
1350                    Object result = null;
1351    
1352                    if (retrieveFromCache) {
1353                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P,
1354                                            finderArgs, this);
1355                    }
1356    
1357                    if (result instanceof LayoutSet) {
1358                            LayoutSet layoutSet = (LayoutSet)result;
1359    
1360                            if ((groupId != layoutSet.getGroupId()) ||
1361                                            (privateLayout != layoutSet.getPrivateLayout())) {
1362                                    result = null;
1363                            }
1364                    }
1365    
1366                    if (result == null) {
1367                            StringBundler query = new StringBundler(3);
1368    
1369                            query.append(_SQL_SELECT_LAYOUTSET_WHERE);
1370    
1371                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1372    
1373                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1374    
1375                            String sql = query.toString();
1376    
1377                            Session session = null;
1378    
1379                            try {
1380                                    session = openSession();
1381    
1382                                    Query q = session.createQuery(sql);
1383    
1384                                    QueryPos qPos = QueryPos.getInstance(q);
1385    
1386                                    qPos.add(groupId);
1387    
1388                                    qPos.add(privateLayout);
1389    
1390                                    List<LayoutSet> list = q.list();
1391    
1392                                    result = list;
1393    
1394                                    LayoutSet layoutSet = null;
1395    
1396                                    if (list.isEmpty()) {
1397                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
1398                                                    finderArgs, list);
1399                                    }
1400                                    else {
1401                                            layoutSet = list.get(0);
1402    
1403                                            cacheResult(layoutSet);
1404    
1405                                            if ((layoutSet.getGroupId() != groupId) ||
1406                                                            (layoutSet.getPrivateLayout() != privateLayout)) {
1407                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P,
1408                                                            finderArgs, layoutSet);
1409                                            }
1410                                    }
1411    
1412                                    return layoutSet;
1413                            }
1414                            catch (Exception e) {
1415                                    throw processException(e);
1416                            }
1417                            finally {
1418                                    if (result == null) {
1419                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P,
1420                                                    finderArgs);
1421                                    }
1422    
1423                                    closeSession(session);
1424                            }
1425                    }
1426                    else {
1427                            if (result instanceof List<?>) {
1428                                    return null;
1429                            }
1430                            else {
1431                                    return (LayoutSet)result;
1432                            }
1433                    }
1434            }
1435    
1436            /**
1437             * Returns all the layout sets.
1438             *
1439             * @return the layout sets
1440             * @throws SystemException if a system exception occurred
1441             */
1442            public List<LayoutSet> findAll() throws SystemException {
1443                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1444            }
1445    
1446            /**
1447             * Returns a range of all the layout sets.
1448             *
1449             * <p>
1450             * 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.
1451             * </p>
1452             *
1453             * @param start the lower bound of the range of layout sets
1454             * @param end the upper bound of the range of layout sets (not inclusive)
1455             * @return the range of layout sets
1456             * @throws SystemException if a system exception occurred
1457             */
1458            public List<LayoutSet> findAll(int start, int end)
1459                    throws SystemException {
1460                    return findAll(start, end, null);
1461            }
1462    
1463            /**
1464             * Returns an ordered range of all the layout sets.
1465             *
1466             * <p>
1467             * 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.
1468             * </p>
1469             *
1470             * @param start the lower bound of the range of layout sets
1471             * @param end the upper bound of the range of layout sets (not inclusive)
1472             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1473             * @return the ordered range of layout sets
1474             * @throws SystemException if a system exception occurred
1475             */
1476            public List<LayoutSet> findAll(int start, int end,
1477                    OrderByComparator orderByComparator) throws SystemException {
1478                    FinderPath finderPath = null;
1479                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1480    
1481                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1482                                    (orderByComparator == null)) {
1483                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1484                            finderArgs = FINDER_ARGS_EMPTY;
1485                    }
1486                    else {
1487                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1488                            finderArgs = new Object[] { start, end, orderByComparator };
1489                    }
1490    
1491                    List<LayoutSet> list = (List<LayoutSet>)FinderCacheUtil.getResult(finderPath,
1492                                    finderArgs, this);
1493    
1494                    if (list == null) {
1495                            StringBundler query = null;
1496                            String sql = null;
1497    
1498                            if (orderByComparator != null) {
1499                                    query = new StringBundler(2 +
1500                                                    (orderByComparator.getOrderByFields().length * 3));
1501    
1502                                    query.append(_SQL_SELECT_LAYOUTSET);
1503    
1504                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1505                                            orderByComparator);
1506    
1507                                    sql = query.toString();
1508                            }
1509                            else {
1510                                    sql = _SQL_SELECT_LAYOUTSET;
1511                            }
1512    
1513                            Session session = null;
1514    
1515                            try {
1516                                    session = openSession();
1517    
1518                                    Query q = session.createQuery(sql);
1519    
1520                                    if (orderByComparator == null) {
1521                                            list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
1522                                                            start, end, false);
1523    
1524                                            Collections.sort(list);
1525                                    }
1526                                    else {
1527                                            list = (List<LayoutSet>)QueryUtil.list(q, getDialect(),
1528                                                            start, end);
1529                                    }
1530                            }
1531                            catch (Exception e) {
1532                                    throw processException(e);
1533                            }
1534                            finally {
1535                                    if (list == null) {
1536                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1537                                    }
1538                                    else {
1539                                            cacheResult(list);
1540    
1541                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1542                                    }
1543    
1544                                    closeSession(session);
1545                            }
1546                    }
1547    
1548                    return list;
1549            }
1550    
1551            /**
1552             * Removes all the layout sets where groupId = &#63; from the database.
1553             *
1554             * @param groupId the group ID
1555             * @throws SystemException if a system exception occurred
1556             */
1557            public void removeByGroupId(long groupId) throws SystemException {
1558                    for (LayoutSet layoutSet : findByGroupId(groupId)) {
1559                            remove(layoutSet);
1560                    }
1561            }
1562    
1563            /**
1564             * Removes all the layout sets where layoutSetPrototypeUuid = &#63; from the database.
1565             *
1566             * @param layoutSetPrototypeUuid the layout set prototype uuid
1567             * @throws SystemException if a system exception occurred
1568             */
1569            public void removeByLayoutSetPrototypeUuid(String layoutSetPrototypeUuid)
1570                    throws SystemException {
1571                    for (LayoutSet layoutSet : findByLayoutSetPrototypeUuid(
1572                                    layoutSetPrototypeUuid)) {
1573                            remove(layoutSet);
1574                    }
1575            }
1576    
1577            /**
1578             * Removes the layout set where groupId = &#63; and privateLayout = &#63; from the database.
1579             *
1580             * @param groupId the group ID
1581             * @param privateLayout the private layout
1582             * @throws SystemException if a system exception occurred
1583             */
1584            public void removeByG_P(long groupId, boolean privateLayout)
1585                    throws NoSuchLayoutSetException, SystemException {
1586                    LayoutSet layoutSet = findByG_P(groupId, privateLayout);
1587    
1588                    remove(layoutSet);
1589            }
1590    
1591            /**
1592             * Removes all the layout sets from the database.
1593             *
1594             * @throws SystemException if a system exception occurred
1595             */
1596            public void removeAll() throws SystemException {
1597                    for (LayoutSet layoutSet : findAll()) {
1598                            remove(layoutSet);
1599                    }
1600            }
1601    
1602            /**
1603             * Returns the number of layout sets where groupId = &#63;.
1604             *
1605             * @param groupId the group ID
1606             * @return the number of matching layout sets
1607             * @throws SystemException if a system exception occurred
1608             */
1609            public int countByGroupId(long groupId) throws SystemException {
1610                    Object[] finderArgs = new Object[] { groupId };
1611    
1612                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1613                                    finderArgs, this);
1614    
1615                    if (count == null) {
1616                            StringBundler query = new StringBundler(2);
1617    
1618                            query.append(_SQL_COUNT_LAYOUTSET_WHERE);
1619    
1620                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1621    
1622                            String sql = query.toString();
1623    
1624                            Session session = null;
1625    
1626                            try {
1627                                    session = openSession();
1628    
1629                                    Query q = session.createQuery(sql);
1630    
1631                                    QueryPos qPos = QueryPos.getInstance(q);
1632    
1633                                    qPos.add(groupId);
1634    
1635                                    count = (Long)q.uniqueResult();
1636                            }
1637                            catch (Exception e) {
1638                                    throw processException(e);
1639                            }
1640                            finally {
1641                                    if (count == null) {
1642                                            count = Long.valueOf(0);
1643                                    }
1644    
1645                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1646                                            finderArgs, count);
1647    
1648                                    closeSession(session);
1649                            }
1650                    }
1651    
1652                    return count.intValue();
1653            }
1654    
1655            /**
1656             * Returns the number of layout sets where layoutSetPrototypeUuid = &#63;.
1657             *
1658             * @param layoutSetPrototypeUuid the layout set prototype uuid
1659             * @return the number of matching layout sets
1660             * @throws SystemException if a system exception occurred
1661             */
1662            public int countByLayoutSetPrototypeUuid(String layoutSetPrototypeUuid)
1663                    throws SystemException {
1664                    Object[] finderArgs = new Object[] { layoutSetPrototypeUuid };
1665    
1666                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LAYOUTSETPROTOTYPEUUID,
1667                                    finderArgs, this);
1668    
1669                    if (count == null) {
1670                            StringBundler query = new StringBundler(2);
1671    
1672                            query.append(_SQL_COUNT_LAYOUTSET_WHERE);
1673    
1674                            if (layoutSetPrototypeUuid == null) {
1675                                    query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_1);
1676                            }
1677                            else {
1678                                    if (layoutSetPrototypeUuid.equals(StringPool.BLANK)) {
1679                                            query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_3);
1680                                    }
1681                                    else {
1682                                            query.append(_FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_2);
1683                                    }
1684                            }
1685    
1686                            String sql = query.toString();
1687    
1688                            Session session = null;
1689    
1690                            try {
1691                                    session = openSession();
1692    
1693                                    Query q = session.createQuery(sql);
1694    
1695                                    QueryPos qPos = QueryPos.getInstance(q);
1696    
1697                                    if (layoutSetPrototypeUuid != null) {
1698                                            qPos.add(layoutSetPrototypeUuid);
1699                                    }
1700    
1701                                    count = (Long)q.uniqueResult();
1702                            }
1703                            catch (Exception e) {
1704                                    throw processException(e);
1705                            }
1706                            finally {
1707                                    if (count == null) {
1708                                            count = Long.valueOf(0);
1709                                    }
1710    
1711                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LAYOUTSETPROTOTYPEUUID,
1712                                            finderArgs, count);
1713    
1714                                    closeSession(session);
1715                            }
1716                    }
1717    
1718                    return count.intValue();
1719            }
1720    
1721            /**
1722             * Returns the number of layout sets where groupId = &#63; and privateLayout = &#63;.
1723             *
1724             * @param groupId the group ID
1725             * @param privateLayout the private layout
1726             * @return the number of matching layout sets
1727             * @throws SystemException if a system exception occurred
1728             */
1729            public int countByG_P(long groupId, boolean privateLayout)
1730                    throws SystemException {
1731                    Object[] finderArgs = new Object[] { groupId, privateLayout };
1732    
1733                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
1734                                    finderArgs, this);
1735    
1736                    if (count == null) {
1737                            StringBundler query = new StringBundler(3);
1738    
1739                            query.append(_SQL_COUNT_LAYOUTSET_WHERE);
1740    
1741                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1742    
1743                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1744    
1745                            String sql = query.toString();
1746    
1747                            Session session = null;
1748    
1749                            try {
1750                                    session = openSession();
1751    
1752                                    Query q = session.createQuery(sql);
1753    
1754                                    QueryPos qPos = QueryPos.getInstance(q);
1755    
1756                                    qPos.add(groupId);
1757    
1758                                    qPos.add(privateLayout);
1759    
1760                                    count = (Long)q.uniqueResult();
1761                            }
1762                            catch (Exception e) {
1763                                    throw processException(e);
1764                            }
1765                            finally {
1766                                    if (count == null) {
1767                                            count = Long.valueOf(0);
1768                                    }
1769    
1770                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
1771                                            count);
1772    
1773                                    closeSession(session);
1774                            }
1775                    }
1776    
1777                    return count.intValue();
1778            }
1779    
1780            /**
1781             * Returns the number of layout sets.
1782             *
1783             * @return the number of layout sets
1784             * @throws SystemException if a system exception occurred
1785             */
1786            public int countAll() throws SystemException {
1787                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1788                                    FINDER_ARGS_EMPTY, this);
1789    
1790                    if (count == null) {
1791                            Session session = null;
1792    
1793                            try {
1794                                    session = openSession();
1795    
1796                                    Query q = session.createQuery(_SQL_COUNT_LAYOUTSET);
1797    
1798                                    count = (Long)q.uniqueResult();
1799                            }
1800                            catch (Exception e) {
1801                                    throw processException(e);
1802                            }
1803                            finally {
1804                                    if (count == null) {
1805                                            count = Long.valueOf(0);
1806                                    }
1807    
1808                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1809                                            FINDER_ARGS_EMPTY, count);
1810    
1811                                    closeSession(session);
1812                            }
1813                    }
1814    
1815                    return count.intValue();
1816            }
1817    
1818            /**
1819             * Initializes the layout set persistence.
1820             */
1821            public void afterPropertiesSet() {
1822                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1823                                            com.liferay.portal.util.PropsUtil.get(
1824                                                    "value.object.listener.com.liferay.portal.model.LayoutSet")));
1825    
1826                    if (listenerClassNames.length > 0) {
1827                            try {
1828                                    List<ModelListener<LayoutSet>> listenersList = new ArrayList<ModelListener<LayoutSet>>();
1829    
1830                                    for (String listenerClassName : listenerClassNames) {
1831                                            listenersList.add((ModelListener<LayoutSet>)InstanceFactory.newInstance(
1832                                                            listenerClassName));
1833                                    }
1834    
1835                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1836                            }
1837                            catch (Exception e) {
1838                                    _log.error(e);
1839                            }
1840                    }
1841            }
1842    
1843            public void destroy() {
1844                    EntityCacheUtil.removeCache(LayoutSetImpl.class.getName());
1845                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1846                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1847            }
1848    
1849            @BeanReference(type = AccountPersistence.class)
1850            protected AccountPersistence accountPersistence;
1851            @BeanReference(type = AddressPersistence.class)
1852            protected AddressPersistence addressPersistence;
1853            @BeanReference(type = BrowserTrackerPersistence.class)
1854            protected BrowserTrackerPersistence browserTrackerPersistence;
1855            @BeanReference(type = ClassNamePersistence.class)
1856            protected ClassNamePersistence classNamePersistence;
1857            @BeanReference(type = ClusterGroupPersistence.class)
1858            protected ClusterGroupPersistence clusterGroupPersistence;
1859            @BeanReference(type = CompanyPersistence.class)
1860            protected CompanyPersistence companyPersistence;
1861            @BeanReference(type = ContactPersistence.class)
1862            protected ContactPersistence contactPersistence;
1863            @BeanReference(type = CountryPersistence.class)
1864            protected CountryPersistence countryPersistence;
1865            @BeanReference(type = EmailAddressPersistence.class)
1866            protected EmailAddressPersistence emailAddressPersistence;
1867            @BeanReference(type = GroupPersistence.class)
1868            protected GroupPersistence groupPersistence;
1869            @BeanReference(type = ImagePersistence.class)
1870            protected ImagePersistence imagePersistence;
1871            @BeanReference(type = LayoutPersistence.class)
1872            protected LayoutPersistence layoutPersistence;
1873            @BeanReference(type = LayoutBranchPersistence.class)
1874            protected LayoutBranchPersistence layoutBranchPersistence;
1875            @BeanReference(type = LayoutPrototypePersistence.class)
1876            protected LayoutPrototypePersistence layoutPrototypePersistence;
1877            @BeanReference(type = LayoutRevisionPersistence.class)
1878            protected LayoutRevisionPersistence layoutRevisionPersistence;
1879            @BeanReference(type = LayoutSetPersistence.class)
1880            protected LayoutSetPersistence layoutSetPersistence;
1881            @BeanReference(type = LayoutSetBranchPersistence.class)
1882            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1883            @BeanReference(type = LayoutSetPrototypePersistence.class)
1884            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1885            @BeanReference(type = ListTypePersistence.class)
1886            protected ListTypePersistence listTypePersistence;
1887            @BeanReference(type = LockPersistence.class)
1888            protected LockPersistence lockPersistence;
1889            @BeanReference(type = MembershipRequestPersistence.class)
1890            protected MembershipRequestPersistence membershipRequestPersistence;
1891            @BeanReference(type = OrganizationPersistence.class)
1892            protected OrganizationPersistence organizationPersistence;
1893            @BeanReference(type = OrgGroupPermissionPersistence.class)
1894            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1895            @BeanReference(type = OrgGroupRolePersistence.class)
1896            protected OrgGroupRolePersistence orgGroupRolePersistence;
1897            @BeanReference(type = OrgLaborPersistence.class)
1898            protected OrgLaborPersistence orgLaborPersistence;
1899            @BeanReference(type = PasswordPolicyPersistence.class)
1900            protected PasswordPolicyPersistence passwordPolicyPersistence;
1901            @BeanReference(type = PasswordPolicyRelPersistence.class)
1902            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1903            @BeanReference(type = PasswordTrackerPersistence.class)
1904            protected PasswordTrackerPersistence passwordTrackerPersistence;
1905            @BeanReference(type = PermissionPersistence.class)
1906            protected PermissionPersistence permissionPersistence;
1907            @BeanReference(type = PhonePersistence.class)
1908            protected PhonePersistence phonePersistence;
1909            @BeanReference(type = PluginSettingPersistence.class)
1910            protected PluginSettingPersistence pluginSettingPersistence;
1911            @BeanReference(type = PortalPreferencesPersistence.class)
1912            protected PortalPreferencesPersistence portalPreferencesPersistence;
1913            @BeanReference(type = PortletPersistence.class)
1914            protected PortletPersistence portletPersistence;
1915            @BeanReference(type = PortletItemPersistence.class)
1916            protected PortletItemPersistence portletItemPersistence;
1917            @BeanReference(type = PortletPreferencesPersistence.class)
1918            protected PortletPreferencesPersistence portletPreferencesPersistence;
1919            @BeanReference(type = RegionPersistence.class)
1920            protected RegionPersistence regionPersistence;
1921            @BeanReference(type = ReleasePersistence.class)
1922            protected ReleasePersistence releasePersistence;
1923            @BeanReference(type = RepositoryPersistence.class)
1924            protected RepositoryPersistence repositoryPersistence;
1925            @BeanReference(type = RepositoryEntryPersistence.class)
1926            protected RepositoryEntryPersistence repositoryEntryPersistence;
1927            @BeanReference(type = ResourcePersistence.class)
1928            protected ResourcePersistence resourcePersistence;
1929            @BeanReference(type = ResourceActionPersistence.class)
1930            protected ResourceActionPersistence resourceActionPersistence;
1931            @BeanReference(type = ResourceBlockPersistence.class)
1932            protected ResourceBlockPersistence resourceBlockPersistence;
1933            @BeanReference(type = ResourceBlockPermissionPersistence.class)
1934            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1935            @BeanReference(type = ResourceCodePersistence.class)
1936            protected ResourceCodePersistence resourceCodePersistence;
1937            @BeanReference(type = ResourcePermissionPersistence.class)
1938            protected ResourcePermissionPersistence resourcePermissionPersistence;
1939            @BeanReference(type = ResourceTypePermissionPersistence.class)
1940            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1941            @BeanReference(type = RolePersistence.class)
1942            protected RolePersistence rolePersistence;
1943            @BeanReference(type = ServiceComponentPersistence.class)
1944            protected ServiceComponentPersistence serviceComponentPersistence;
1945            @BeanReference(type = ShardPersistence.class)
1946            protected ShardPersistence shardPersistence;
1947            @BeanReference(type = SubscriptionPersistence.class)
1948            protected SubscriptionPersistence subscriptionPersistence;
1949            @BeanReference(type = TeamPersistence.class)
1950            protected TeamPersistence teamPersistence;
1951            @BeanReference(type = TicketPersistence.class)
1952            protected TicketPersistence ticketPersistence;
1953            @BeanReference(type = UserPersistence.class)
1954            protected UserPersistence userPersistence;
1955            @BeanReference(type = UserGroupPersistence.class)
1956            protected UserGroupPersistence userGroupPersistence;
1957            @BeanReference(type = UserGroupGroupRolePersistence.class)
1958            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1959            @BeanReference(type = UserGroupRolePersistence.class)
1960            protected UserGroupRolePersistence userGroupRolePersistence;
1961            @BeanReference(type = UserIdMapperPersistence.class)
1962            protected UserIdMapperPersistence userIdMapperPersistence;
1963            @BeanReference(type = UserNotificationEventPersistence.class)
1964            protected UserNotificationEventPersistence userNotificationEventPersistence;
1965            @BeanReference(type = UserTrackerPersistence.class)
1966            protected UserTrackerPersistence userTrackerPersistence;
1967            @BeanReference(type = UserTrackerPathPersistence.class)
1968            protected UserTrackerPathPersistence userTrackerPathPersistence;
1969            @BeanReference(type = VirtualHostPersistence.class)
1970            protected VirtualHostPersistence virtualHostPersistence;
1971            @BeanReference(type = WebDAVPropsPersistence.class)
1972            protected WebDAVPropsPersistence webDAVPropsPersistence;
1973            @BeanReference(type = WebsitePersistence.class)
1974            protected WebsitePersistence websitePersistence;
1975            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1976            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1977            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1978            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1979            private static final String _SQL_SELECT_LAYOUTSET = "SELECT layoutSet FROM LayoutSet layoutSet";
1980            private static final String _SQL_SELECT_LAYOUTSET_WHERE = "SELECT layoutSet FROM LayoutSet layoutSet WHERE ";
1981            private static final String _SQL_COUNT_LAYOUTSET = "SELECT COUNT(layoutSet) FROM LayoutSet layoutSet";
1982            private static final String _SQL_COUNT_LAYOUTSET_WHERE = "SELECT COUNT(layoutSet) FROM LayoutSet layoutSet WHERE ";
1983            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "layoutSet.groupId = ?";
1984            private static final String _FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_1 =
1985                    "layoutSet.layoutSetPrototypeUuid IS NULL";
1986            private static final String _FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_2 =
1987                    "layoutSet.layoutSetPrototypeUuid = ?";
1988            private static final String _FINDER_COLUMN_LAYOUTSETPROTOTYPEUUID_LAYOUTSETPROTOTYPEUUID_3 =
1989                    "(layoutSet.layoutSetPrototypeUuid IS NULL OR layoutSet.layoutSetPrototypeUuid = ?)";
1990            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "layoutSet.groupId = ? AND ";
1991            private static final String _FINDER_COLUMN_G_P_PRIVATELAYOUT_2 = "layoutSet.privateLayout = ?";
1992            private static final String _ORDER_BY_ENTITY_ALIAS = "layoutSet.";
1993            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutSet exists with the primary key ";
1994            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutSet exists with the key {";
1995            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1996            private static Log _log = LogFactoryUtil.getLog(LayoutSetPersistenceImpl.class);
1997            private static LayoutSet _nullLayoutSet = new LayoutSetImpl() {
1998                            @Override
1999                            public Object clone() {
2000                                    return this;
2001                            }
2002    
2003                            @Override
2004                            public CacheModel<LayoutSet> toCacheModel() {
2005                                    return _nullLayoutSetCacheModel;
2006                            }
2007                    };
2008    
2009            private static CacheModel<LayoutSet> _nullLayoutSetCacheModel = new CacheModel<LayoutSet>() {
2010                            public LayoutSet toEntityModel() {
2011                                    return _nullLayoutSet;
2012                            }
2013                    };
2014    }