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