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