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