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