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