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