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