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