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.NoSuchLayoutSetBranchException;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.SQLQuery;
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.LayoutSetBranch;
039    import com.liferay.portal.model.MVCCModel;
040    import com.liferay.portal.model.impl.LayoutSetBranchImpl;
041    import com.liferay.portal.model.impl.LayoutSetBranchModelImpl;
042    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
043    import com.liferay.portal.service.ServiceContext;
044    import com.liferay.portal.service.ServiceContextThreadLocal;
045    import com.liferay.portal.service.persistence.LayoutSetBranchPersistence;
046    
047    import java.io.Serializable;
048    
049    import java.util.Collections;
050    import java.util.Date;
051    import java.util.HashMap;
052    import java.util.HashSet;
053    import java.util.Iterator;
054    import java.util.List;
055    import java.util.Map;
056    import java.util.Set;
057    
058    /**
059     * The persistence implementation for the layout set branch service.
060     *
061     * <p>
062     * Caching information and settings can be found in <code>portal.properties</code>
063     * </p>
064     *
065     * @author Brian Wing Shun Chan
066     * @see LayoutSetBranchPersistence
067     * @see com.liferay.portal.service.persistence.LayoutSetBranchUtil
068     * @generated
069     */
070    @ProviderType
071    public class LayoutSetBranchPersistenceImpl extends BasePersistenceImpl<LayoutSetBranch>
072            implements LayoutSetBranchPersistence {
073            /*
074             * NOTE FOR DEVELOPERS:
075             *
076             * Never modify or reference this class directly. Always use {@link LayoutSetBranchUtil} to access the layout set branch persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
077             */
078            public static final String FINDER_CLASS_NAME_ENTITY = LayoutSetBranchImpl.class.getName();
079            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List1";
081            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List2";
083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
084                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
085                            LayoutSetBranchImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
086                            "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
088                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
089                            LayoutSetBranchImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
091            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
092                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
095                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
096                            LayoutSetBranchImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
097                            "findByGroupId",
098                            new String[] {
099                                    Long.class.getName(),
100                                    
101                            Integer.class.getName(), Integer.class.getName(),
102                                    OrderByComparator.class.getName()
103                            });
104            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
105                    new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
106                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
107                            LayoutSetBranchImpl.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
109                            new String[] { Long.class.getName() },
110                            LayoutSetBranchModelImpl.GROUPID_COLUMN_BITMASK |
111                            LayoutSetBranchModelImpl.NAME_COLUMN_BITMASK);
112            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
113                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
114                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
115                            new String[] { Long.class.getName() });
116    
117            /**
118             * Returns all the layout set branchs where groupId = &#63;.
119             *
120             * @param groupId the group ID
121             * @return the matching layout set branchs
122             */
123            @Override
124            public List<LayoutSetBranch> findByGroupId(long groupId) {
125                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
126            }
127    
128            /**
129             * Returns a range of all the layout set branchs where groupId = &#63;.
130             *
131             * <p>
132             * 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 LayoutSetBranchModelImpl}. 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.
133             * </p>
134             *
135             * @param groupId the group ID
136             * @param start the lower bound of the range of layout set branchs
137             * @param end the upper bound of the range of layout set branchs (not inclusive)
138             * @return the range of matching layout set branchs
139             */
140            @Override
141            public List<LayoutSetBranch> findByGroupId(long groupId, int start, int end) {
142                    return findByGroupId(groupId, start, end, null);
143            }
144    
145            /**
146             * Returns an ordered range of all the layout set branchs where groupId = &#63;.
147             *
148             * <p>
149             * 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 LayoutSetBranchModelImpl}. 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.
150             * </p>
151             *
152             * @param groupId the group ID
153             * @param start the lower bound of the range of layout set branchs
154             * @param end the upper bound of the range of layout set branchs (not inclusive)
155             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
156             * @return the ordered range of matching layout set branchs
157             */
158            @Override
159            public List<LayoutSetBranch> findByGroupId(long groupId, int start,
160                    int end, OrderByComparator<LayoutSetBranch> orderByComparator) {
161                    return findByGroupId(groupId, start, end, orderByComparator, true);
162            }
163    
164            /**
165             * Returns an ordered range of all the layout set branchs where groupId = &#63;.
166             *
167             * <p>
168             * 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 LayoutSetBranchModelImpl}. 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.
169             * </p>
170             *
171             * @param groupId the group ID
172             * @param start the lower bound of the range of layout set branchs
173             * @param end the upper bound of the range of layout set branchs (not inclusive)
174             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
175             * @param retrieveFromCache whether to retrieve from the finder cache
176             * @return the ordered range of matching layout set branchs
177             */
178            @Override
179            public List<LayoutSetBranch> findByGroupId(long groupId, int start,
180                    int end, OrderByComparator<LayoutSetBranch> orderByComparator,
181                    boolean retrieveFromCache) {
182                    boolean pagination = true;
183                    FinderPath finderPath = null;
184                    Object[] finderArgs = null;
185    
186                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
187                                    (orderByComparator == null)) {
188                            pagination = false;
189                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
190                            finderArgs = new Object[] { groupId };
191                    }
192                    else {
193                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
194                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
195                    }
196    
197                    List<LayoutSetBranch> list = null;
198    
199                    if (retrieveFromCache) {
200                            list = (List<LayoutSetBranch>)finderCache.getResult(finderPath,
201                                            finderArgs, this);
202    
203                            if ((list != null) && !list.isEmpty()) {
204                                    for (LayoutSetBranch layoutSetBranch : list) {
205                                            if ((groupId != layoutSetBranch.getGroupId())) {
206                                                    list = null;
207    
208                                                    break;
209                                            }
210                                    }
211                            }
212                    }
213    
214                    if (list == null) {
215                            StringBundler query = null;
216    
217                            if (orderByComparator != null) {
218                                    query = new StringBundler(3 +
219                                                    (orderByComparator.getOrderByFields().length * 3));
220                            }
221                            else {
222                                    query = new StringBundler(3);
223                            }
224    
225                            query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
226    
227                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
228    
229                            if (orderByComparator != null) {
230                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
231                                            orderByComparator);
232                            }
233                            else
234                             if (pagination) {
235                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
236                            }
237    
238                            String sql = query.toString();
239    
240                            Session session = null;
241    
242                            try {
243                                    session = openSession();
244    
245                                    Query q = session.createQuery(sql);
246    
247                                    QueryPos qPos = QueryPos.getInstance(q);
248    
249                                    qPos.add(groupId);
250    
251                                    if (!pagination) {
252                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
253                                                            getDialect(), start, end, false);
254    
255                                            Collections.sort(list);
256    
257                                            list = Collections.unmodifiableList(list);
258                                    }
259                                    else {
260                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
261                                                            getDialect(), start, end);
262                                    }
263    
264                                    cacheResult(list);
265    
266                                    finderCache.putResult(finderPath, finderArgs, list);
267                            }
268                            catch (Exception e) {
269                                    finderCache.removeResult(finderPath, finderArgs);
270    
271                                    throw processException(e);
272                            }
273                            finally {
274                                    closeSession(session);
275                            }
276                    }
277    
278                    return list;
279            }
280    
281            /**
282             * Returns the first layout set branch in the ordered set where groupId = &#63;.
283             *
284             * @param groupId the group ID
285             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
286             * @return the first matching layout set branch
287             * @throws NoSuchLayoutSetBranchException if a matching layout set branch could not be found
288             */
289            @Override
290            public LayoutSetBranch findByGroupId_First(long groupId,
291                    OrderByComparator<LayoutSetBranch> orderByComparator)
292                    throws NoSuchLayoutSetBranchException {
293                    LayoutSetBranch layoutSetBranch = fetchByGroupId_First(groupId,
294                                    orderByComparator);
295    
296                    if (layoutSetBranch != null) {
297                            return layoutSetBranch;
298                    }
299    
300                    StringBundler msg = new StringBundler(4);
301    
302                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
303    
304                    msg.append("groupId=");
305                    msg.append(groupId);
306    
307                    msg.append(StringPool.CLOSE_CURLY_BRACE);
308    
309                    throw new NoSuchLayoutSetBranchException(msg.toString());
310            }
311    
312            /**
313             * Returns the first layout set branch in the ordered set where groupId = &#63;.
314             *
315             * @param groupId the group ID
316             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
317             * @return the first matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
318             */
319            @Override
320            public LayoutSetBranch fetchByGroupId_First(long groupId,
321                    OrderByComparator<LayoutSetBranch> orderByComparator) {
322                    List<LayoutSetBranch> list = findByGroupId(groupId, 0, 1,
323                                    orderByComparator);
324    
325                    if (!list.isEmpty()) {
326                            return list.get(0);
327                    }
328    
329                    return null;
330            }
331    
332            /**
333             * Returns the last layout set branch in the ordered set where groupId = &#63;.
334             *
335             * @param groupId the group ID
336             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
337             * @return the last matching layout set branch
338             * @throws NoSuchLayoutSetBranchException if a matching layout set branch could not be found
339             */
340            @Override
341            public LayoutSetBranch findByGroupId_Last(long groupId,
342                    OrderByComparator<LayoutSetBranch> orderByComparator)
343                    throws NoSuchLayoutSetBranchException {
344                    LayoutSetBranch layoutSetBranch = fetchByGroupId_Last(groupId,
345                                    orderByComparator);
346    
347                    if (layoutSetBranch != null) {
348                            return layoutSetBranch;
349                    }
350    
351                    StringBundler msg = new StringBundler(4);
352    
353                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
354    
355                    msg.append("groupId=");
356                    msg.append(groupId);
357    
358                    msg.append(StringPool.CLOSE_CURLY_BRACE);
359    
360                    throw new NoSuchLayoutSetBranchException(msg.toString());
361            }
362    
363            /**
364             * Returns the last layout set branch in the ordered set where groupId = &#63;.
365             *
366             * @param groupId the group ID
367             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
368             * @return the last matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
369             */
370            @Override
371            public LayoutSetBranch fetchByGroupId_Last(long groupId,
372                    OrderByComparator<LayoutSetBranch> orderByComparator) {
373                    int count = countByGroupId(groupId);
374    
375                    if (count == 0) {
376                            return null;
377                    }
378    
379                    List<LayoutSetBranch> list = findByGroupId(groupId, count - 1, count,
380                                    orderByComparator);
381    
382                    if (!list.isEmpty()) {
383                            return list.get(0);
384                    }
385    
386                    return null;
387            }
388    
389            /**
390             * Returns the layout set branchs before and after the current layout set branch in the ordered set where groupId = &#63;.
391             *
392             * @param layoutSetBranchId the primary key of the current layout set branch
393             * @param groupId the group ID
394             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
395             * @return the previous, current, and next layout set branch
396             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
397             */
398            @Override
399            public LayoutSetBranch[] findByGroupId_PrevAndNext(long layoutSetBranchId,
400                    long groupId, OrderByComparator<LayoutSetBranch> orderByComparator)
401                    throws NoSuchLayoutSetBranchException {
402                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
403    
404                    Session session = null;
405    
406                    try {
407                            session = openSession();
408    
409                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
410    
411                            array[0] = getByGroupId_PrevAndNext(session, layoutSetBranch,
412                                            groupId, orderByComparator, true);
413    
414                            array[1] = layoutSetBranch;
415    
416                            array[2] = getByGroupId_PrevAndNext(session, layoutSetBranch,
417                                            groupId, orderByComparator, false);
418    
419                            return array;
420                    }
421                    catch (Exception e) {
422                            throw processException(e);
423                    }
424                    finally {
425                            closeSession(session);
426                    }
427            }
428    
429            protected LayoutSetBranch getByGroupId_PrevAndNext(Session session,
430                    LayoutSetBranch layoutSetBranch, long groupId,
431                    OrderByComparator<LayoutSetBranch> orderByComparator, boolean previous) {
432                    StringBundler query = null;
433    
434                    if (orderByComparator != null) {
435                            query = new StringBundler(6 +
436                                            (orderByComparator.getOrderByFields().length * 6));
437                    }
438                    else {
439                            query = new StringBundler(3);
440                    }
441    
442                    query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
443    
444                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
445    
446                    if (orderByComparator != null) {
447                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
448    
449                            if (orderByConditionFields.length > 0) {
450                                    query.append(WHERE_AND);
451                            }
452    
453                            for (int i = 0; i < orderByConditionFields.length; i++) {
454                                    query.append(_ORDER_BY_ENTITY_ALIAS);
455                                    query.append(orderByConditionFields[i]);
456    
457                                    if ((i + 1) < orderByConditionFields.length) {
458                                            if (orderByComparator.isAscending() ^ previous) {
459                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
460                                            }
461                                            else {
462                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
463                                            }
464                                    }
465                                    else {
466                                            if (orderByComparator.isAscending() ^ previous) {
467                                                    query.append(WHERE_GREATER_THAN);
468                                            }
469                                            else {
470                                                    query.append(WHERE_LESSER_THAN);
471                                            }
472                                    }
473                            }
474    
475                            query.append(ORDER_BY_CLAUSE);
476    
477                            String[] orderByFields = orderByComparator.getOrderByFields();
478    
479                            for (int i = 0; i < orderByFields.length; i++) {
480                                    query.append(_ORDER_BY_ENTITY_ALIAS);
481                                    query.append(orderByFields[i]);
482    
483                                    if ((i + 1) < orderByFields.length) {
484                                            if (orderByComparator.isAscending() ^ previous) {
485                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
486                                            }
487                                            else {
488                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
489                                            }
490                                    }
491                                    else {
492                                            if (orderByComparator.isAscending() ^ previous) {
493                                                    query.append(ORDER_BY_ASC);
494                                            }
495                                            else {
496                                                    query.append(ORDER_BY_DESC);
497                                            }
498                                    }
499                            }
500                    }
501                    else {
502                            query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
503                    }
504    
505                    String sql = query.toString();
506    
507                    Query q = session.createQuery(sql);
508    
509                    q.setFirstResult(0);
510                    q.setMaxResults(2);
511    
512                    QueryPos qPos = QueryPos.getInstance(q);
513    
514                    qPos.add(groupId);
515    
516                    if (orderByComparator != null) {
517                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
518    
519                            for (Object value : values) {
520                                    qPos.add(value);
521                            }
522                    }
523    
524                    List<LayoutSetBranch> list = q.list();
525    
526                    if (list.size() == 2) {
527                            return list.get(1);
528                    }
529                    else {
530                            return null;
531                    }
532            }
533    
534            /**
535             * Returns all the layout set branchs that the user has permission to view where groupId = &#63;.
536             *
537             * @param groupId the group ID
538             * @return the matching layout set branchs that the user has permission to view
539             */
540            @Override
541            public List<LayoutSetBranch> filterFindByGroupId(long groupId) {
542                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
543                            QueryUtil.ALL_POS, null);
544            }
545    
546            /**
547             * Returns a range of all the layout set branchs that the user has permission to view where groupId = &#63;.
548             *
549             * <p>
550             * 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 LayoutSetBranchModelImpl}. 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.
551             * </p>
552             *
553             * @param groupId the group ID
554             * @param start the lower bound of the range of layout set branchs
555             * @param end the upper bound of the range of layout set branchs (not inclusive)
556             * @return the range of matching layout set branchs that the user has permission to view
557             */
558            @Override
559            public List<LayoutSetBranch> filterFindByGroupId(long groupId, int start,
560                    int end) {
561                    return filterFindByGroupId(groupId, start, end, null);
562            }
563    
564            /**
565             * Returns an ordered range of all the layout set branchs that the user has permissions to view where groupId = &#63;.
566             *
567             * <p>
568             * 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 LayoutSetBranchModelImpl}. 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.
569             * </p>
570             *
571             * @param groupId the group ID
572             * @param start the lower bound of the range of layout set branchs
573             * @param end the upper bound of the range of layout set branchs (not inclusive)
574             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
575             * @return the ordered range of matching layout set branchs that the user has permission to view
576             */
577            @Override
578            public List<LayoutSetBranch> filterFindByGroupId(long groupId, int start,
579                    int end, OrderByComparator<LayoutSetBranch> orderByComparator) {
580                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
581                            return findByGroupId(groupId, start, end, orderByComparator);
582                    }
583    
584                    StringBundler query = null;
585    
586                    if (orderByComparator != null) {
587                            query = new StringBundler(3 +
588                                            (orderByComparator.getOrderByFields().length * 3));
589                    }
590                    else {
591                            query = new StringBundler(3);
592                    }
593    
594                    if (getDB().isSupportsInlineDistinct()) {
595                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
596                    }
597                    else {
598                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
599                    }
600    
601                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
602    
603                    if (!getDB().isSupportsInlineDistinct()) {
604                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
605                    }
606    
607                    if (orderByComparator != null) {
608                            if (getDB().isSupportsInlineDistinct()) {
609                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
610                                            orderByComparator, true);
611                            }
612                            else {
613                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
614                                            orderByComparator, true);
615                            }
616                    }
617                    else {
618                            if (getDB().isSupportsInlineDistinct()) {
619                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
620                            }
621                            else {
622                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
623                            }
624                    }
625    
626                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
627                                    LayoutSetBranch.class.getName(),
628                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
629    
630                    Session session = null;
631    
632                    try {
633                            session = openSession();
634    
635                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
636    
637                            if (getDB().isSupportsInlineDistinct()) {
638                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
639                            }
640                            else {
641                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
642                            }
643    
644                            QueryPos qPos = QueryPos.getInstance(q);
645    
646                            qPos.add(groupId);
647    
648                            return (List<LayoutSetBranch>)QueryUtil.list(q, getDialect(),
649                                    start, end);
650                    }
651                    catch (Exception e) {
652                            throw processException(e);
653                    }
654                    finally {
655                            closeSession(session);
656                    }
657            }
658    
659            /**
660             * Returns the layout set branchs before and after the current layout set branch in the ordered set of layout set branchs that the user has permission to view where groupId = &#63;.
661             *
662             * @param layoutSetBranchId the primary key of the current layout set branch
663             * @param groupId the group ID
664             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
665             * @return the previous, current, and next layout set branch
666             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
667             */
668            @Override
669            public LayoutSetBranch[] filterFindByGroupId_PrevAndNext(
670                    long layoutSetBranchId, long groupId,
671                    OrderByComparator<LayoutSetBranch> orderByComparator)
672                    throws NoSuchLayoutSetBranchException {
673                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
674                            return findByGroupId_PrevAndNext(layoutSetBranchId, groupId,
675                                    orderByComparator);
676                    }
677    
678                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
679    
680                    Session session = null;
681    
682                    try {
683                            session = openSession();
684    
685                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
686    
687                            array[0] = filterGetByGroupId_PrevAndNext(session, layoutSetBranch,
688                                            groupId, orderByComparator, true);
689    
690                            array[1] = layoutSetBranch;
691    
692                            array[2] = filterGetByGroupId_PrevAndNext(session, layoutSetBranch,
693                                            groupId, orderByComparator, false);
694    
695                            return array;
696                    }
697                    catch (Exception e) {
698                            throw processException(e);
699                    }
700                    finally {
701                            closeSession(session);
702                    }
703            }
704    
705            protected LayoutSetBranch filterGetByGroupId_PrevAndNext(Session session,
706                    LayoutSetBranch layoutSetBranch, long groupId,
707                    OrderByComparator<LayoutSetBranch> orderByComparator, boolean previous) {
708                    StringBundler query = null;
709    
710                    if (orderByComparator != null) {
711                            query = new StringBundler(6 +
712                                            (orderByComparator.getOrderByFields().length * 6));
713                    }
714                    else {
715                            query = new StringBundler(3);
716                    }
717    
718                    if (getDB().isSupportsInlineDistinct()) {
719                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
720                    }
721                    else {
722                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
723                    }
724    
725                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
726    
727                    if (!getDB().isSupportsInlineDistinct()) {
728                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
729                    }
730    
731                    if (orderByComparator != null) {
732                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
733    
734                            if (orderByConditionFields.length > 0) {
735                                    query.append(WHERE_AND);
736                            }
737    
738                            for (int i = 0; i < orderByConditionFields.length; i++) {
739                                    if (getDB().isSupportsInlineDistinct()) {
740                                            query.append(_ORDER_BY_ENTITY_ALIAS);
741                                    }
742                                    else {
743                                            query.append(_ORDER_BY_ENTITY_TABLE);
744                                    }
745    
746                                    query.append(orderByConditionFields[i]);
747    
748                                    if ((i + 1) < orderByConditionFields.length) {
749                                            if (orderByComparator.isAscending() ^ previous) {
750                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
751                                            }
752                                            else {
753                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
754                                            }
755                                    }
756                                    else {
757                                            if (orderByComparator.isAscending() ^ previous) {
758                                                    query.append(WHERE_GREATER_THAN);
759                                            }
760                                            else {
761                                                    query.append(WHERE_LESSER_THAN);
762                                            }
763                                    }
764                            }
765    
766                            query.append(ORDER_BY_CLAUSE);
767    
768                            String[] orderByFields = orderByComparator.getOrderByFields();
769    
770                            for (int i = 0; i < orderByFields.length; i++) {
771                                    if (getDB().isSupportsInlineDistinct()) {
772                                            query.append(_ORDER_BY_ENTITY_ALIAS);
773                                    }
774                                    else {
775                                            query.append(_ORDER_BY_ENTITY_TABLE);
776                                    }
777    
778                                    query.append(orderByFields[i]);
779    
780                                    if ((i + 1) < orderByFields.length) {
781                                            if (orderByComparator.isAscending() ^ previous) {
782                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
783                                            }
784                                            else {
785                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
786                                            }
787                                    }
788                                    else {
789                                            if (orderByComparator.isAscending() ^ previous) {
790                                                    query.append(ORDER_BY_ASC);
791                                            }
792                                            else {
793                                                    query.append(ORDER_BY_DESC);
794                                            }
795                                    }
796                            }
797                    }
798                    else {
799                            if (getDB().isSupportsInlineDistinct()) {
800                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
801                            }
802                            else {
803                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
804                            }
805                    }
806    
807                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
808                                    LayoutSetBranch.class.getName(),
809                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
810    
811                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
812    
813                    q.setFirstResult(0);
814                    q.setMaxResults(2);
815    
816                    if (getDB().isSupportsInlineDistinct()) {
817                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
818                    }
819                    else {
820                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
821                    }
822    
823                    QueryPos qPos = QueryPos.getInstance(q);
824    
825                    qPos.add(groupId);
826    
827                    if (orderByComparator != null) {
828                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
829    
830                            for (Object value : values) {
831                                    qPos.add(value);
832                            }
833                    }
834    
835                    List<LayoutSetBranch> list = q.list();
836    
837                    if (list.size() == 2) {
838                            return list.get(1);
839                    }
840                    else {
841                            return null;
842                    }
843            }
844    
845            /**
846             * Removes all the layout set branchs where groupId = &#63; from the database.
847             *
848             * @param groupId the group ID
849             */
850            @Override
851            public void removeByGroupId(long groupId) {
852                    for (LayoutSetBranch layoutSetBranch : findByGroupId(groupId,
853                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
854                            remove(layoutSetBranch);
855                    }
856            }
857    
858            /**
859             * Returns the number of layout set branchs where groupId = &#63;.
860             *
861             * @param groupId the group ID
862             * @return the number of matching layout set branchs
863             */
864            @Override
865            public int countByGroupId(long groupId) {
866                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
867    
868                    Object[] finderArgs = new Object[] { groupId };
869    
870                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
871    
872                    if (count == null) {
873                            StringBundler query = new StringBundler(2);
874    
875                            query.append(_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
876    
877                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
878    
879                            String sql = query.toString();
880    
881                            Session session = null;
882    
883                            try {
884                                    session = openSession();
885    
886                                    Query q = session.createQuery(sql);
887    
888                                    QueryPos qPos = QueryPos.getInstance(q);
889    
890                                    qPos.add(groupId);
891    
892                                    count = (Long)q.uniqueResult();
893    
894                                    finderCache.putResult(finderPath, finderArgs, count);
895                            }
896                            catch (Exception e) {
897                                    finderCache.removeResult(finderPath, finderArgs);
898    
899                                    throw processException(e);
900                            }
901                            finally {
902                                    closeSession(session);
903                            }
904                    }
905    
906                    return count.intValue();
907            }
908    
909            /**
910             * Returns the number of layout set branchs that the user has permission to view where groupId = &#63;.
911             *
912             * @param groupId the group ID
913             * @return the number of matching layout set branchs that the user has permission to view
914             */
915            @Override
916            public int filterCountByGroupId(long groupId) {
917                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
918                            return countByGroupId(groupId);
919                    }
920    
921                    StringBundler query = new StringBundler(2);
922    
923                    query.append(_FILTER_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
924    
925                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
926    
927                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
928                                    LayoutSetBranch.class.getName(),
929                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
930    
931                    Session session = null;
932    
933                    try {
934                            session = openSession();
935    
936                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
937    
938                            q.addScalar(COUNT_COLUMN_NAME,
939                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
940    
941                            QueryPos qPos = QueryPos.getInstance(q);
942    
943                            qPos.add(groupId);
944    
945                            Long count = (Long)q.uniqueResult();
946    
947                            return count.intValue();
948                    }
949                    catch (Exception e) {
950                            throw processException(e);
951                    }
952                    finally {
953                            closeSession(session);
954                    }
955            }
956    
957            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "layoutSetBranch.groupId = ?";
958            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
959                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
960                            LayoutSetBranchImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
961                            "findByG_P",
962                            new String[] {
963                                    Long.class.getName(), Boolean.class.getName(),
964                                    
965                            Integer.class.getName(), Integer.class.getName(),
966                                    OrderByComparator.class.getName()
967                            });
968            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
969                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
970                            LayoutSetBranchImpl.class,
971                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
972                            new String[] { Long.class.getName(), Boolean.class.getName() },
973                            LayoutSetBranchModelImpl.GROUPID_COLUMN_BITMASK |
974                            LayoutSetBranchModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
975                            LayoutSetBranchModelImpl.NAME_COLUMN_BITMASK);
976            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
977                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
978                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
979                            new String[] { Long.class.getName(), Boolean.class.getName() });
980    
981            /**
982             * Returns all the layout set branchs where groupId = &#63; and privateLayout = &#63;.
983             *
984             * @param groupId the group ID
985             * @param privateLayout the private layout
986             * @return the matching layout set branchs
987             */
988            @Override
989            public List<LayoutSetBranch> findByG_P(long groupId, boolean privateLayout) {
990                    return findByG_P(groupId, privateLayout, QueryUtil.ALL_POS,
991                            QueryUtil.ALL_POS, null);
992            }
993    
994            /**
995             * Returns a range of all the layout set branchs where groupId = &#63; and privateLayout = &#63;.
996             *
997             * <p>
998             * 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 LayoutSetBranchModelImpl}. 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.
999             * </p>
1000             *
1001             * @param groupId the group ID
1002             * @param privateLayout the private layout
1003             * @param start the lower bound of the range of layout set branchs
1004             * @param end the upper bound of the range of layout set branchs (not inclusive)
1005             * @return the range of matching layout set branchs
1006             */
1007            @Override
1008            public List<LayoutSetBranch> findByG_P(long groupId, boolean privateLayout,
1009                    int start, int end) {
1010                    return findByG_P(groupId, privateLayout, start, end, null);
1011            }
1012    
1013            /**
1014             * Returns an ordered range of all the layout set branchs where groupId = &#63; and privateLayout = &#63;.
1015             *
1016             * <p>
1017             * 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 LayoutSetBranchModelImpl}. 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.
1018             * </p>
1019             *
1020             * @param groupId the group ID
1021             * @param privateLayout the private layout
1022             * @param start the lower bound of the range of layout set branchs
1023             * @param end the upper bound of the range of layout set branchs (not inclusive)
1024             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1025             * @return the ordered range of matching layout set branchs
1026             */
1027            @Override
1028            public List<LayoutSetBranch> findByG_P(long groupId, boolean privateLayout,
1029                    int start, int end, OrderByComparator<LayoutSetBranch> orderByComparator) {
1030                    return findByG_P(groupId, privateLayout, start, end, orderByComparator,
1031                            true);
1032            }
1033    
1034            /**
1035             * Returns an ordered range of all the layout set branchs where groupId = &#63; and privateLayout = &#63;.
1036             *
1037             * <p>
1038             * 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 LayoutSetBranchModelImpl}. 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.
1039             * </p>
1040             *
1041             * @param groupId the group ID
1042             * @param privateLayout the private layout
1043             * @param start the lower bound of the range of layout set branchs
1044             * @param end the upper bound of the range of layout set branchs (not inclusive)
1045             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1046             * @param retrieveFromCache whether to retrieve from the finder cache
1047             * @return the ordered range of matching layout set branchs
1048             */
1049            @Override
1050            public List<LayoutSetBranch> findByG_P(long groupId, boolean privateLayout,
1051                    int start, int end,
1052                    OrderByComparator<LayoutSetBranch> orderByComparator,
1053                    boolean retrieveFromCache) {
1054                    boolean pagination = true;
1055                    FinderPath finderPath = null;
1056                    Object[] finderArgs = null;
1057    
1058                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1059                                    (orderByComparator == null)) {
1060                            pagination = false;
1061                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
1062                            finderArgs = new Object[] { groupId, privateLayout };
1063                    }
1064                    else {
1065                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
1066                            finderArgs = new Object[] {
1067                                            groupId, privateLayout,
1068                                            
1069                                            start, end, orderByComparator
1070                                    };
1071                    }
1072    
1073                    List<LayoutSetBranch> list = null;
1074    
1075                    if (retrieveFromCache) {
1076                            list = (List<LayoutSetBranch>)finderCache.getResult(finderPath,
1077                                            finderArgs, this);
1078    
1079                            if ((list != null) && !list.isEmpty()) {
1080                                    for (LayoutSetBranch layoutSetBranch : list) {
1081                                            if ((groupId != layoutSetBranch.getGroupId()) ||
1082                                                            (privateLayout != layoutSetBranch.getPrivateLayout())) {
1083                                                    list = null;
1084    
1085                                                    break;
1086                                            }
1087                                    }
1088                            }
1089                    }
1090    
1091                    if (list == null) {
1092                            StringBundler query = null;
1093    
1094                            if (orderByComparator != null) {
1095                                    query = new StringBundler(4 +
1096                                                    (orderByComparator.getOrderByFields().length * 3));
1097                            }
1098                            else {
1099                                    query = new StringBundler(4);
1100                            }
1101    
1102                            query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
1103    
1104                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1105    
1106                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1107    
1108                            if (orderByComparator != null) {
1109                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1110                                            orderByComparator);
1111                            }
1112                            else
1113                             if (pagination) {
1114                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
1115                            }
1116    
1117                            String sql = query.toString();
1118    
1119                            Session session = null;
1120    
1121                            try {
1122                                    session = openSession();
1123    
1124                                    Query q = session.createQuery(sql);
1125    
1126                                    QueryPos qPos = QueryPos.getInstance(q);
1127    
1128                                    qPos.add(groupId);
1129    
1130                                    qPos.add(privateLayout);
1131    
1132                                    if (!pagination) {
1133                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
1134                                                            getDialect(), start, end, false);
1135    
1136                                            Collections.sort(list);
1137    
1138                                            list = Collections.unmodifiableList(list);
1139                                    }
1140                                    else {
1141                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
1142                                                            getDialect(), start, end);
1143                                    }
1144    
1145                                    cacheResult(list);
1146    
1147                                    finderCache.putResult(finderPath, finderArgs, list);
1148                            }
1149                            catch (Exception e) {
1150                                    finderCache.removeResult(finderPath, finderArgs);
1151    
1152                                    throw processException(e);
1153                            }
1154                            finally {
1155                                    closeSession(session);
1156                            }
1157                    }
1158    
1159                    return list;
1160            }
1161    
1162            /**
1163             * Returns the first layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63;.
1164             *
1165             * @param groupId the group ID
1166             * @param privateLayout the private layout
1167             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1168             * @return the first matching layout set branch
1169             * @throws NoSuchLayoutSetBranchException if a matching layout set branch could not be found
1170             */
1171            @Override
1172            public LayoutSetBranch findByG_P_First(long groupId, boolean privateLayout,
1173                    OrderByComparator<LayoutSetBranch> orderByComparator)
1174                    throws NoSuchLayoutSetBranchException {
1175                    LayoutSetBranch layoutSetBranch = fetchByG_P_First(groupId,
1176                                    privateLayout, orderByComparator);
1177    
1178                    if (layoutSetBranch != null) {
1179                            return layoutSetBranch;
1180                    }
1181    
1182                    StringBundler msg = new StringBundler(6);
1183    
1184                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1185    
1186                    msg.append("groupId=");
1187                    msg.append(groupId);
1188    
1189                    msg.append(", privateLayout=");
1190                    msg.append(privateLayout);
1191    
1192                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1193    
1194                    throw new NoSuchLayoutSetBranchException(msg.toString());
1195            }
1196    
1197            /**
1198             * Returns the first layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63;.
1199             *
1200             * @param groupId the group ID
1201             * @param privateLayout the private layout
1202             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1203             * @return the first matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
1204             */
1205            @Override
1206            public LayoutSetBranch fetchByG_P_First(long groupId,
1207                    boolean privateLayout,
1208                    OrderByComparator<LayoutSetBranch> orderByComparator) {
1209                    List<LayoutSetBranch> list = findByG_P(groupId, privateLayout, 0, 1,
1210                                    orderByComparator);
1211    
1212                    if (!list.isEmpty()) {
1213                            return list.get(0);
1214                    }
1215    
1216                    return null;
1217            }
1218    
1219            /**
1220             * Returns the last layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63;.
1221             *
1222             * @param groupId the group ID
1223             * @param privateLayout the private layout
1224             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1225             * @return the last matching layout set branch
1226             * @throws NoSuchLayoutSetBranchException if a matching layout set branch could not be found
1227             */
1228            @Override
1229            public LayoutSetBranch findByG_P_Last(long groupId, boolean privateLayout,
1230                    OrderByComparator<LayoutSetBranch> orderByComparator)
1231                    throws NoSuchLayoutSetBranchException {
1232                    LayoutSetBranch layoutSetBranch = fetchByG_P_Last(groupId,
1233                                    privateLayout, orderByComparator);
1234    
1235                    if (layoutSetBranch != null) {
1236                            return layoutSetBranch;
1237                    }
1238    
1239                    StringBundler msg = new StringBundler(6);
1240    
1241                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1242    
1243                    msg.append("groupId=");
1244                    msg.append(groupId);
1245    
1246                    msg.append(", privateLayout=");
1247                    msg.append(privateLayout);
1248    
1249                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1250    
1251                    throw new NoSuchLayoutSetBranchException(msg.toString());
1252            }
1253    
1254            /**
1255             * Returns the last layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63;.
1256             *
1257             * @param groupId the group ID
1258             * @param privateLayout the private layout
1259             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1260             * @return the last matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
1261             */
1262            @Override
1263            public LayoutSetBranch fetchByG_P_Last(long groupId, boolean privateLayout,
1264                    OrderByComparator<LayoutSetBranch> orderByComparator) {
1265                    int count = countByG_P(groupId, privateLayout);
1266    
1267                    if (count == 0) {
1268                            return null;
1269                    }
1270    
1271                    List<LayoutSetBranch> list = findByG_P(groupId, privateLayout,
1272                                    count - 1, count, orderByComparator);
1273    
1274                    if (!list.isEmpty()) {
1275                            return list.get(0);
1276                    }
1277    
1278                    return null;
1279            }
1280    
1281            /**
1282             * Returns the layout set branchs before and after the current layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63;.
1283             *
1284             * @param layoutSetBranchId the primary key of the current layout set branch
1285             * @param groupId the group ID
1286             * @param privateLayout the private layout
1287             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1288             * @return the previous, current, and next layout set branch
1289             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
1290             */
1291            @Override
1292            public LayoutSetBranch[] findByG_P_PrevAndNext(long layoutSetBranchId,
1293                    long groupId, boolean privateLayout,
1294                    OrderByComparator<LayoutSetBranch> orderByComparator)
1295                    throws NoSuchLayoutSetBranchException {
1296                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
1297    
1298                    Session session = null;
1299    
1300                    try {
1301                            session = openSession();
1302    
1303                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
1304    
1305                            array[0] = getByG_P_PrevAndNext(session, layoutSetBranch, groupId,
1306                                            privateLayout, orderByComparator, true);
1307    
1308                            array[1] = layoutSetBranch;
1309    
1310                            array[2] = getByG_P_PrevAndNext(session, layoutSetBranch, groupId,
1311                                            privateLayout, orderByComparator, false);
1312    
1313                            return array;
1314                    }
1315                    catch (Exception e) {
1316                            throw processException(e);
1317                    }
1318                    finally {
1319                            closeSession(session);
1320                    }
1321            }
1322    
1323            protected LayoutSetBranch getByG_P_PrevAndNext(Session session,
1324                    LayoutSetBranch layoutSetBranch, long groupId, boolean privateLayout,
1325                    OrderByComparator<LayoutSetBranch> orderByComparator, boolean previous) {
1326                    StringBundler query = null;
1327    
1328                    if (orderByComparator != null) {
1329                            query = new StringBundler(6 +
1330                                            (orderByComparator.getOrderByFields().length * 6));
1331                    }
1332                    else {
1333                            query = new StringBundler(3);
1334                    }
1335    
1336                    query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
1337    
1338                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1339    
1340                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1341    
1342                    if (orderByComparator != null) {
1343                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1344    
1345                            if (orderByConditionFields.length > 0) {
1346                                    query.append(WHERE_AND);
1347                            }
1348    
1349                            for (int i = 0; i < orderByConditionFields.length; i++) {
1350                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1351                                    query.append(orderByConditionFields[i]);
1352    
1353                                    if ((i + 1) < orderByConditionFields.length) {
1354                                            if (orderByComparator.isAscending() ^ previous) {
1355                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1356                                            }
1357                                            else {
1358                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1359                                            }
1360                                    }
1361                                    else {
1362                                            if (orderByComparator.isAscending() ^ previous) {
1363                                                    query.append(WHERE_GREATER_THAN);
1364                                            }
1365                                            else {
1366                                                    query.append(WHERE_LESSER_THAN);
1367                                            }
1368                                    }
1369                            }
1370    
1371                            query.append(ORDER_BY_CLAUSE);
1372    
1373                            String[] orderByFields = orderByComparator.getOrderByFields();
1374    
1375                            for (int i = 0; i < orderByFields.length; i++) {
1376                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1377                                    query.append(orderByFields[i]);
1378    
1379                                    if ((i + 1) < orderByFields.length) {
1380                                            if (orderByComparator.isAscending() ^ previous) {
1381                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1382                                            }
1383                                            else {
1384                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1385                                            }
1386                                    }
1387                                    else {
1388                                            if (orderByComparator.isAscending() ^ previous) {
1389                                                    query.append(ORDER_BY_ASC);
1390                                            }
1391                                            else {
1392                                                    query.append(ORDER_BY_DESC);
1393                                            }
1394                                    }
1395                            }
1396                    }
1397                    else {
1398                            query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
1399                    }
1400    
1401                    String sql = query.toString();
1402    
1403                    Query q = session.createQuery(sql);
1404    
1405                    q.setFirstResult(0);
1406                    q.setMaxResults(2);
1407    
1408                    QueryPos qPos = QueryPos.getInstance(q);
1409    
1410                    qPos.add(groupId);
1411    
1412                    qPos.add(privateLayout);
1413    
1414                    if (orderByComparator != null) {
1415                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
1416    
1417                            for (Object value : values) {
1418                                    qPos.add(value);
1419                            }
1420                    }
1421    
1422                    List<LayoutSetBranch> list = q.list();
1423    
1424                    if (list.size() == 2) {
1425                            return list.get(1);
1426                    }
1427                    else {
1428                            return null;
1429                    }
1430            }
1431    
1432            /**
1433             * Returns all the layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
1434             *
1435             * @param groupId the group ID
1436             * @param privateLayout the private layout
1437             * @return the matching layout set branchs that the user has permission to view
1438             */
1439            @Override
1440            public List<LayoutSetBranch> filterFindByG_P(long groupId,
1441                    boolean privateLayout) {
1442                    return filterFindByG_P(groupId, privateLayout, QueryUtil.ALL_POS,
1443                            QueryUtil.ALL_POS, null);
1444            }
1445    
1446            /**
1447             * Returns a range of all the layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
1448             *
1449             * <p>
1450             * 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 LayoutSetBranchModelImpl}. 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.
1451             * </p>
1452             *
1453             * @param groupId the group ID
1454             * @param privateLayout the private layout
1455             * @param start the lower bound of the range of layout set branchs
1456             * @param end the upper bound of the range of layout set branchs (not inclusive)
1457             * @return the range of matching layout set branchs that the user has permission to view
1458             */
1459            @Override
1460            public List<LayoutSetBranch> filterFindByG_P(long groupId,
1461                    boolean privateLayout, int start, int end) {
1462                    return filterFindByG_P(groupId, privateLayout, start, end, null);
1463            }
1464    
1465            /**
1466             * Returns an ordered range of all the layout set branchs that the user has permissions to view where groupId = &#63; and privateLayout = &#63;.
1467             *
1468             * <p>
1469             * 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 LayoutSetBranchModelImpl}. 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.
1470             * </p>
1471             *
1472             * @param groupId the group ID
1473             * @param privateLayout the private layout
1474             * @param start the lower bound of the range of layout set branchs
1475             * @param end the upper bound of the range of layout set branchs (not inclusive)
1476             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1477             * @return the ordered range of matching layout set branchs that the user has permission to view
1478             */
1479            @Override
1480            public List<LayoutSetBranch> filterFindByG_P(long groupId,
1481                    boolean privateLayout, int start, int end,
1482                    OrderByComparator<LayoutSetBranch> orderByComparator) {
1483                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1484                            return findByG_P(groupId, privateLayout, start, end,
1485                                    orderByComparator);
1486                    }
1487    
1488                    StringBundler query = null;
1489    
1490                    if (orderByComparator != null) {
1491                            query = new StringBundler(4 +
1492                                            (orderByComparator.getOrderByFields().length * 3));
1493                    }
1494                    else {
1495                            query = new StringBundler(4);
1496                    }
1497    
1498                    if (getDB().isSupportsInlineDistinct()) {
1499                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
1500                    }
1501                    else {
1502                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
1503                    }
1504    
1505                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1506    
1507                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1508    
1509                    if (!getDB().isSupportsInlineDistinct()) {
1510                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
1511                    }
1512    
1513                    if (orderByComparator != null) {
1514                            if (getDB().isSupportsInlineDistinct()) {
1515                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1516                                            orderByComparator, true);
1517                            }
1518                            else {
1519                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1520                                            orderByComparator, true);
1521                            }
1522                    }
1523                    else {
1524                            if (getDB().isSupportsInlineDistinct()) {
1525                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
1526                            }
1527                            else {
1528                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
1529                            }
1530                    }
1531    
1532                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1533                                    LayoutSetBranch.class.getName(),
1534                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1535    
1536                    Session session = null;
1537    
1538                    try {
1539                            session = openSession();
1540    
1541                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1542    
1543                            if (getDB().isSupportsInlineDistinct()) {
1544                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
1545                            }
1546                            else {
1547                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
1548                            }
1549    
1550                            QueryPos qPos = QueryPos.getInstance(q);
1551    
1552                            qPos.add(groupId);
1553    
1554                            qPos.add(privateLayout);
1555    
1556                            return (List<LayoutSetBranch>)QueryUtil.list(q, getDialect(),
1557                                    start, end);
1558                    }
1559                    catch (Exception e) {
1560                            throw processException(e);
1561                    }
1562                    finally {
1563                            closeSession(session);
1564                    }
1565            }
1566    
1567            /**
1568             * Returns the layout set branchs before and after the current layout set branch in the ordered set of layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
1569             *
1570             * @param layoutSetBranchId the primary key of the current layout set branch
1571             * @param groupId the group ID
1572             * @param privateLayout the private layout
1573             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1574             * @return the previous, current, and next layout set branch
1575             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
1576             */
1577            @Override
1578            public LayoutSetBranch[] filterFindByG_P_PrevAndNext(
1579                    long layoutSetBranchId, long groupId, boolean privateLayout,
1580                    OrderByComparator<LayoutSetBranch> orderByComparator)
1581                    throws NoSuchLayoutSetBranchException {
1582                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1583                            return findByG_P_PrevAndNext(layoutSetBranchId, groupId,
1584                                    privateLayout, orderByComparator);
1585                    }
1586    
1587                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
1588    
1589                    Session session = null;
1590    
1591                    try {
1592                            session = openSession();
1593    
1594                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
1595    
1596                            array[0] = filterGetByG_P_PrevAndNext(session, layoutSetBranch,
1597                                            groupId, privateLayout, orderByComparator, true);
1598    
1599                            array[1] = layoutSetBranch;
1600    
1601                            array[2] = filterGetByG_P_PrevAndNext(session, layoutSetBranch,
1602                                            groupId, privateLayout, orderByComparator, false);
1603    
1604                            return array;
1605                    }
1606                    catch (Exception e) {
1607                            throw processException(e);
1608                    }
1609                    finally {
1610                            closeSession(session);
1611                    }
1612            }
1613    
1614            protected LayoutSetBranch filterGetByG_P_PrevAndNext(Session session,
1615                    LayoutSetBranch layoutSetBranch, long groupId, boolean privateLayout,
1616                    OrderByComparator<LayoutSetBranch> orderByComparator, boolean previous) {
1617                    StringBundler query = null;
1618    
1619                    if (orderByComparator != null) {
1620                            query = new StringBundler(6 +
1621                                            (orderByComparator.getOrderByFields().length * 6));
1622                    }
1623                    else {
1624                            query = new StringBundler(3);
1625                    }
1626    
1627                    if (getDB().isSupportsInlineDistinct()) {
1628                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
1629                    }
1630                    else {
1631                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
1632                    }
1633    
1634                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1635    
1636                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1637    
1638                    if (!getDB().isSupportsInlineDistinct()) {
1639                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
1640                    }
1641    
1642                    if (orderByComparator != null) {
1643                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1644    
1645                            if (orderByConditionFields.length > 0) {
1646                                    query.append(WHERE_AND);
1647                            }
1648    
1649                            for (int i = 0; i < orderByConditionFields.length; i++) {
1650                                    if (getDB().isSupportsInlineDistinct()) {
1651                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1652                                    }
1653                                    else {
1654                                            query.append(_ORDER_BY_ENTITY_TABLE);
1655                                    }
1656    
1657                                    query.append(orderByConditionFields[i]);
1658    
1659                                    if ((i + 1) < orderByConditionFields.length) {
1660                                            if (orderByComparator.isAscending() ^ previous) {
1661                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1662                                            }
1663                                            else {
1664                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1665                                            }
1666                                    }
1667                                    else {
1668                                            if (orderByComparator.isAscending() ^ previous) {
1669                                                    query.append(WHERE_GREATER_THAN);
1670                                            }
1671                                            else {
1672                                                    query.append(WHERE_LESSER_THAN);
1673                                            }
1674                                    }
1675                            }
1676    
1677                            query.append(ORDER_BY_CLAUSE);
1678    
1679                            String[] orderByFields = orderByComparator.getOrderByFields();
1680    
1681                            for (int i = 0; i < orderByFields.length; i++) {
1682                                    if (getDB().isSupportsInlineDistinct()) {
1683                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1684                                    }
1685                                    else {
1686                                            query.append(_ORDER_BY_ENTITY_TABLE);
1687                                    }
1688    
1689                                    query.append(orderByFields[i]);
1690    
1691                                    if ((i + 1) < orderByFields.length) {
1692                                            if (orderByComparator.isAscending() ^ previous) {
1693                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1694                                            }
1695                                            else {
1696                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1697                                            }
1698                                    }
1699                                    else {
1700                                            if (orderByComparator.isAscending() ^ previous) {
1701                                                    query.append(ORDER_BY_ASC);
1702                                            }
1703                                            else {
1704                                                    query.append(ORDER_BY_DESC);
1705                                            }
1706                                    }
1707                            }
1708                    }
1709                    else {
1710                            if (getDB().isSupportsInlineDistinct()) {
1711                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
1712                            }
1713                            else {
1714                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
1715                            }
1716                    }
1717    
1718                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1719                                    LayoutSetBranch.class.getName(),
1720                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1721    
1722                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
1723    
1724                    q.setFirstResult(0);
1725                    q.setMaxResults(2);
1726    
1727                    if (getDB().isSupportsInlineDistinct()) {
1728                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
1729                    }
1730                    else {
1731                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
1732                    }
1733    
1734                    QueryPos qPos = QueryPos.getInstance(q);
1735    
1736                    qPos.add(groupId);
1737    
1738                    qPos.add(privateLayout);
1739    
1740                    if (orderByComparator != null) {
1741                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
1742    
1743                            for (Object value : values) {
1744                                    qPos.add(value);
1745                            }
1746                    }
1747    
1748                    List<LayoutSetBranch> list = q.list();
1749    
1750                    if (list.size() == 2) {
1751                            return list.get(1);
1752                    }
1753                    else {
1754                            return null;
1755                    }
1756            }
1757    
1758            /**
1759             * Removes all the layout set branchs where groupId = &#63; and privateLayout = &#63; from the database.
1760             *
1761             * @param groupId the group ID
1762             * @param privateLayout the private layout
1763             */
1764            @Override
1765            public void removeByG_P(long groupId, boolean privateLayout) {
1766                    for (LayoutSetBranch layoutSetBranch : findByG_P(groupId,
1767                                    privateLayout, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1768                            remove(layoutSetBranch);
1769                    }
1770            }
1771    
1772            /**
1773             * Returns the number of layout set branchs where groupId = &#63; and privateLayout = &#63;.
1774             *
1775             * @param groupId the group ID
1776             * @param privateLayout the private layout
1777             * @return the number of matching layout set branchs
1778             */
1779            @Override
1780            public int countByG_P(long groupId, boolean privateLayout) {
1781                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
1782    
1783                    Object[] finderArgs = new Object[] { groupId, privateLayout };
1784    
1785                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1786    
1787                    if (count == null) {
1788                            StringBundler query = new StringBundler(3);
1789    
1790                            query.append(_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
1791    
1792                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1793    
1794                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1795    
1796                            String sql = query.toString();
1797    
1798                            Session session = null;
1799    
1800                            try {
1801                                    session = openSession();
1802    
1803                                    Query q = session.createQuery(sql);
1804    
1805                                    QueryPos qPos = QueryPos.getInstance(q);
1806    
1807                                    qPos.add(groupId);
1808    
1809                                    qPos.add(privateLayout);
1810    
1811                                    count = (Long)q.uniqueResult();
1812    
1813                                    finderCache.putResult(finderPath, finderArgs, count);
1814                            }
1815                            catch (Exception e) {
1816                                    finderCache.removeResult(finderPath, finderArgs);
1817    
1818                                    throw processException(e);
1819                            }
1820                            finally {
1821                                    closeSession(session);
1822                            }
1823                    }
1824    
1825                    return count.intValue();
1826            }
1827    
1828            /**
1829             * Returns the number of layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
1830             *
1831             * @param groupId the group ID
1832             * @param privateLayout the private layout
1833             * @return the number of matching layout set branchs that the user has permission to view
1834             */
1835            @Override
1836            public int filterCountByG_P(long groupId, boolean privateLayout) {
1837                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1838                            return countByG_P(groupId, privateLayout);
1839                    }
1840    
1841                    StringBundler query = new StringBundler(3);
1842    
1843                    query.append(_FILTER_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
1844    
1845                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1846    
1847                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1848    
1849                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1850                                    LayoutSetBranch.class.getName(),
1851                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1852    
1853                    Session session = null;
1854    
1855                    try {
1856                            session = openSession();
1857    
1858                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1859    
1860                            q.addScalar(COUNT_COLUMN_NAME,
1861                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1862    
1863                            QueryPos qPos = QueryPos.getInstance(q);
1864    
1865                            qPos.add(groupId);
1866    
1867                            qPos.add(privateLayout);
1868    
1869                            Long count = (Long)q.uniqueResult();
1870    
1871                            return count.intValue();
1872                    }
1873                    catch (Exception e) {
1874                            throw processException(e);
1875                    }
1876                    finally {
1877                            closeSession(session);
1878                    }
1879            }
1880    
1881            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "layoutSetBranch.groupId = ? AND ";
1882            private static final String _FINDER_COLUMN_G_P_PRIVATELAYOUT_2 = "layoutSetBranch.privateLayout = ?";
1883            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_N = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
1884                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
1885                            LayoutSetBranchImpl.class, FINDER_CLASS_NAME_ENTITY,
1886                            "fetchByG_P_N",
1887                            new String[] {
1888                                    Long.class.getName(), Boolean.class.getName(),
1889                                    String.class.getName()
1890                            },
1891                            LayoutSetBranchModelImpl.GROUPID_COLUMN_BITMASK |
1892                            LayoutSetBranchModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
1893                            LayoutSetBranchModelImpl.NAME_COLUMN_BITMASK);
1894            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
1895                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
1896                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N",
1897                            new String[] {
1898                                    Long.class.getName(), Boolean.class.getName(),
1899                                    String.class.getName()
1900                            });
1901    
1902            /**
1903             * Returns the layout set branch where groupId = &#63; and privateLayout = &#63; and name = &#63; or throws a {@link NoSuchLayoutSetBranchException} if it could not be found.
1904             *
1905             * @param groupId the group ID
1906             * @param privateLayout the private layout
1907             * @param name the name
1908             * @return the matching layout set branch
1909             * @throws NoSuchLayoutSetBranchException if a matching layout set branch could not be found
1910             */
1911            @Override
1912            public LayoutSetBranch findByG_P_N(long groupId, boolean privateLayout,
1913                    String name) throws NoSuchLayoutSetBranchException {
1914                    LayoutSetBranch layoutSetBranch = fetchByG_P_N(groupId, privateLayout,
1915                                    name);
1916    
1917                    if (layoutSetBranch == null) {
1918                            StringBundler msg = new StringBundler(8);
1919    
1920                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1921    
1922                            msg.append("groupId=");
1923                            msg.append(groupId);
1924    
1925                            msg.append(", privateLayout=");
1926                            msg.append(privateLayout);
1927    
1928                            msg.append(", name=");
1929                            msg.append(name);
1930    
1931                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1932    
1933                            if (_log.isWarnEnabled()) {
1934                                    _log.warn(msg.toString());
1935                            }
1936    
1937                            throw new NoSuchLayoutSetBranchException(msg.toString());
1938                    }
1939    
1940                    return layoutSetBranch;
1941            }
1942    
1943            /**
1944             * Returns the layout set branch where groupId = &#63; and privateLayout = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1945             *
1946             * @param groupId the group ID
1947             * @param privateLayout the private layout
1948             * @param name the name
1949             * @return the matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
1950             */
1951            @Override
1952            public LayoutSetBranch fetchByG_P_N(long groupId, boolean privateLayout,
1953                    String name) {
1954                    return fetchByG_P_N(groupId, privateLayout, name, true);
1955            }
1956    
1957            /**
1958             * Returns the layout set branch where groupId = &#63; and privateLayout = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1959             *
1960             * @param groupId the group ID
1961             * @param privateLayout the private layout
1962             * @param name the name
1963             * @param retrieveFromCache whether to retrieve from the finder cache
1964             * @return the matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
1965             */
1966            @Override
1967            public LayoutSetBranch fetchByG_P_N(long groupId, boolean privateLayout,
1968                    String name, boolean retrieveFromCache) {
1969                    Object[] finderArgs = new Object[] { groupId, privateLayout, name };
1970    
1971                    Object result = null;
1972    
1973                    if (retrieveFromCache) {
1974                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_G_P_N,
1975                                            finderArgs, this);
1976                    }
1977    
1978                    if (result instanceof LayoutSetBranch) {
1979                            LayoutSetBranch layoutSetBranch = (LayoutSetBranch)result;
1980    
1981                            if ((groupId != layoutSetBranch.getGroupId()) ||
1982                                            (privateLayout != layoutSetBranch.getPrivateLayout()) ||
1983                                            !Validator.equals(name, layoutSetBranch.getName())) {
1984                                    result = null;
1985                            }
1986                    }
1987    
1988                    if (result == null) {
1989                            StringBundler query = new StringBundler(5);
1990    
1991                            query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
1992    
1993                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
1994    
1995                            query.append(_FINDER_COLUMN_G_P_N_PRIVATELAYOUT_2);
1996    
1997                            boolean bindName = false;
1998    
1999                            if (name == null) {
2000                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
2001                            }
2002                            else if (name.equals(StringPool.BLANK)) {
2003                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
2004                            }
2005                            else {
2006                                    bindName = true;
2007    
2008                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
2009                            }
2010    
2011                            String sql = query.toString();
2012    
2013                            Session session = null;
2014    
2015                            try {
2016                                    session = openSession();
2017    
2018                                    Query q = session.createQuery(sql);
2019    
2020                                    QueryPos qPos = QueryPos.getInstance(q);
2021    
2022                                    qPos.add(groupId);
2023    
2024                                    qPos.add(privateLayout);
2025    
2026                                    if (bindName) {
2027                                            qPos.add(name);
2028                                    }
2029    
2030                                    List<LayoutSetBranch> list = q.list();
2031    
2032                                    if (list.isEmpty()) {
2033                                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N,
2034                                                    finderArgs, list);
2035                                    }
2036                                    else {
2037                                            LayoutSetBranch layoutSetBranch = list.get(0);
2038    
2039                                            result = layoutSetBranch;
2040    
2041                                            cacheResult(layoutSetBranch);
2042    
2043                                            if ((layoutSetBranch.getGroupId() != groupId) ||
2044                                                            (layoutSetBranch.getPrivateLayout() != privateLayout) ||
2045                                                            (layoutSetBranch.getName() == null) ||
2046                                                            !layoutSetBranch.getName().equals(name)) {
2047                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N,
2048                                                            finderArgs, layoutSetBranch);
2049                                            }
2050                                    }
2051                            }
2052                            catch (Exception e) {
2053                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_N, finderArgs);
2054    
2055                                    throw processException(e);
2056                            }
2057                            finally {
2058                                    closeSession(session);
2059                            }
2060                    }
2061    
2062                    if (result instanceof List<?>) {
2063                            return null;
2064                    }
2065                    else {
2066                            return (LayoutSetBranch)result;
2067                    }
2068            }
2069    
2070            /**
2071             * Removes the layout set branch where groupId = &#63; and privateLayout = &#63; and name = &#63; from the database.
2072             *
2073             * @param groupId the group ID
2074             * @param privateLayout the private layout
2075             * @param name the name
2076             * @return the layout set branch that was removed
2077             */
2078            @Override
2079            public LayoutSetBranch removeByG_P_N(long groupId, boolean privateLayout,
2080                    String name) throws NoSuchLayoutSetBranchException {
2081                    LayoutSetBranch layoutSetBranch = findByG_P_N(groupId, privateLayout,
2082                                    name);
2083    
2084                    return remove(layoutSetBranch);
2085            }
2086    
2087            /**
2088             * Returns the number of layout set branchs where groupId = &#63; and privateLayout = &#63; and name = &#63;.
2089             *
2090             * @param groupId the group ID
2091             * @param privateLayout the private layout
2092             * @param name the name
2093             * @return the number of matching layout set branchs
2094             */
2095            @Override
2096            public int countByG_P_N(long groupId, boolean privateLayout, String name) {
2097                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_N;
2098    
2099                    Object[] finderArgs = new Object[] { groupId, privateLayout, name };
2100    
2101                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2102    
2103                    if (count == null) {
2104                            StringBundler query = new StringBundler(4);
2105    
2106                            query.append(_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
2107    
2108                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
2109    
2110                            query.append(_FINDER_COLUMN_G_P_N_PRIVATELAYOUT_2);
2111    
2112                            boolean bindName = false;
2113    
2114                            if (name == null) {
2115                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
2116                            }
2117                            else if (name.equals(StringPool.BLANK)) {
2118                                    query.append(_FINDER_COLUMN_G_P_N_NAME_3);
2119                            }
2120                            else {
2121                                    bindName = true;
2122    
2123                                    query.append(_FINDER_COLUMN_G_P_N_NAME_2);
2124                            }
2125    
2126                            String sql = query.toString();
2127    
2128                            Session session = null;
2129    
2130                            try {
2131                                    session = openSession();
2132    
2133                                    Query q = session.createQuery(sql);
2134    
2135                                    QueryPos qPos = QueryPos.getInstance(q);
2136    
2137                                    qPos.add(groupId);
2138    
2139                                    qPos.add(privateLayout);
2140    
2141                                    if (bindName) {
2142                                            qPos.add(name);
2143                                    }
2144    
2145                                    count = (Long)q.uniqueResult();
2146    
2147                                    finderCache.putResult(finderPath, finderArgs, count);
2148                            }
2149                            catch (Exception e) {
2150                                    finderCache.removeResult(finderPath, finderArgs);
2151    
2152                                    throw processException(e);
2153                            }
2154                            finally {
2155                                    closeSession(session);
2156                            }
2157                    }
2158    
2159                    return count.intValue();
2160            }
2161    
2162            private static final String _FINDER_COLUMN_G_P_N_GROUPID_2 = "layoutSetBranch.groupId = ? AND ";
2163            private static final String _FINDER_COLUMN_G_P_N_PRIVATELAYOUT_2 = "layoutSetBranch.privateLayout = ? AND ";
2164            private static final String _FINDER_COLUMN_G_P_N_NAME_1 = "layoutSetBranch.name IS NULL";
2165            private static final String _FINDER_COLUMN_G_P_N_NAME_2 = "layoutSetBranch.name = ?";
2166            private static final String _FINDER_COLUMN_G_P_N_NAME_3 = "(layoutSetBranch.name IS NULL OR layoutSetBranch.name = '')";
2167            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_M = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
2168                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
2169                            LayoutSetBranchImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2170                            "findByG_P_M",
2171                            new String[] {
2172                                    Long.class.getName(), Boolean.class.getName(),
2173                                    Boolean.class.getName(),
2174                                    
2175                            Integer.class.getName(), Integer.class.getName(),
2176                                    OrderByComparator.class.getName()
2177                            });
2178            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_M = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
2179                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
2180                            LayoutSetBranchImpl.class,
2181                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_M",
2182                            new String[] {
2183                                    Long.class.getName(), Boolean.class.getName(),
2184                                    Boolean.class.getName()
2185                            },
2186                            LayoutSetBranchModelImpl.GROUPID_COLUMN_BITMASK |
2187                            LayoutSetBranchModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
2188                            LayoutSetBranchModelImpl.MASTER_COLUMN_BITMASK |
2189                            LayoutSetBranchModelImpl.NAME_COLUMN_BITMASK);
2190            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_M = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
2191                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
2192                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_M",
2193                            new String[] {
2194                                    Long.class.getName(), Boolean.class.getName(),
2195                                    Boolean.class.getName()
2196                            });
2197    
2198            /**
2199             * Returns all the layout set branchs where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2200             *
2201             * @param groupId the group ID
2202             * @param privateLayout the private layout
2203             * @param master the master
2204             * @return the matching layout set branchs
2205             */
2206            @Override
2207            public List<LayoutSetBranch> findByG_P_M(long groupId,
2208                    boolean privateLayout, boolean master) {
2209                    return findByG_P_M(groupId, privateLayout, master, QueryUtil.ALL_POS,
2210                            QueryUtil.ALL_POS, null);
2211            }
2212    
2213            /**
2214             * Returns a range of all the layout set branchs where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2215             *
2216             * <p>
2217             * 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 LayoutSetBranchModelImpl}. 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.
2218             * </p>
2219             *
2220             * @param groupId the group ID
2221             * @param privateLayout the private layout
2222             * @param master the master
2223             * @param start the lower bound of the range of layout set branchs
2224             * @param end the upper bound of the range of layout set branchs (not inclusive)
2225             * @return the range of matching layout set branchs
2226             */
2227            @Override
2228            public List<LayoutSetBranch> findByG_P_M(long groupId,
2229                    boolean privateLayout, boolean master, int start, int end) {
2230                    return findByG_P_M(groupId, privateLayout, master, start, end, null);
2231            }
2232    
2233            /**
2234             * Returns an ordered range of all the layout set branchs where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2235             *
2236             * <p>
2237             * 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 LayoutSetBranchModelImpl}. 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.
2238             * </p>
2239             *
2240             * @param groupId the group ID
2241             * @param privateLayout the private layout
2242             * @param master the master
2243             * @param start the lower bound of the range of layout set branchs
2244             * @param end the upper bound of the range of layout set branchs (not inclusive)
2245             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2246             * @return the ordered range of matching layout set branchs
2247             */
2248            @Override
2249            public List<LayoutSetBranch> findByG_P_M(long groupId,
2250                    boolean privateLayout, boolean master, int start, int end,
2251                    OrderByComparator<LayoutSetBranch> orderByComparator) {
2252                    return findByG_P_M(groupId, privateLayout, master, start, end,
2253                            orderByComparator, true);
2254            }
2255    
2256            /**
2257             * Returns an ordered range of all the layout set branchs where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2258             *
2259             * <p>
2260             * 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 LayoutSetBranchModelImpl}. 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.
2261             * </p>
2262             *
2263             * @param groupId the group ID
2264             * @param privateLayout the private layout
2265             * @param master the master
2266             * @param start the lower bound of the range of layout set branchs
2267             * @param end the upper bound of the range of layout set branchs (not inclusive)
2268             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2269             * @param retrieveFromCache whether to retrieve from the finder cache
2270             * @return the ordered range of matching layout set branchs
2271             */
2272            @Override
2273            public List<LayoutSetBranch> findByG_P_M(long groupId,
2274                    boolean privateLayout, boolean master, int start, int end,
2275                    OrderByComparator<LayoutSetBranch> orderByComparator,
2276                    boolean retrieveFromCache) {
2277                    boolean pagination = true;
2278                    FinderPath finderPath = null;
2279                    Object[] finderArgs = null;
2280    
2281                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2282                                    (orderByComparator == null)) {
2283                            pagination = false;
2284                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_M;
2285                            finderArgs = new Object[] { groupId, privateLayout, master };
2286                    }
2287                    else {
2288                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_M;
2289                            finderArgs = new Object[] {
2290                                            groupId, privateLayout, master,
2291                                            
2292                                            start, end, orderByComparator
2293                                    };
2294                    }
2295    
2296                    List<LayoutSetBranch> list = null;
2297    
2298                    if (retrieveFromCache) {
2299                            list = (List<LayoutSetBranch>)finderCache.getResult(finderPath,
2300                                            finderArgs, this);
2301    
2302                            if ((list != null) && !list.isEmpty()) {
2303                                    for (LayoutSetBranch layoutSetBranch : list) {
2304                                            if ((groupId != layoutSetBranch.getGroupId()) ||
2305                                                            (privateLayout != layoutSetBranch.getPrivateLayout()) ||
2306                                                            (master != layoutSetBranch.getMaster())) {
2307                                                    list = null;
2308    
2309                                                    break;
2310                                            }
2311                                    }
2312                            }
2313                    }
2314    
2315                    if (list == null) {
2316                            StringBundler query = null;
2317    
2318                            if (orderByComparator != null) {
2319                                    query = new StringBundler(5 +
2320                                                    (orderByComparator.getOrderByFields().length * 3));
2321                            }
2322                            else {
2323                                    query = new StringBundler(5);
2324                            }
2325    
2326                            query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
2327    
2328                            query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
2329    
2330                            query.append(_FINDER_COLUMN_G_P_M_PRIVATELAYOUT_2);
2331    
2332                            query.append(_FINDER_COLUMN_G_P_M_MASTER_2);
2333    
2334                            if (orderByComparator != null) {
2335                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2336                                            orderByComparator);
2337                            }
2338                            else
2339                             if (pagination) {
2340                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
2341                            }
2342    
2343                            String sql = query.toString();
2344    
2345                            Session session = null;
2346    
2347                            try {
2348                                    session = openSession();
2349    
2350                                    Query q = session.createQuery(sql);
2351    
2352                                    QueryPos qPos = QueryPos.getInstance(q);
2353    
2354                                    qPos.add(groupId);
2355    
2356                                    qPos.add(privateLayout);
2357    
2358                                    qPos.add(master);
2359    
2360                                    if (!pagination) {
2361                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
2362                                                            getDialect(), start, end, false);
2363    
2364                                            Collections.sort(list);
2365    
2366                                            list = Collections.unmodifiableList(list);
2367                                    }
2368                                    else {
2369                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
2370                                                            getDialect(), start, end);
2371                                    }
2372    
2373                                    cacheResult(list);
2374    
2375                                    finderCache.putResult(finderPath, finderArgs, list);
2376                            }
2377                            catch (Exception e) {
2378                                    finderCache.removeResult(finderPath, finderArgs);
2379    
2380                                    throw processException(e);
2381                            }
2382                            finally {
2383                                    closeSession(session);
2384                            }
2385                    }
2386    
2387                    return list;
2388            }
2389    
2390            /**
2391             * Returns the first layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2392             *
2393             * @param groupId the group ID
2394             * @param privateLayout the private layout
2395             * @param master the master
2396             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2397             * @return the first matching layout set branch
2398             * @throws NoSuchLayoutSetBranchException if a matching layout set branch could not be found
2399             */
2400            @Override
2401            public LayoutSetBranch findByG_P_M_First(long groupId,
2402                    boolean privateLayout, boolean master,
2403                    OrderByComparator<LayoutSetBranch> orderByComparator)
2404                    throws NoSuchLayoutSetBranchException {
2405                    LayoutSetBranch layoutSetBranch = fetchByG_P_M_First(groupId,
2406                                    privateLayout, master, orderByComparator);
2407    
2408                    if (layoutSetBranch != null) {
2409                            return layoutSetBranch;
2410                    }
2411    
2412                    StringBundler msg = new StringBundler(8);
2413    
2414                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2415    
2416                    msg.append("groupId=");
2417                    msg.append(groupId);
2418    
2419                    msg.append(", privateLayout=");
2420                    msg.append(privateLayout);
2421    
2422                    msg.append(", master=");
2423                    msg.append(master);
2424    
2425                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2426    
2427                    throw new NoSuchLayoutSetBranchException(msg.toString());
2428            }
2429    
2430            /**
2431             * Returns the first layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2432             *
2433             * @param groupId the group ID
2434             * @param privateLayout the private layout
2435             * @param master the master
2436             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2437             * @return the first matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
2438             */
2439            @Override
2440            public LayoutSetBranch fetchByG_P_M_First(long groupId,
2441                    boolean privateLayout, boolean master,
2442                    OrderByComparator<LayoutSetBranch> orderByComparator) {
2443                    List<LayoutSetBranch> list = findByG_P_M(groupId, privateLayout,
2444                                    master, 0, 1, orderByComparator);
2445    
2446                    if (!list.isEmpty()) {
2447                            return list.get(0);
2448                    }
2449    
2450                    return null;
2451            }
2452    
2453            /**
2454             * Returns the last layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2455             *
2456             * @param groupId the group ID
2457             * @param privateLayout the private layout
2458             * @param master the master
2459             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2460             * @return the last matching layout set branch
2461             * @throws NoSuchLayoutSetBranchException if a matching layout set branch could not be found
2462             */
2463            @Override
2464            public LayoutSetBranch findByG_P_M_Last(long groupId,
2465                    boolean privateLayout, boolean master,
2466                    OrderByComparator<LayoutSetBranch> orderByComparator)
2467                    throws NoSuchLayoutSetBranchException {
2468                    LayoutSetBranch layoutSetBranch = fetchByG_P_M_Last(groupId,
2469                                    privateLayout, master, orderByComparator);
2470    
2471                    if (layoutSetBranch != null) {
2472                            return layoutSetBranch;
2473                    }
2474    
2475                    StringBundler msg = new StringBundler(8);
2476    
2477                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2478    
2479                    msg.append("groupId=");
2480                    msg.append(groupId);
2481    
2482                    msg.append(", privateLayout=");
2483                    msg.append(privateLayout);
2484    
2485                    msg.append(", master=");
2486                    msg.append(master);
2487    
2488                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2489    
2490                    throw new NoSuchLayoutSetBranchException(msg.toString());
2491            }
2492    
2493            /**
2494             * Returns the last layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2495             *
2496             * @param groupId the group ID
2497             * @param privateLayout the private layout
2498             * @param master the master
2499             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2500             * @return the last matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
2501             */
2502            @Override
2503            public LayoutSetBranch fetchByG_P_M_Last(long groupId,
2504                    boolean privateLayout, boolean master,
2505                    OrderByComparator<LayoutSetBranch> orderByComparator) {
2506                    int count = countByG_P_M(groupId, privateLayout, master);
2507    
2508                    if (count == 0) {
2509                            return null;
2510                    }
2511    
2512                    List<LayoutSetBranch> list = findByG_P_M(groupId, privateLayout,
2513                                    master, count - 1, count, orderByComparator);
2514    
2515                    if (!list.isEmpty()) {
2516                            return list.get(0);
2517                    }
2518    
2519                    return null;
2520            }
2521    
2522            /**
2523             * Returns the layout set branchs before and after the current layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2524             *
2525             * @param layoutSetBranchId the primary key of the current layout set branch
2526             * @param groupId the group ID
2527             * @param privateLayout the private layout
2528             * @param master the master
2529             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2530             * @return the previous, current, and next layout set branch
2531             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
2532             */
2533            @Override
2534            public LayoutSetBranch[] findByG_P_M_PrevAndNext(long layoutSetBranchId,
2535                    long groupId, boolean privateLayout, boolean master,
2536                    OrderByComparator<LayoutSetBranch> orderByComparator)
2537                    throws NoSuchLayoutSetBranchException {
2538                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
2539    
2540                    Session session = null;
2541    
2542                    try {
2543                            session = openSession();
2544    
2545                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
2546    
2547                            array[0] = getByG_P_M_PrevAndNext(session, layoutSetBranch,
2548                                            groupId, privateLayout, master, orderByComparator, true);
2549    
2550                            array[1] = layoutSetBranch;
2551    
2552                            array[2] = getByG_P_M_PrevAndNext(session, layoutSetBranch,
2553                                            groupId, privateLayout, master, orderByComparator, false);
2554    
2555                            return array;
2556                    }
2557                    catch (Exception e) {
2558                            throw processException(e);
2559                    }
2560                    finally {
2561                            closeSession(session);
2562                    }
2563            }
2564    
2565            protected LayoutSetBranch getByG_P_M_PrevAndNext(Session session,
2566                    LayoutSetBranch layoutSetBranch, long groupId, boolean privateLayout,
2567                    boolean master, OrderByComparator<LayoutSetBranch> orderByComparator,
2568                    boolean previous) {
2569                    StringBundler query = null;
2570    
2571                    if (orderByComparator != null) {
2572                            query = new StringBundler(6 +
2573                                            (orderByComparator.getOrderByFields().length * 6));
2574                    }
2575                    else {
2576                            query = new StringBundler(3);
2577                    }
2578    
2579                    query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
2580    
2581                    query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
2582    
2583                    query.append(_FINDER_COLUMN_G_P_M_PRIVATELAYOUT_2);
2584    
2585                    query.append(_FINDER_COLUMN_G_P_M_MASTER_2);
2586    
2587                    if (orderByComparator != null) {
2588                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2589    
2590                            if (orderByConditionFields.length > 0) {
2591                                    query.append(WHERE_AND);
2592                            }
2593    
2594                            for (int i = 0; i < orderByConditionFields.length; i++) {
2595                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2596                                    query.append(orderByConditionFields[i]);
2597    
2598                                    if ((i + 1) < orderByConditionFields.length) {
2599                                            if (orderByComparator.isAscending() ^ previous) {
2600                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2601                                            }
2602                                            else {
2603                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2604                                            }
2605                                    }
2606                                    else {
2607                                            if (orderByComparator.isAscending() ^ previous) {
2608                                                    query.append(WHERE_GREATER_THAN);
2609                                            }
2610                                            else {
2611                                                    query.append(WHERE_LESSER_THAN);
2612                                            }
2613                                    }
2614                            }
2615    
2616                            query.append(ORDER_BY_CLAUSE);
2617    
2618                            String[] orderByFields = orderByComparator.getOrderByFields();
2619    
2620                            for (int i = 0; i < orderByFields.length; i++) {
2621                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2622                                    query.append(orderByFields[i]);
2623    
2624                                    if ((i + 1) < orderByFields.length) {
2625                                            if (orderByComparator.isAscending() ^ previous) {
2626                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2627                                            }
2628                                            else {
2629                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2630                                            }
2631                                    }
2632                                    else {
2633                                            if (orderByComparator.isAscending() ^ previous) {
2634                                                    query.append(ORDER_BY_ASC);
2635                                            }
2636                                            else {
2637                                                    query.append(ORDER_BY_DESC);
2638                                            }
2639                                    }
2640                            }
2641                    }
2642                    else {
2643                            query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
2644                    }
2645    
2646                    String sql = query.toString();
2647    
2648                    Query q = session.createQuery(sql);
2649    
2650                    q.setFirstResult(0);
2651                    q.setMaxResults(2);
2652    
2653                    QueryPos qPos = QueryPos.getInstance(q);
2654    
2655                    qPos.add(groupId);
2656    
2657                    qPos.add(privateLayout);
2658    
2659                    qPos.add(master);
2660    
2661                    if (orderByComparator != null) {
2662                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
2663    
2664                            for (Object value : values) {
2665                                    qPos.add(value);
2666                            }
2667                    }
2668    
2669                    List<LayoutSetBranch> list = q.list();
2670    
2671                    if (list.size() == 2) {
2672                            return list.get(1);
2673                    }
2674                    else {
2675                            return null;
2676                    }
2677            }
2678    
2679            /**
2680             * Returns all the layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2681             *
2682             * @param groupId the group ID
2683             * @param privateLayout the private layout
2684             * @param master the master
2685             * @return the matching layout set branchs that the user has permission to view
2686             */
2687            @Override
2688            public List<LayoutSetBranch> filterFindByG_P_M(long groupId,
2689                    boolean privateLayout, boolean master) {
2690                    return filterFindByG_P_M(groupId, privateLayout, master,
2691                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2692            }
2693    
2694            /**
2695             * Returns a range of all the layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2696             *
2697             * <p>
2698             * 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 LayoutSetBranchModelImpl}. 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.
2699             * </p>
2700             *
2701             * @param groupId the group ID
2702             * @param privateLayout the private layout
2703             * @param master the master
2704             * @param start the lower bound of the range of layout set branchs
2705             * @param end the upper bound of the range of layout set branchs (not inclusive)
2706             * @return the range of matching layout set branchs that the user has permission to view
2707             */
2708            @Override
2709            public List<LayoutSetBranch> filterFindByG_P_M(long groupId,
2710                    boolean privateLayout, boolean master, int start, int end) {
2711                    return filterFindByG_P_M(groupId, privateLayout, master, start, end,
2712                            null);
2713            }
2714    
2715            /**
2716             * Returns an ordered range of all the layout set branchs that the user has permissions to view where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2717             *
2718             * <p>
2719             * 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 LayoutSetBranchModelImpl}. 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.
2720             * </p>
2721             *
2722             * @param groupId the group ID
2723             * @param privateLayout the private layout
2724             * @param master the master
2725             * @param start the lower bound of the range of layout set branchs
2726             * @param end the upper bound of the range of layout set branchs (not inclusive)
2727             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2728             * @return the ordered range of matching layout set branchs that the user has permission to view
2729             */
2730            @Override
2731            public List<LayoutSetBranch> filterFindByG_P_M(long groupId,
2732                    boolean privateLayout, boolean master, int start, int end,
2733                    OrderByComparator<LayoutSetBranch> orderByComparator) {
2734                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2735                            return findByG_P_M(groupId, privateLayout, master, start, end,
2736                                    orderByComparator);
2737                    }
2738    
2739                    StringBundler query = null;
2740    
2741                    if (orderByComparator != null) {
2742                            query = new StringBundler(5 +
2743                                            (orderByComparator.getOrderByFields().length * 3));
2744                    }
2745                    else {
2746                            query = new StringBundler(5);
2747                    }
2748    
2749                    if (getDB().isSupportsInlineDistinct()) {
2750                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
2751                    }
2752                    else {
2753                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
2754                    }
2755    
2756                    query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
2757    
2758                    query.append(_FINDER_COLUMN_G_P_M_PRIVATELAYOUT_2);
2759    
2760                    query.append(_FINDER_COLUMN_G_P_M_MASTER_2);
2761    
2762                    if (!getDB().isSupportsInlineDistinct()) {
2763                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
2764                    }
2765    
2766                    if (orderByComparator != null) {
2767                            if (getDB().isSupportsInlineDistinct()) {
2768                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2769                                            orderByComparator, true);
2770                            }
2771                            else {
2772                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2773                                            orderByComparator, true);
2774                            }
2775                    }
2776                    else {
2777                            if (getDB().isSupportsInlineDistinct()) {
2778                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
2779                            }
2780                            else {
2781                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
2782                            }
2783                    }
2784    
2785                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2786                                    LayoutSetBranch.class.getName(),
2787                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2788    
2789                    Session session = null;
2790    
2791                    try {
2792                            session = openSession();
2793    
2794                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2795    
2796                            if (getDB().isSupportsInlineDistinct()) {
2797                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
2798                            }
2799                            else {
2800                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
2801                            }
2802    
2803                            QueryPos qPos = QueryPos.getInstance(q);
2804    
2805                            qPos.add(groupId);
2806    
2807                            qPos.add(privateLayout);
2808    
2809                            qPos.add(master);
2810    
2811                            return (List<LayoutSetBranch>)QueryUtil.list(q, getDialect(),
2812                                    start, end);
2813                    }
2814                    catch (Exception e) {
2815                            throw processException(e);
2816                    }
2817                    finally {
2818                            closeSession(session);
2819                    }
2820            }
2821    
2822            /**
2823             * Returns the layout set branchs before and after the current layout set branch in the ordered set of layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63; and master = &#63;.
2824             *
2825             * @param layoutSetBranchId the primary key of the current layout set branch
2826             * @param groupId the group ID
2827             * @param privateLayout the private layout
2828             * @param master the master
2829             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2830             * @return the previous, current, and next layout set branch
2831             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
2832             */
2833            @Override
2834            public LayoutSetBranch[] filterFindByG_P_M_PrevAndNext(
2835                    long layoutSetBranchId, long groupId, boolean privateLayout,
2836                    boolean master, OrderByComparator<LayoutSetBranch> orderByComparator)
2837                    throws NoSuchLayoutSetBranchException {
2838                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2839                            return findByG_P_M_PrevAndNext(layoutSetBranchId, groupId,
2840                                    privateLayout, master, orderByComparator);
2841                    }
2842    
2843                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
2844    
2845                    Session session = null;
2846    
2847                    try {
2848                            session = openSession();
2849    
2850                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
2851    
2852                            array[0] = filterGetByG_P_M_PrevAndNext(session, layoutSetBranch,
2853                                            groupId, privateLayout, master, orderByComparator, true);
2854    
2855                            array[1] = layoutSetBranch;
2856    
2857                            array[2] = filterGetByG_P_M_PrevAndNext(session, layoutSetBranch,
2858                                            groupId, privateLayout, master, orderByComparator, false);
2859    
2860                            return array;
2861                    }
2862                    catch (Exception e) {
2863                            throw processException(e);
2864                    }
2865                    finally {
2866                            closeSession(session);
2867                    }
2868            }
2869    
2870            protected LayoutSetBranch filterGetByG_P_M_PrevAndNext(Session session,
2871                    LayoutSetBranch layoutSetBranch, long groupId, boolean privateLayout,
2872                    boolean master, OrderByComparator<LayoutSetBranch> orderByComparator,
2873                    boolean previous) {
2874                    StringBundler query = null;
2875    
2876                    if (orderByComparator != null) {
2877                            query = new StringBundler(6 +
2878                                            (orderByComparator.getOrderByFields().length * 6));
2879                    }
2880                    else {
2881                            query = new StringBundler(3);
2882                    }
2883    
2884                    if (getDB().isSupportsInlineDistinct()) {
2885                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
2886                    }
2887                    else {
2888                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
2889                    }
2890    
2891                    query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
2892    
2893                    query.append(_FINDER_COLUMN_G_P_M_PRIVATELAYOUT_2);
2894    
2895                    query.append(_FINDER_COLUMN_G_P_M_MASTER_2);
2896    
2897                    if (!getDB().isSupportsInlineDistinct()) {
2898                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
2899                    }
2900    
2901                    if (orderByComparator != null) {
2902                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2903    
2904                            if (orderByConditionFields.length > 0) {
2905                                    query.append(WHERE_AND);
2906                            }
2907    
2908                            for (int i = 0; i < orderByConditionFields.length; i++) {
2909                                    if (getDB().isSupportsInlineDistinct()) {
2910                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2911                                    }
2912                                    else {
2913                                            query.append(_ORDER_BY_ENTITY_TABLE);
2914                                    }
2915    
2916                                    query.append(orderByConditionFields[i]);
2917    
2918                                    if ((i + 1) < orderByConditionFields.length) {
2919                                            if (orderByComparator.isAscending() ^ previous) {
2920                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2921                                            }
2922                                            else {
2923                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2924                                            }
2925                                    }
2926                                    else {
2927                                            if (orderByComparator.isAscending() ^ previous) {
2928                                                    query.append(WHERE_GREATER_THAN);
2929                                            }
2930                                            else {
2931                                                    query.append(WHERE_LESSER_THAN);
2932                                            }
2933                                    }
2934                            }
2935    
2936                            query.append(ORDER_BY_CLAUSE);
2937    
2938                            String[] orderByFields = orderByComparator.getOrderByFields();
2939    
2940                            for (int i = 0; i < orderByFields.length; i++) {
2941                                    if (getDB().isSupportsInlineDistinct()) {
2942                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2943                                    }
2944                                    else {
2945                                            query.append(_ORDER_BY_ENTITY_TABLE);
2946                                    }
2947    
2948                                    query.append(orderByFields[i]);
2949    
2950                                    if ((i + 1) < orderByFields.length) {
2951                                            if (orderByComparator.isAscending() ^ previous) {
2952                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2953                                            }
2954                                            else {
2955                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2956                                            }
2957                                    }
2958                                    else {
2959                                            if (orderByComparator.isAscending() ^ previous) {
2960                                                    query.append(ORDER_BY_ASC);
2961                                            }
2962                                            else {
2963                                                    query.append(ORDER_BY_DESC);
2964                                            }
2965                                    }
2966                            }
2967                    }
2968                    else {
2969                            if (getDB().isSupportsInlineDistinct()) {
2970                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
2971                            }
2972                            else {
2973                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
2974                            }
2975                    }
2976    
2977                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2978                                    LayoutSetBranch.class.getName(),
2979                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2980    
2981                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2982    
2983                    q.setFirstResult(0);
2984                    q.setMaxResults(2);
2985    
2986                    if (getDB().isSupportsInlineDistinct()) {
2987                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
2988                    }
2989                    else {
2990                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
2991                    }
2992    
2993                    QueryPos qPos = QueryPos.getInstance(q);
2994    
2995                    qPos.add(groupId);
2996    
2997                    qPos.add(privateLayout);
2998    
2999                    qPos.add(master);
3000    
3001                    if (orderByComparator != null) {
3002                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
3003    
3004                            for (Object value : values) {
3005                                    qPos.add(value);
3006                            }
3007                    }
3008    
3009                    List<LayoutSetBranch> list = q.list();
3010    
3011                    if (list.size() == 2) {
3012                            return list.get(1);
3013                    }
3014                    else {
3015                            return null;
3016                    }
3017            }
3018    
3019            /**
3020             * Removes all the layout set branchs where groupId = &#63; and privateLayout = &#63; and master = &#63; from the database.
3021             *
3022             * @param groupId the group ID
3023             * @param privateLayout the private layout
3024             * @param master the master
3025             */
3026            @Override
3027            public void removeByG_P_M(long groupId, boolean privateLayout,
3028                    boolean master) {
3029                    for (LayoutSetBranch layoutSetBranch : findByG_P_M(groupId,
3030                                    privateLayout, master, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3031                                    null)) {
3032                            remove(layoutSetBranch);
3033                    }
3034            }
3035    
3036            /**
3037             * Returns the number of layout set branchs where groupId = &#63; and privateLayout = &#63; and master = &#63;.
3038             *
3039             * @param groupId the group ID
3040             * @param privateLayout the private layout
3041             * @param master the master
3042             * @return the number of matching layout set branchs
3043             */
3044            @Override
3045            public int countByG_P_M(long groupId, boolean privateLayout, boolean master) {
3046                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_M;
3047    
3048                    Object[] finderArgs = new Object[] { groupId, privateLayout, master };
3049    
3050                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3051    
3052                    if (count == null) {
3053                            StringBundler query = new StringBundler(4);
3054    
3055                            query.append(_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
3056    
3057                            query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
3058    
3059                            query.append(_FINDER_COLUMN_G_P_M_PRIVATELAYOUT_2);
3060    
3061                            query.append(_FINDER_COLUMN_G_P_M_MASTER_2);
3062    
3063                            String sql = query.toString();
3064    
3065                            Session session = null;
3066    
3067                            try {
3068                                    session = openSession();
3069    
3070                                    Query q = session.createQuery(sql);
3071    
3072                                    QueryPos qPos = QueryPos.getInstance(q);
3073    
3074                                    qPos.add(groupId);
3075    
3076                                    qPos.add(privateLayout);
3077    
3078                                    qPos.add(master);
3079    
3080                                    count = (Long)q.uniqueResult();
3081    
3082                                    finderCache.putResult(finderPath, finderArgs, count);
3083                            }
3084                            catch (Exception e) {
3085                                    finderCache.removeResult(finderPath, finderArgs);
3086    
3087                                    throw processException(e);
3088                            }
3089                            finally {
3090                                    closeSession(session);
3091                            }
3092                    }
3093    
3094                    return count.intValue();
3095            }
3096    
3097            /**
3098             * Returns the number of layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63; and master = &#63;.
3099             *
3100             * @param groupId the group ID
3101             * @param privateLayout the private layout
3102             * @param master the master
3103             * @return the number of matching layout set branchs that the user has permission to view
3104             */
3105            @Override
3106            public int filterCountByG_P_M(long groupId, boolean privateLayout,
3107                    boolean master) {
3108                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3109                            return countByG_P_M(groupId, privateLayout, master);
3110                    }
3111    
3112                    StringBundler query = new StringBundler(4);
3113    
3114                    query.append(_FILTER_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
3115    
3116                    query.append(_FINDER_COLUMN_G_P_M_GROUPID_2);
3117    
3118                    query.append(_FINDER_COLUMN_G_P_M_PRIVATELAYOUT_2);
3119    
3120                    query.append(_FINDER_COLUMN_G_P_M_MASTER_2);
3121    
3122                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3123                                    LayoutSetBranch.class.getName(),
3124                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3125    
3126                    Session session = null;
3127    
3128                    try {
3129                            session = openSession();
3130    
3131                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3132    
3133                            q.addScalar(COUNT_COLUMN_NAME,
3134                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3135    
3136                            QueryPos qPos = QueryPos.getInstance(q);
3137    
3138                            qPos.add(groupId);
3139    
3140                            qPos.add(privateLayout);
3141    
3142                            qPos.add(master);
3143    
3144                            Long count = (Long)q.uniqueResult();
3145    
3146                            return count.intValue();
3147                    }
3148                    catch (Exception e) {
3149                            throw processException(e);
3150                    }
3151                    finally {
3152                            closeSession(session);
3153                    }
3154            }
3155    
3156            private static final String _FINDER_COLUMN_G_P_M_GROUPID_2 = "layoutSetBranch.groupId = ? AND ";
3157            private static final String _FINDER_COLUMN_G_P_M_PRIVATELAYOUT_2 = "layoutSetBranch.privateLayout = ? AND ";
3158            private static final String _FINDER_COLUMN_G_P_M_MASTER_2 = "layoutSetBranch.master = ?";
3159    
3160            public LayoutSetBranchPersistenceImpl() {
3161                    setModelClass(LayoutSetBranch.class);
3162            }
3163    
3164            /**
3165             * Caches the layout set branch in the entity cache if it is enabled.
3166             *
3167             * @param layoutSetBranch the layout set branch
3168             */
3169            @Override
3170            public void cacheResult(LayoutSetBranch layoutSetBranch) {
3171                    entityCache.putResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3172                            LayoutSetBranchImpl.class, layoutSetBranch.getPrimaryKey(),
3173                            layoutSetBranch);
3174    
3175                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N,
3176                            new Object[] {
3177                                    layoutSetBranch.getGroupId(), layoutSetBranch.getPrivateLayout(),
3178                                    layoutSetBranch.getName()
3179                            }, layoutSetBranch);
3180    
3181                    layoutSetBranch.resetOriginalValues();
3182            }
3183    
3184            /**
3185             * Caches the layout set branchs in the entity cache if it is enabled.
3186             *
3187             * @param layoutSetBranchs the layout set branchs
3188             */
3189            @Override
3190            public void cacheResult(List<LayoutSetBranch> layoutSetBranchs) {
3191                    for (LayoutSetBranch layoutSetBranch : layoutSetBranchs) {
3192                            if (entityCache.getResult(
3193                                                    LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3194                                                    LayoutSetBranchImpl.class,
3195                                                    layoutSetBranch.getPrimaryKey()) == null) {
3196                                    cacheResult(layoutSetBranch);
3197                            }
3198                            else {
3199                                    layoutSetBranch.resetOriginalValues();
3200                            }
3201                    }
3202            }
3203    
3204            /**
3205             * Clears the cache for all layout set branchs.
3206             *
3207             * <p>
3208             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
3209             * </p>
3210             */
3211            @Override
3212            public void clearCache() {
3213                    entityCache.clearCache(LayoutSetBranchImpl.class);
3214    
3215                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
3216                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3217                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3218            }
3219    
3220            /**
3221             * Clears the cache for the layout set branch.
3222             *
3223             * <p>
3224             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
3225             * </p>
3226             */
3227            @Override
3228            public void clearCache(LayoutSetBranch layoutSetBranch) {
3229                    entityCache.removeResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3230                            LayoutSetBranchImpl.class, layoutSetBranch.getPrimaryKey());
3231    
3232                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3233                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3234    
3235                    clearUniqueFindersCache((LayoutSetBranchModelImpl)layoutSetBranch);
3236            }
3237    
3238            @Override
3239            public void clearCache(List<LayoutSetBranch> layoutSetBranchs) {
3240                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3241                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3242    
3243                    for (LayoutSetBranch layoutSetBranch : layoutSetBranchs) {
3244                            entityCache.removeResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3245                                    LayoutSetBranchImpl.class, layoutSetBranch.getPrimaryKey());
3246    
3247                            clearUniqueFindersCache((LayoutSetBranchModelImpl)layoutSetBranch);
3248                    }
3249            }
3250    
3251            protected void cacheUniqueFindersCache(
3252                    LayoutSetBranchModelImpl layoutSetBranchModelImpl, boolean isNew) {
3253                    if (isNew) {
3254                            Object[] args = new Object[] {
3255                                            layoutSetBranchModelImpl.getGroupId(),
3256                                            layoutSetBranchModelImpl.getPrivateLayout(),
3257                                            layoutSetBranchModelImpl.getName()
3258                                    };
3259    
3260                            finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
3261                                    Long.valueOf(1));
3262                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
3263                                    layoutSetBranchModelImpl);
3264                    }
3265                    else {
3266                            if ((layoutSetBranchModelImpl.getColumnBitmask() &
3267                                            FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
3268                                    Object[] args = new Object[] {
3269                                                    layoutSetBranchModelImpl.getGroupId(),
3270                                                    layoutSetBranchModelImpl.getPrivateLayout(),
3271                                                    layoutSetBranchModelImpl.getName()
3272                                            };
3273    
3274                                    finderCache.putResult(FINDER_PATH_COUNT_BY_G_P_N, args,
3275                                            Long.valueOf(1));
3276                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_P_N, args,
3277                                            layoutSetBranchModelImpl);
3278                            }
3279                    }
3280            }
3281    
3282            protected void clearUniqueFindersCache(
3283                    LayoutSetBranchModelImpl layoutSetBranchModelImpl) {
3284                    Object[] args = new Object[] {
3285                                    layoutSetBranchModelImpl.getGroupId(),
3286                                    layoutSetBranchModelImpl.getPrivateLayout(),
3287                                    layoutSetBranchModelImpl.getName()
3288                            };
3289    
3290                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
3291                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
3292    
3293                    if ((layoutSetBranchModelImpl.getColumnBitmask() &
3294                                    FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
3295                            args = new Object[] {
3296                                            layoutSetBranchModelImpl.getOriginalGroupId(),
3297                                            layoutSetBranchModelImpl.getOriginalPrivateLayout(),
3298                                            layoutSetBranchModelImpl.getOriginalName()
3299                                    };
3300    
3301                            finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
3302                            finderCache.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
3303                    }
3304            }
3305    
3306            /**
3307             * Creates a new layout set branch with the primary key. Does not add the layout set branch to the database.
3308             *
3309             * @param layoutSetBranchId the primary key for the new layout set branch
3310             * @return the new layout set branch
3311             */
3312            @Override
3313            public LayoutSetBranch create(long layoutSetBranchId) {
3314                    LayoutSetBranch layoutSetBranch = new LayoutSetBranchImpl();
3315    
3316                    layoutSetBranch.setNew(true);
3317                    layoutSetBranch.setPrimaryKey(layoutSetBranchId);
3318    
3319                    return layoutSetBranch;
3320            }
3321    
3322            /**
3323             * Removes the layout set branch with the primary key from the database. Also notifies the appropriate model listeners.
3324             *
3325             * @param layoutSetBranchId the primary key of the layout set branch
3326             * @return the layout set branch that was removed
3327             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
3328             */
3329            @Override
3330            public LayoutSetBranch remove(long layoutSetBranchId)
3331                    throws NoSuchLayoutSetBranchException {
3332                    return remove((Serializable)layoutSetBranchId);
3333            }
3334    
3335            /**
3336             * Removes the layout set branch with the primary key from the database. Also notifies the appropriate model listeners.
3337             *
3338             * @param primaryKey the primary key of the layout set branch
3339             * @return the layout set branch that was removed
3340             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
3341             */
3342            @Override
3343            public LayoutSetBranch remove(Serializable primaryKey)
3344                    throws NoSuchLayoutSetBranchException {
3345                    Session session = null;
3346    
3347                    try {
3348                            session = openSession();
3349    
3350                            LayoutSetBranch layoutSetBranch = (LayoutSetBranch)session.get(LayoutSetBranchImpl.class,
3351                                            primaryKey);
3352    
3353                            if (layoutSetBranch == null) {
3354                                    if (_log.isWarnEnabled()) {
3355                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3356                                    }
3357    
3358                                    throw new NoSuchLayoutSetBranchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3359                                            primaryKey);
3360                            }
3361    
3362                            return remove(layoutSetBranch);
3363                    }
3364                    catch (NoSuchLayoutSetBranchException nsee) {
3365                            throw nsee;
3366                    }
3367                    catch (Exception e) {
3368                            throw processException(e);
3369                    }
3370                    finally {
3371                            closeSession(session);
3372                    }
3373            }
3374    
3375            @Override
3376            protected LayoutSetBranch removeImpl(LayoutSetBranch layoutSetBranch) {
3377                    layoutSetBranch = toUnwrappedModel(layoutSetBranch);
3378    
3379                    Session session = null;
3380    
3381                    try {
3382                            session = openSession();
3383    
3384                            if (!session.contains(layoutSetBranch)) {
3385                                    layoutSetBranch = (LayoutSetBranch)session.get(LayoutSetBranchImpl.class,
3386                                                    layoutSetBranch.getPrimaryKeyObj());
3387                            }
3388    
3389                            if (layoutSetBranch != null) {
3390                                    session.delete(layoutSetBranch);
3391                            }
3392                    }
3393                    catch (Exception e) {
3394                            throw processException(e);
3395                    }
3396                    finally {
3397                            closeSession(session);
3398                    }
3399    
3400                    if (layoutSetBranch != null) {
3401                            clearCache(layoutSetBranch);
3402                    }
3403    
3404                    return layoutSetBranch;
3405            }
3406    
3407            @Override
3408            public LayoutSetBranch updateImpl(LayoutSetBranch layoutSetBranch) {
3409                    layoutSetBranch = toUnwrappedModel(layoutSetBranch);
3410    
3411                    boolean isNew = layoutSetBranch.isNew();
3412    
3413                    LayoutSetBranchModelImpl layoutSetBranchModelImpl = (LayoutSetBranchModelImpl)layoutSetBranch;
3414    
3415                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
3416    
3417                    Date now = new Date();
3418    
3419                    if (isNew && (layoutSetBranch.getCreateDate() == null)) {
3420                            if (serviceContext == null) {
3421                                    layoutSetBranch.setCreateDate(now);
3422                            }
3423                            else {
3424                                    layoutSetBranch.setCreateDate(serviceContext.getCreateDate(now));
3425                            }
3426                    }
3427    
3428                    if (!layoutSetBranchModelImpl.hasSetModifiedDate()) {
3429                            if (serviceContext == null) {
3430                                    layoutSetBranch.setModifiedDate(now);
3431                            }
3432                            else {
3433                                    layoutSetBranch.setModifiedDate(serviceContext.getModifiedDate(
3434                                                    now));
3435                            }
3436                    }
3437    
3438                    Session session = null;
3439    
3440                    try {
3441                            session = openSession();
3442    
3443                            if (layoutSetBranch.isNew()) {
3444                                    session.save(layoutSetBranch);
3445    
3446                                    layoutSetBranch.setNew(false);
3447                            }
3448                            else {
3449                                    layoutSetBranch = (LayoutSetBranch)session.merge(layoutSetBranch);
3450                            }
3451                    }
3452                    catch (Exception e) {
3453                            throw processException(e);
3454                    }
3455                    finally {
3456                            closeSession(session);
3457                    }
3458    
3459                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3460    
3461                    if (isNew || !LayoutSetBranchModelImpl.COLUMN_BITMASK_ENABLED) {
3462                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3463                    }
3464    
3465                    else {
3466                            if ((layoutSetBranchModelImpl.getColumnBitmask() &
3467                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
3468                                    Object[] args = new Object[] {
3469                                                    layoutSetBranchModelImpl.getOriginalGroupId()
3470                                            };
3471    
3472                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
3473                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
3474                                            args);
3475    
3476                                    args = new Object[] { layoutSetBranchModelImpl.getGroupId() };
3477    
3478                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
3479                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
3480                                            args);
3481                            }
3482    
3483                            if ((layoutSetBranchModelImpl.getColumnBitmask() &
3484                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
3485                                    Object[] args = new Object[] {
3486                                                    layoutSetBranchModelImpl.getOriginalGroupId(),
3487                                                    layoutSetBranchModelImpl.getOriginalPrivateLayout()
3488                                            };
3489    
3490                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
3491                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
3492                                            args);
3493    
3494                                    args = new Object[] {
3495                                                    layoutSetBranchModelImpl.getGroupId(),
3496                                                    layoutSetBranchModelImpl.getPrivateLayout()
3497                                            };
3498    
3499                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
3500                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
3501                                            args);
3502                            }
3503    
3504                            if ((layoutSetBranchModelImpl.getColumnBitmask() &
3505                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_M.getColumnBitmask()) != 0) {
3506                                    Object[] args = new Object[] {
3507                                                    layoutSetBranchModelImpl.getOriginalGroupId(),
3508                                                    layoutSetBranchModelImpl.getOriginalPrivateLayout(),
3509                                                    layoutSetBranchModelImpl.getOriginalMaster()
3510                                            };
3511    
3512                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_M, args);
3513                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_M,
3514                                            args);
3515    
3516                                    args = new Object[] {
3517                                                    layoutSetBranchModelImpl.getGroupId(),
3518                                                    layoutSetBranchModelImpl.getPrivateLayout(),
3519                                                    layoutSetBranchModelImpl.getMaster()
3520                                            };
3521    
3522                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_M, args);
3523                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_M,
3524                                            args);
3525                            }
3526                    }
3527    
3528                    entityCache.putResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3529                            LayoutSetBranchImpl.class, layoutSetBranch.getPrimaryKey(),
3530                            layoutSetBranch, false);
3531    
3532                    clearUniqueFindersCache(layoutSetBranchModelImpl);
3533                    cacheUniqueFindersCache(layoutSetBranchModelImpl, isNew);
3534    
3535                    layoutSetBranch.resetOriginalValues();
3536    
3537                    return layoutSetBranch;
3538            }
3539    
3540            protected LayoutSetBranch toUnwrappedModel(LayoutSetBranch layoutSetBranch) {
3541                    if (layoutSetBranch instanceof LayoutSetBranchImpl) {
3542                            return layoutSetBranch;
3543                    }
3544    
3545                    LayoutSetBranchImpl layoutSetBranchImpl = new LayoutSetBranchImpl();
3546    
3547                    layoutSetBranchImpl.setNew(layoutSetBranch.isNew());
3548                    layoutSetBranchImpl.setPrimaryKey(layoutSetBranch.getPrimaryKey());
3549    
3550                    layoutSetBranchImpl.setMvccVersion(layoutSetBranch.getMvccVersion());
3551                    layoutSetBranchImpl.setLayoutSetBranchId(layoutSetBranch.getLayoutSetBranchId());
3552                    layoutSetBranchImpl.setGroupId(layoutSetBranch.getGroupId());
3553                    layoutSetBranchImpl.setCompanyId(layoutSetBranch.getCompanyId());
3554                    layoutSetBranchImpl.setUserId(layoutSetBranch.getUserId());
3555                    layoutSetBranchImpl.setUserName(layoutSetBranch.getUserName());
3556                    layoutSetBranchImpl.setCreateDate(layoutSetBranch.getCreateDate());
3557                    layoutSetBranchImpl.setModifiedDate(layoutSetBranch.getModifiedDate());
3558                    layoutSetBranchImpl.setPrivateLayout(layoutSetBranch.isPrivateLayout());
3559                    layoutSetBranchImpl.setName(layoutSetBranch.getName());
3560                    layoutSetBranchImpl.setDescription(layoutSetBranch.getDescription());
3561                    layoutSetBranchImpl.setMaster(layoutSetBranch.isMaster());
3562                    layoutSetBranchImpl.setLogoId(layoutSetBranch.getLogoId());
3563                    layoutSetBranchImpl.setThemeId(layoutSetBranch.getThemeId());
3564                    layoutSetBranchImpl.setColorSchemeId(layoutSetBranch.getColorSchemeId());
3565                    layoutSetBranchImpl.setWapThemeId(layoutSetBranch.getWapThemeId());
3566                    layoutSetBranchImpl.setWapColorSchemeId(layoutSetBranch.getWapColorSchemeId());
3567                    layoutSetBranchImpl.setCss(layoutSetBranch.getCss());
3568                    layoutSetBranchImpl.setSettings(layoutSetBranch.getSettings());
3569                    layoutSetBranchImpl.setLayoutSetPrototypeUuid(layoutSetBranch.getLayoutSetPrototypeUuid());
3570                    layoutSetBranchImpl.setLayoutSetPrototypeLinkEnabled(layoutSetBranch.isLayoutSetPrototypeLinkEnabled());
3571    
3572                    return layoutSetBranchImpl;
3573            }
3574    
3575            /**
3576             * Returns the layout set branch with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
3577             *
3578             * @param primaryKey the primary key of the layout set branch
3579             * @return the layout set branch
3580             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
3581             */
3582            @Override
3583            public LayoutSetBranch findByPrimaryKey(Serializable primaryKey)
3584                    throws NoSuchLayoutSetBranchException {
3585                    LayoutSetBranch layoutSetBranch = fetchByPrimaryKey(primaryKey);
3586    
3587                    if (layoutSetBranch == null) {
3588                            if (_log.isWarnEnabled()) {
3589                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3590                            }
3591    
3592                            throw new NoSuchLayoutSetBranchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3593                                    primaryKey);
3594                    }
3595    
3596                    return layoutSetBranch;
3597            }
3598    
3599            /**
3600             * Returns the layout set branch with the primary key or throws a {@link NoSuchLayoutSetBranchException} if it could not be found.
3601             *
3602             * @param layoutSetBranchId the primary key of the layout set branch
3603             * @return the layout set branch
3604             * @throws NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
3605             */
3606            @Override
3607            public LayoutSetBranch findByPrimaryKey(long layoutSetBranchId)
3608                    throws NoSuchLayoutSetBranchException {
3609                    return findByPrimaryKey((Serializable)layoutSetBranchId);
3610            }
3611    
3612            /**
3613             * Returns the layout set branch with the primary key or returns <code>null</code> if it could not be found.
3614             *
3615             * @param primaryKey the primary key of the layout set branch
3616             * @return the layout set branch, or <code>null</code> if a layout set branch with the primary key could not be found
3617             */
3618            @Override
3619            public LayoutSetBranch fetchByPrimaryKey(Serializable primaryKey) {
3620                    LayoutSetBranch layoutSetBranch = (LayoutSetBranch)entityCache.getResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3621                                    LayoutSetBranchImpl.class, primaryKey);
3622    
3623                    if (layoutSetBranch == _nullLayoutSetBranch) {
3624                            return null;
3625                    }
3626    
3627                    if (layoutSetBranch == null) {
3628                            Session session = null;
3629    
3630                            try {
3631                                    session = openSession();
3632    
3633                                    layoutSetBranch = (LayoutSetBranch)session.get(LayoutSetBranchImpl.class,
3634                                                    primaryKey);
3635    
3636                                    if (layoutSetBranch != null) {
3637                                            cacheResult(layoutSetBranch);
3638                                    }
3639                                    else {
3640                                            entityCache.putResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3641                                                    LayoutSetBranchImpl.class, primaryKey,
3642                                                    _nullLayoutSetBranch);
3643                                    }
3644                            }
3645                            catch (Exception e) {
3646                                    entityCache.removeResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3647                                            LayoutSetBranchImpl.class, primaryKey);
3648    
3649                                    throw processException(e);
3650                            }
3651                            finally {
3652                                    closeSession(session);
3653                            }
3654                    }
3655    
3656                    return layoutSetBranch;
3657            }
3658    
3659            /**
3660             * Returns the layout set branch with the primary key or returns <code>null</code> if it could not be found.
3661             *
3662             * @param layoutSetBranchId the primary key of the layout set branch
3663             * @return the layout set branch, or <code>null</code> if a layout set branch with the primary key could not be found
3664             */
3665            @Override
3666            public LayoutSetBranch fetchByPrimaryKey(long layoutSetBranchId) {
3667                    return fetchByPrimaryKey((Serializable)layoutSetBranchId);
3668            }
3669    
3670            @Override
3671            public Map<Serializable, LayoutSetBranch> fetchByPrimaryKeys(
3672                    Set<Serializable> primaryKeys) {
3673                    if (primaryKeys.isEmpty()) {
3674                            return Collections.emptyMap();
3675                    }
3676    
3677                    Map<Serializable, LayoutSetBranch> map = new HashMap<Serializable, LayoutSetBranch>();
3678    
3679                    if (primaryKeys.size() == 1) {
3680                            Iterator<Serializable> iterator = primaryKeys.iterator();
3681    
3682                            Serializable primaryKey = iterator.next();
3683    
3684                            LayoutSetBranch layoutSetBranch = fetchByPrimaryKey(primaryKey);
3685    
3686                            if (layoutSetBranch != null) {
3687                                    map.put(primaryKey, layoutSetBranch);
3688                            }
3689    
3690                            return map;
3691                    }
3692    
3693                    Set<Serializable> uncachedPrimaryKeys = null;
3694    
3695                    for (Serializable primaryKey : primaryKeys) {
3696                            LayoutSetBranch layoutSetBranch = (LayoutSetBranch)entityCache.getResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3697                                            LayoutSetBranchImpl.class, primaryKey);
3698    
3699                            if (layoutSetBranch == null) {
3700                                    if (uncachedPrimaryKeys == null) {
3701                                            uncachedPrimaryKeys = new HashSet<Serializable>();
3702                                    }
3703    
3704                                    uncachedPrimaryKeys.add(primaryKey);
3705                            }
3706                            else {
3707                                    map.put(primaryKey, layoutSetBranch);
3708                            }
3709                    }
3710    
3711                    if (uncachedPrimaryKeys == null) {
3712                            return map;
3713                    }
3714    
3715                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
3716                                    1);
3717    
3718                    query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE_PKS_IN);
3719    
3720                    for (Serializable primaryKey : uncachedPrimaryKeys) {
3721                            query.append(String.valueOf(primaryKey));
3722    
3723                            query.append(StringPool.COMMA);
3724                    }
3725    
3726                    query.setIndex(query.index() - 1);
3727    
3728                    query.append(StringPool.CLOSE_PARENTHESIS);
3729    
3730                    String sql = query.toString();
3731    
3732                    Session session = null;
3733    
3734                    try {
3735                            session = openSession();
3736    
3737                            Query q = session.createQuery(sql);
3738    
3739                            for (LayoutSetBranch layoutSetBranch : (List<LayoutSetBranch>)q.list()) {
3740                                    map.put(layoutSetBranch.getPrimaryKeyObj(), layoutSetBranch);
3741    
3742                                    cacheResult(layoutSetBranch);
3743    
3744                                    uncachedPrimaryKeys.remove(layoutSetBranch.getPrimaryKeyObj());
3745                            }
3746    
3747                            for (Serializable primaryKey : uncachedPrimaryKeys) {
3748                                    entityCache.putResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
3749                                            LayoutSetBranchImpl.class, primaryKey, _nullLayoutSetBranch);
3750                            }
3751                    }
3752                    catch (Exception e) {
3753                            throw processException(e);
3754                    }
3755                    finally {
3756                            closeSession(session);
3757                    }
3758    
3759                    return map;
3760            }
3761    
3762            /**
3763             * Returns all the layout set branchs.
3764             *
3765             * @return the layout set branchs
3766             */
3767            @Override
3768            public List<LayoutSetBranch> findAll() {
3769                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3770            }
3771    
3772            /**
3773             * Returns a range of all the layout set branchs.
3774             *
3775             * <p>
3776             * 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 LayoutSetBranchModelImpl}. 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.
3777             * </p>
3778             *
3779             * @param start the lower bound of the range of layout set branchs
3780             * @param end the upper bound of the range of layout set branchs (not inclusive)
3781             * @return the range of layout set branchs
3782             */
3783            @Override
3784            public List<LayoutSetBranch> findAll(int start, int end) {
3785                    return findAll(start, end, null);
3786            }
3787    
3788            /**
3789             * Returns an ordered range of all the layout set branchs.
3790             *
3791             * <p>
3792             * 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 LayoutSetBranchModelImpl}. 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.
3793             * </p>
3794             *
3795             * @param start the lower bound of the range of layout set branchs
3796             * @param end the upper bound of the range of layout set branchs (not inclusive)
3797             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3798             * @return the ordered range of layout set branchs
3799             */
3800            @Override
3801            public List<LayoutSetBranch> findAll(int start, int end,
3802                    OrderByComparator<LayoutSetBranch> orderByComparator) {
3803                    return findAll(start, end, orderByComparator, true);
3804            }
3805    
3806            /**
3807             * Returns an ordered range of all the layout set branchs.
3808             *
3809             * <p>
3810             * 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 LayoutSetBranchModelImpl}. 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.
3811             * </p>
3812             *
3813             * @param start the lower bound of the range of layout set branchs
3814             * @param end the upper bound of the range of layout set branchs (not inclusive)
3815             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3816             * @param retrieveFromCache whether to retrieve from the finder cache
3817             * @return the ordered range of layout set branchs
3818             */
3819            @Override
3820            public List<LayoutSetBranch> findAll(int start, int end,
3821                    OrderByComparator<LayoutSetBranch> orderByComparator,
3822                    boolean retrieveFromCache) {
3823                    boolean pagination = true;
3824                    FinderPath finderPath = null;
3825                    Object[] finderArgs = null;
3826    
3827                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3828                                    (orderByComparator == null)) {
3829                            pagination = false;
3830                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3831                            finderArgs = FINDER_ARGS_EMPTY;
3832                    }
3833                    else {
3834                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3835                            finderArgs = new Object[] { start, end, orderByComparator };
3836                    }
3837    
3838                    List<LayoutSetBranch> list = null;
3839    
3840                    if (retrieveFromCache) {
3841                            list = (List<LayoutSetBranch>)finderCache.getResult(finderPath,
3842                                            finderArgs, this);
3843                    }
3844    
3845                    if (list == null) {
3846                            StringBundler query = null;
3847                            String sql = null;
3848    
3849                            if (orderByComparator != null) {
3850                                    query = new StringBundler(2 +
3851                                                    (orderByComparator.getOrderByFields().length * 3));
3852    
3853                                    query.append(_SQL_SELECT_LAYOUTSETBRANCH);
3854    
3855                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3856                                            orderByComparator);
3857    
3858                                    sql = query.toString();
3859                            }
3860                            else {
3861                                    sql = _SQL_SELECT_LAYOUTSETBRANCH;
3862    
3863                                    if (pagination) {
3864                                            sql = sql.concat(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
3865                                    }
3866                            }
3867    
3868                            Session session = null;
3869    
3870                            try {
3871                                    session = openSession();
3872    
3873                                    Query q = session.createQuery(sql);
3874    
3875                                    if (!pagination) {
3876                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
3877                                                            getDialect(), start, end, false);
3878    
3879                                            Collections.sort(list);
3880    
3881                                            list = Collections.unmodifiableList(list);
3882                                    }
3883                                    else {
3884                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
3885                                                            getDialect(), start, end);
3886                                    }
3887    
3888                                    cacheResult(list);
3889    
3890                                    finderCache.putResult(finderPath, finderArgs, list);
3891                            }
3892                            catch (Exception e) {
3893                                    finderCache.removeResult(finderPath, finderArgs);
3894    
3895                                    throw processException(e);
3896                            }
3897                            finally {
3898                                    closeSession(session);
3899                            }
3900                    }
3901    
3902                    return list;
3903            }
3904    
3905            /**
3906             * Removes all the layout set branchs from the database.
3907             *
3908             */
3909            @Override
3910            public void removeAll() {
3911                    for (LayoutSetBranch layoutSetBranch : findAll()) {
3912                            remove(layoutSetBranch);
3913                    }
3914            }
3915    
3916            /**
3917             * Returns the number of layout set branchs.
3918             *
3919             * @return the number of layout set branchs
3920             */
3921            @Override
3922            public int countAll() {
3923                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
3924                                    FINDER_ARGS_EMPTY, this);
3925    
3926                    if (count == null) {
3927                            Session session = null;
3928    
3929                            try {
3930                                    session = openSession();
3931    
3932                                    Query q = session.createQuery(_SQL_COUNT_LAYOUTSETBRANCH);
3933    
3934                                    count = (Long)q.uniqueResult();
3935    
3936                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
3937                                            count);
3938                            }
3939                            catch (Exception e) {
3940                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
3941                                            FINDER_ARGS_EMPTY);
3942    
3943                                    throw processException(e);
3944                            }
3945                            finally {
3946                                    closeSession(session);
3947                            }
3948                    }
3949    
3950                    return count.intValue();
3951            }
3952    
3953            @Override
3954            public Set<String> getBadColumnNames() {
3955                    return _badColumnNames;
3956            }
3957    
3958            @Override
3959            protected Map<String, Integer> getTableColumnsMap() {
3960                    return LayoutSetBranchModelImpl.TABLE_COLUMNS_MAP;
3961            }
3962    
3963            /**
3964             * Initializes the layout set branch persistence.
3965             */
3966            public void afterPropertiesSet() {
3967            }
3968    
3969            public void destroy() {
3970                    entityCache.removeCache(LayoutSetBranchImpl.class.getName());
3971                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
3972                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3973                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3974            }
3975    
3976            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
3977            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
3978            private static final String _SQL_SELECT_LAYOUTSETBRANCH = "SELECT layoutSetBranch FROM LayoutSetBranch layoutSetBranch";
3979            private static final String _SQL_SELECT_LAYOUTSETBRANCH_WHERE_PKS_IN = "SELECT layoutSetBranch FROM LayoutSetBranch layoutSetBranch WHERE layoutSetBranchId IN (";
3980            private static final String _SQL_SELECT_LAYOUTSETBRANCH_WHERE = "SELECT layoutSetBranch FROM LayoutSetBranch layoutSetBranch WHERE ";
3981            private static final String _SQL_COUNT_LAYOUTSETBRANCH = "SELECT COUNT(layoutSetBranch) FROM LayoutSetBranch layoutSetBranch";
3982            private static final String _SQL_COUNT_LAYOUTSETBRANCH_WHERE = "SELECT COUNT(layoutSetBranch) FROM LayoutSetBranch layoutSetBranch WHERE ";
3983            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "layoutSetBranch.layoutSetBranchId";
3984            private static final String _FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE = "SELECT DISTINCT {layoutSetBranch.*} FROM LayoutSetBranch layoutSetBranch WHERE ";
3985            private static final String _FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1 =
3986                    "SELECT {LayoutSetBranch.*} FROM (SELECT DISTINCT layoutSetBranch.layoutSetBranchId FROM LayoutSetBranch layoutSetBranch WHERE ";
3987            private static final String _FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2 =
3988                    ") TEMP_TABLE INNER JOIN LayoutSetBranch ON TEMP_TABLE.layoutSetBranchId = LayoutSetBranch.layoutSetBranchId";
3989            private static final String _FILTER_SQL_COUNT_LAYOUTSETBRANCH_WHERE = "SELECT COUNT(DISTINCT layoutSetBranch.layoutSetBranchId) AS COUNT_VALUE FROM LayoutSetBranch layoutSetBranch WHERE ";
3990            private static final String _FILTER_ENTITY_ALIAS = "layoutSetBranch";
3991            private static final String _FILTER_ENTITY_TABLE = "LayoutSetBranch";
3992            private static final String _ORDER_BY_ENTITY_ALIAS = "layoutSetBranch.";
3993            private static final String _ORDER_BY_ENTITY_TABLE = "LayoutSetBranch.";
3994            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutSetBranch exists with the primary key ";
3995            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutSetBranch exists with the key {";
3996            private static final Log _log = LogFactoryUtil.getLog(LayoutSetBranchPersistenceImpl.class);
3997            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3998                                    "settings"
3999                            });
4000            private static final LayoutSetBranch _nullLayoutSetBranch = new LayoutSetBranchImpl() {
4001                            @Override
4002                            public Object clone() {
4003                                    return this;
4004                            }
4005    
4006                            @Override
4007                            public CacheModel<LayoutSetBranch> toCacheModel() {
4008                                    return _nullLayoutSetBranchCacheModel;
4009                            }
4010                    };
4011    
4012            private static final CacheModel<LayoutSetBranch> _nullLayoutSetBranchCacheModel =
4013                    new NullCacheModel();
4014    
4015            private static class NullCacheModel implements CacheModel<LayoutSetBranch>,
4016                    MVCCModel {
4017                    @Override
4018                    public long getMvccVersion() {
4019                            return -1;
4020                    }
4021    
4022                    @Override
4023                    public void setMvccVersion(long mvccVersion) {
4024                    }
4025    
4026                    @Override
4027                    public LayoutSetBranch toEntityModel() {
4028                            return _nullLayoutSetBranch;
4029                    }
4030            }
4031    }