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