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