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