001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchLayoutSetBranchException;
018    import com.liferay.portal.NoSuchModelException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.SQLQuery;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.exception.SystemException;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
032    import com.liferay.portal.kernel.util.GetterUtil;
033    import com.liferay.portal.kernel.util.InstanceFactory;
034    import com.liferay.portal.kernel.util.OrderByComparator;
035    import com.liferay.portal.kernel.util.StringBundler;
036    import com.liferay.portal.kernel.util.StringPool;
037    import com.liferay.portal.kernel.util.StringUtil;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.LayoutSetBranch;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.model.impl.LayoutSetBranchImpl;
042    import com.liferay.portal.model.impl.LayoutSetBranchModelImpl;
043    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
044    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045    
046    import java.io.Serializable;
047    
048    import java.util.ArrayList;
049    import java.util.Collections;
050    import java.util.List;
051    
052    /**
053     * The persistence implementation for the layout set branch service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see LayoutSetBranchPersistence
061     * @see LayoutSetBranchUtil
062     * @generated
063     */
064    public class LayoutSetBranchPersistenceImpl extends BasePersistenceImpl<LayoutSetBranch>
065            implements LayoutSetBranchPersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * 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.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = LayoutSetBranchImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List1";
074            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List2";
076            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
077                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
078                            LayoutSetBranchImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
079                            "findByGroupId",
080                            new String[] {
081                                    Long.class.getName(),
082                                    
083                            "java.lang.Integer", "java.lang.Integer",
084                                    "com.liferay.portal.kernel.util.OrderByComparator"
085                            });
086            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
087                    new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
088                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
089                            LayoutSetBranchImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
091                            new String[] { Long.class.getName() },
092                            LayoutSetBranchModelImpl.GROUPID_COLUMN_BITMASK);
093            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
094                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
096                            new String[] { Long.class.getName() });
097            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
098                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
099                            LayoutSetBranchImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
100                            "findByG_P",
101                            new String[] {
102                                    Long.class.getName(), Boolean.class.getName(),
103                                    
104                            "java.lang.Integer", "java.lang.Integer",
105                                    "com.liferay.portal.kernel.util.OrderByComparator"
106                            });
107            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
108                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
109                            LayoutSetBranchImpl.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
111                            new String[] { Long.class.getName(), Boolean.class.getName() },
112                            LayoutSetBranchModelImpl.GROUPID_COLUMN_BITMASK |
113                            LayoutSetBranchModelImpl.PRIVATELAYOUT_COLUMN_BITMASK);
114            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
115                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
116                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
117                            new String[] { Long.class.getName(), Boolean.class.getName() });
118            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_N = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
119                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
120                            LayoutSetBranchImpl.class, FINDER_CLASS_NAME_ENTITY,
121                            "fetchByG_P_N",
122                            new String[] {
123                                    Long.class.getName(), Boolean.class.getName(),
124                                    String.class.getName()
125                            },
126                            LayoutSetBranchModelImpl.GROUPID_COLUMN_BITMASK |
127                            LayoutSetBranchModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
128                            LayoutSetBranchModelImpl.NAME_COLUMN_BITMASK);
129            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
130                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
131                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N",
132                            new String[] {
133                                    Long.class.getName(), Boolean.class.getName(),
134                                    String.class.getName()
135                            });
136            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
137                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
138                            LayoutSetBranchImpl.class,
139                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
140            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
141                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED,
142                            LayoutSetBranchImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
143                            "findAll", new String[0]);
144            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
145                            LayoutSetBranchModelImpl.FINDER_CACHE_ENABLED, Long.class,
146                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
147    
148            /**
149             * Caches the layout set branch in the entity cache if it is enabled.
150             *
151             * @param layoutSetBranch the layout set branch
152             */
153            public void cacheResult(LayoutSetBranch layoutSetBranch) {
154                    EntityCacheUtil.putResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
155                            LayoutSetBranchImpl.class, layoutSetBranch.getPrimaryKey(),
156                            layoutSetBranch);
157    
158                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
159                            new Object[] {
160                                    Long.valueOf(layoutSetBranch.getGroupId()),
161                                    Boolean.valueOf(layoutSetBranch.getPrivateLayout()),
162                                    
163                            layoutSetBranch.getName()
164                            }, layoutSetBranch);
165    
166                    layoutSetBranch.resetOriginalValues();
167            }
168    
169            /**
170             * Caches the layout set branchs in the entity cache if it is enabled.
171             *
172             * @param layoutSetBranchs the layout set branchs
173             */
174            public void cacheResult(List<LayoutSetBranch> layoutSetBranchs) {
175                    for (LayoutSetBranch layoutSetBranch : layoutSetBranchs) {
176                            if (EntityCacheUtil.getResult(
177                                                    LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
178                                                    LayoutSetBranchImpl.class,
179                                                    layoutSetBranch.getPrimaryKey()) == null) {
180                                    cacheResult(layoutSetBranch);
181                            }
182                            else {
183                                    layoutSetBranch.resetOriginalValues();
184                            }
185                    }
186            }
187    
188            /**
189             * Clears the cache for all layout set branchs.
190             *
191             * <p>
192             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
193             * </p>
194             */
195            @Override
196            public void clearCache() {
197                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
198                            CacheRegistryUtil.clear(LayoutSetBranchImpl.class.getName());
199                    }
200    
201                    EntityCacheUtil.clearCache(LayoutSetBranchImpl.class.getName());
202    
203                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
204                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
205                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
206            }
207    
208            /**
209             * Clears the cache for the layout set branch.
210             *
211             * <p>
212             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
213             * </p>
214             */
215            @Override
216            public void clearCache(LayoutSetBranch layoutSetBranch) {
217                    EntityCacheUtil.removeResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
218                            LayoutSetBranchImpl.class, layoutSetBranch.getPrimaryKey());
219    
220                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
221                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
222    
223                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N,
224                            new Object[] {
225                                    Long.valueOf(layoutSetBranch.getGroupId()),
226                                    Boolean.valueOf(layoutSetBranch.getPrivateLayout()),
227                                    
228                            layoutSetBranch.getName()
229                            });
230            }
231    
232            /**
233             * Creates a new layout set branch with the primary key. Does not add the layout set branch to the database.
234             *
235             * @param layoutSetBranchId the primary key for the new layout set branch
236             * @return the new layout set branch
237             */
238            public LayoutSetBranch create(long layoutSetBranchId) {
239                    LayoutSetBranch layoutSetBranch = new LayoutSetBranchImpl();
240    
241                    layoutSetBranch.setNew(true);
242                    layoutSetBranch.setPrimaryKey(layoutSetBranchId);
243    
244                    return layoutSetBranch;
245            }
246    
247            /**
248             * Removes the layout set branch with the primary key from the database. Also notifies the appropriate model listeners.
249             *
250             * @param primaryKey the primary key of the layout set branch
251             * @return the layout set branch that was removed
252             * @throws com.liferay.portal.NoSuchModelException if a layout set branch with the primary key could not be found
253             * @throws SystemException if a system exception occurred
254             */
255            @Override
256            public LayoutSetBranch remove(Serializable primaryKey)
257                    throws NoSuchModelException, SystemException {
258                    return remove(((Long)primaryKey).longValue());
259            }
260    
261            /**
262             * Removes the layout set branch with the primary key from the database. Also notifies the appropriate model listeners.
263             *
264             * @param layoutSetBranchId the primary key of the layout set branch
265             * @return the layout set branch that was removed
266             * @throws com.liferay.portal.NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
267             * @throws SystemException if a system exception occurred
268             */
269            public LayoutSetBranch remove(long layoutSetBranchId)
270                    throws NoSuchLayoutSetBranchException, SystemException {
271                    Session session = null;
272    
273                    try {
274                            session = openSession();
275    
276                            LayoutSetBranch layoutSetBranch = (LayoutSetBranch)session.get(LayoutSetBranchImpl.class,
277                                            Long.valueOf(layoutSetBranchId));
278    
279                            if (layoutSetBranch == null) {
280                                    if (_log.isWarnEnabled()) {
281                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
282                                                    layoutSetBranchId);
283                                    }
284    
285                                    throw new NoSuchLayoutSetBranchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
286                                            layoutSetBranchId);
287                            }
288    
289                            return layoutSetBranchPersistence.remove(layoutSetBranch);
290                    }
291                    catch (NoSuchLayoutSetBranchException nsee) {
292                            throw nsee;
293                    }
294                    catch (Exception e) {
295                            throw processException(e);
296                    }
297                    finally {
298                            closeSession(session);
299                    }
300            }
301    
302            /**
303             * Removes the layout set branch from the database. Also notifies the appropriate model listeners.
304             *
305             * @param layoutSetBranch the layout set branch
306             * @return the layout set branch that was removed
307             * @throws SystemException if a system exception occurred
308             */
309            @Override
310            public LayoutSetBranch remove(LayoutSetBranch layoutSetBranch)
311                    throws SystemException {
312                    return super.remove(layoutSetBranch);
313            }
314    
315            @Override
316            protected LayoutSetBranch removeImpl(LayoutSetBranch layoutSetBranch)
317                    throws SystemException {
318                    layoutSetBranch = toUnwrappedModel(layoutSetBranch);
319    
320                    Session session = null;
321    
322                    try {
323                            session = openSession();
324    
325                            BatchSessionUtil.delete(session, layoutSetBranch);
326                    }
327                    catch (Exception e) {
328                            throw processException(e);
329                    }
330                    finally {
331                            closeSession(session);
332                    }
333    
334                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
335                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
336    
337                    LayoutSetBranchModelImpl layoutSetBranchModelImpl = (LayoutSetBranchModelImpl)layoutSetBranch;
338    
339                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N,
340                            new Object[] {
341                                    Long.valueOf(layoutSetBranchModelImpl.getGroupId()),
342                                    Boolean.valueOf(layoutSetBranchModelImpl.getPrivateLayout()),
343                                    
344                            layoutSetBranchModelImpl.getName()
345                            });
346    
347                    EntityCacheUtil.removeResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
348                            LayoutSetBranchImpl.class, layoutSetBranch.getPrimaryKey());
349    
350                    return layoutSetBranch;
351            }
352    
353            @Override
354            public LayoutSetBranch updateImpl(
355                    com.liferay.portal.model.LayoutSetBranch layoutSetBranch, boolean merge)
356                    throws SystemException {
357                    layoutSetBranch = toUnwrappedModel(layoutSetBranch);
358    
359                    boolean isNew = layoutSetBranch.isNew();
360    
361                    LayoutSetBranchModelImpl layoutSetBranchModelImpl = (LayoutSetBranchModelImpl)layoutSetBranch;
362    
363                    Session session = null;
364    
365                    try {
366                            session = openSession();
367    
368                            BatchSessionUtil.update(session, layoutSetBranch, merge);
369    
370                            layoutSetBranch.setNew(false);
371                    }
372                    catch (Exception e) {
373                            throw processException(e);
374                    }
375                    finally {
376                            closeSession(session);
377                    }
378    
379                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
380    
381                    if (isNew || !LayoutSetBranchModelImpl.COLUMN_BITMASK_ENABLED) {
382                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
383                    }
384    
385                    else {
386                            if ((layoutSetBranchModelImpl.getColumnBitmask() &
387                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
388                                    Object[] args = new Object[] {
389                                                    Long.valueOf(layoutSetBranchModelImpl.getOriginalGroupId())
390                                            };
391    
392                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
393                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
394                                            args);
395    
396                                    args = new Object[] {
397                                                    Long.valueOf(layoutSetBranchModelImpl.getGroupId())
398                                            };
399    
400                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
401                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
402                                            args);
403                            }
404    
405                            if ((layoutSetBranchModelImpl.getColumnBitmask() &
406                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
407                                    Object[] args = new Object[] {
408                                                    Long.valueOf(layoutSetBranchModelImpl.getOriginalGroupId()),
409                                                    Boolean.valueOf(layoutSetBranchModelImpl.getOriginalPrivateLayout())
410                                            };
411    
412                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
413                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
414                                            args);
415    
416                                    args = new Object[] {
417                                                    Long.valueOf(layoutSetBranchModelImpl.getGroupId()),
418                                                    Boolean.valueOf(layoutSetBranchModelImpl.getPrivateLayout())
419                                            };
420    
421                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
422                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
423                                            args);
424                            }
425                    }
426    
427                    EntityCacheUtil.putResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
428                            LayoutSetBranchImpl.class, layoutSetBranch.getPrimaryKey(),
429                            layoutSetBranch);
430    
431                    if (isNew) {
432                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
433                                    new Object[] {
434                                            Long.valueOf(layoutSetBranch.getGroupId()),
435                                            Boolean.valueOf(layoutSetBranch.getPrivateLayout()),
436                                            
437                                    layoutSetBranch.getName()
438                                    }, layoutSetBranch);
439                    }
440                    else {
441                            if ((layoutSetBranchModelImpl.getColumnBitmask() &
442                                            FINDER_PATH_FETCH_BY_G_P_N.getColumnBitmask()) != 0) {
443                                    Object[] args = new Object[] {
444                                                    Long.valueOf(layoutSetBranchModelImpl.getOriginalGroupId()),
445                                                    Boolean.valueOf(layoutSetBranchModelImpl.getOriginalPrivateLayout()),
446                                                    
447                                                    layoutSetBranchModelImpl.getOriginalName()
448                                            };
449    
450                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N, args);
451                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, args);
452    
453                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
454                                            new Object[] {
455                                                    Long.valueOf(layoutSetBranch.getGroupId()),
456                                                    Boolean.valueOf(layoutSetBranch.getPrivateLayout()),
457                                                    
458                                            layoutSetBranch.getName()
459                                            }, layoutSetBranch);
460                            }
461                    }
462    
463                    return layoutSetBranch;
464            }
465    
466            protected LayoutSetBranch toUnwrappedModel(LayoutSetBranch layoutSetBranch) {
467                    if (layoutSetBranch instanceof LayoutSetBranchImpl) {
468                            return layoutSetBranch;
469                    }
470    
471                    LayoutSetBranchImpl layoutSetBranchImpl = new LayoutSetBranchImpl();
472    
473                    layoutSetBranchImpl.setNew(layoutSetBranch.isNew());
474                    layoutSetBranchImpl.setPrimaryKey(layoutSetBranch.getPrimaryKey());
475    
476                    layoutSetBranchImpl.setLayoutSetBranchId(layoutSetBranch.getLayoutSetBranchId());
477                    layoutSetBranchImpl.setGroupId(layoutSetBranch.getGroupId());
478                    layoutSetBranchImpl.setCompanyId(layoutSetBranch.getCompanyId());
479                    layoutSetBranchImpl.setUserId(layoutSetBranch.getUserId());
480                    layoutSetBranchImpl.setUserName(layoutSetBranch.getUserName());
481                    layoutSetBranchImpl.setCreateDate(layoutSetBranch.getCreateDate());
482                    layoutSetBranchImpl.setModifiedDate(layoutSetBranch.getModifiedDate());
483                    layoutSetBranchImpl.setPrivateLayout(layoutSetBranch.isPrivateLayout());
484                    layoutSetBranchImpl.setName(layoutSetBranch.getName());
485                    layoutSetBranchImpl.setDescription(layoutSetBranch.getDescription());
486                    layoutSetBranchImpl.setMaster(layoutSetBranch.isMaster());
487    
488                    return layoutSetBranchImpl;
489            }
490    
491            /**
492             * Returns the layout set branch with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
493             *
494             * @param primaryKey the primary key of the layout set branch
495             * @return the layout set branch
496             * @throws com.liferay.portal.NoSuchModelException if a layout set branch with the primary key could not be found
497             * @throws SystemException if a system exception occurred
498             */
499            @Override
500            public LayoutSetBranch findByPrimaryKey(Serializable primaryKey)
501                    throws NoSuchModelException, SystemException {
502                    return findByPrimaryKey(((Long)primaryKey).longValue());
503            }
504    
505            /**
506             * Returns the layout set branch with the primary key or throws a {@link com.liferay.portal.NoSuchLayoutSetBranchException} if it could not be found.
507             *
508             * @param layoutSetBranchId the primary key of the layout set branch
509             * @return the layout set branch
510             * @throws com.liferay.portal.NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
511             * @throws SystemException if a system exception occurred
512             */
513            public LayoutSetBranch findByPrimaryKey(long layoutSetBranchId)
514                    throws NoSuchLayoutSetBranchException, SystemException {
515                    LayoutSetBranch layoutSetBranch = fetchByPrimaryKey(layoutSetBranchId);
516    
517                    if (layoutSetBranch == null) {
518                            if (_log.isWarnEnabled()) {
519                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + layoutSetBranchId);
520                            }
521    
522                            throw new NoSuchLayoutSetBranchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
523                                    layoutSetBranchId);
524                    }
525    
526                    return layoutSetBranch;
527            }
528    
529            /**
530             * Returns the layout set branch with the primary key or returns <code>null</code> if it could not be found.
531             *
532             * @param primaryKey the primary key of the layout set branch
533             * @return the layout set branch, or <code>null</code> if a layout set branch with the primary key could not be found
534             * @throws SystemException if a system exception occurred
535             */
536            @Override
537            public LayoutSetBranch fetchByPrimaryKey(Serializable primaryKey)
538                    throws SystemException {
539                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
540            }
541    
542            /**
543             * Returns the layout set branch with the primary key or returns <code>null</code> if it could not be found.
544             *
545             * @param layoutSetBranchId the primary key of the layout set branch
546             * @return the layout set branch, or <code>null</code> if a layout set branch with the primary key could not be found
547             * @throws SystemException if a system exception occurred
548             */
549            public LayoutSetBranch fetchByPrimaryKey(long layoutSetBranchId)
550                    throws SystemException {
551                    LayoutSetBranch layoutSetBranch = (LayoutSetBranch)EntityCacheUtil.getResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
552                                    LayoutSetBranchImpl.class, layoutSetBranchId);
553    
554                    if (layoutSetBranch == _nullLayoutSetBranch) {
555                            return null;
556                    }
557    
558                    if (layoutSetBranch == null) {
559                            Session session = null;
560    
561                            boolean hasException = false;
562    
563                            try {
564                                    session = openSession();
565    
566                                    layoutSetBranch = (LayoutSetBranch)session.get(LayoutSetBranchImpl.class,
567                                                    Long.valueOf(layoutSetBranchId));
568                            }
569                            catch (Exception e) {
570                                    hasException = true;
571    
572                                    throw processException(e);
573                            }
574                            finally {
575                                    if (layoutSetBranch != null) {
576                                            cacheResult(layoutSetBranch);
577                                    }
578                                    else if (!hasException) {
579                                            EntityCacheUtil.putResult(LayoutSetBranchModelImpl.ENTITY_CACHE_ENABLED,
580                                                    LayoutSetBranchImpl.class, layoutSetBranchId,
581                                                    _nullLayoutSetBranch);
582                                    }
583    
584                                    closeSession(session);
585                            }
586                    }
587    
588                    return layoutSetBranch;
589            }
590    
591            /**
592             * Returns all the layout set branchs where groupId = &#63;.
593             *
594             * @param groupId the group ID
595             * @return the matching layout set branchs
596             * @throws SystemException if a system exception occurred
597             */
598            public List<LayoutSetBranch> findByGroupId(long groupId)
599                    throws SystemException {
600                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
601            }
602    
603            /**
604             * Returns a range of all the layout set branchs where groupId = &#63;.
605             *
606             * <p>
607             * 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.
608             * </p>
609             *
610             * @param groupId the group ID
611             * @param start the lower bound of the range of layout set branchs
612             * @param end the upper bound of the range of layout set branchs (not inclusive)
613             * @return the range of matching layout set branchs
614             * @throws SystemException if a system exception occurred
615             */
616            public List<LayoutSetBranch> findByGroupId(long groupId, int start, int end)
617                    throws SystemException {
618                    return findByGroupId(groupId, start, end, null);
619            }
620    
621            /**
622             * Returns an ordered range of all the layout set branchs where groupId = &#63;.
623             *
624             * <p>
625             * 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.
626             * </p>
627             *
628             * @param groupId the group ID
629             * @param start the lower bound of the range of layout set branchs
630             * @param end the upper bound of the range of layout set branchs (not inclusive)
631             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
632             * @return the ordered range of matching layout set branchs
633             * @throws SystemException if a system exception occurred
634             */
635            public List<LayoutSetBranch> findByGroupId(long groupId, int start,
636                    int end, OrderByComparator orderByComparator) throws SystemException {
637                    FinderPath finderPath = null;
638                    Object[] finderArgs = null;
639    
640                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
641                                    (orderByComparator == null)) {
642                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
643                            finderArgs = new Object[] { groupId };
644                    }
645                    else {
646                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
647                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
648                    }
649    
650                    List<LayoutSetBranch> list = (List<LayoutSetBranch>)FinderCacheUtil.getResult(finderPath,
651                                    finderArgs, this);
652    
653                    if (list == null) {
654                            StringBundler query = null;
655    
656                            if (orderByComparator != null) {
657                                    query = new StringBundler(3 +
658                                                    (orderByComparator.getOrderByFields().length * 3));
659                            }
660                            else {
661                                    query = new StringBundler(3);
662                            }
663    
664                            query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
665    
666                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
667    
668                            if (orderByComparator != null) {
669                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
670                                            orderByComparator);
671                            }
672    
673                            else {
674                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
675                            }
676    
677                            String sql = query.toString();
678    
679                            Session session = null;
680    
681                            try {
682                                    session = openSession();
683    
684                                    Query q = session.createQuery(sql);
685    
686                                    QueryPos qPos = QueryPos.getInstance(q);
687    
688                                    qPos.add(groupId);
689    
690                                    list = (List<LayoutSetBranch>)QueryUtil.list(q, getDialect(),
691                                                    start, end);
692                            }
693                            catch (Exception e) {
694                                    throw processException(e);
695                            }
696                            finally {
697                                    if (list == null) {
698                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
699                                    }
700                                    else {
701                                            cacheResult(list);
702    
703                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
704                                    }
705    
706                                    closeSession(session);
707                            }
708                    }
709    
710                    return list;
711            }
712    
713            /**
714             * Returns the first layout set branch in the ordered set where groupId = &#63;.
715             *
716             * <p>
717             * 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.
718             * </p>
719             *
720             * @param groupId the group ID
721             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
722             * @return the first matching layout set branch
723             * @throws com.liferay.portal.NoSuchLayoutSetBranchException if a matching layout set branch could not be found
724             * @throws SystemException if a system exception occurred
725             */
726            public LayoutSetBranch findByGroupId_First(long groupId,
727                    OrderByComparator orderByComparator)
728                    throws NoSuchLayoutSetBranchException, SystemException {
729                    List<LayoutSetBranch> list = findByGroupId(groupId, 0, 1,
730                                    orderByComparator);
731    
732                    if (list.isEmpty()) {
733                            StringBundler msg = new StringBundler(4);
734    
735                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
736    
737                            msg.append("groupId=");
738                            msg.append(groupId);
739    
740                            msg.append(StringPool.CLOSE_CURLY_BRACE);
741    
742                            throw new NoSuchLayoutSetBranchException(msg.toString());
743                    }
744                    else {
745                            return list.get(0);
746                    }
747            }
748    
749            /**
750             * Returns the last layout set branch in the ordered set where groupId = &#63;.
751             *
752             * <p>
753             * 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.
754             * </p>
755             *
756             * @param groupId the group ID
757             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
758             * @return the last matching layout set branch
759             * @throws com.liferay.portal.NoSuchLayoutSetBranchException if a matching layout set branch could not be found
760             * @throws SystemException if a system exception occurred
761             */
762            public LayoutSetBranch findByGroupId_Last(long groupId,
763                    OrderByComparator orderByComparator)
764                    throws NoSuchLayoutSetBranchException, SystemException {
765                    int count = countByGroupId(groupId);
766    
767                    List<LayoutSetBranch> list = findByGroupId(groupId, count - 1, count,
768                                    orderByComparator);
769    
770                    if (list.isEmpty()) {
771                            StringBundler msg = new StringBundler(4);
772    
773                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
774    
775                            msg.append("groupId=");
776                            msg.append(groupId);
777    
778                            msg.append(StringPool.CLOSE_CURLY_BRACE);
779    
780                            throw new NoSuchLayoutSetBranchException(msg.toString());
781                    }
782                    else {
783                            return list.get(0);
784                    }
785            }
786    
787            /**
788             * Returns the layout set branchs before and after the current layout set branch in the ordered set where groupId = &#63;.
789             *
790             * <p>
791             * 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.
792             * </p>
793             *
794             * @param layoutSetBranchId the primary key of the current layout set branch
795             * @param groupId the group ID
796             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
797             * @return the previous, current, and next layout set branch
798             * @throws com.liferay.portal.NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
799             * @throws SystemException if a system exception occurred
800             */
801            public LayoutSetBranch[] findByGroupId_PrevAndNext(long layoutSetBranchId,
802                    long groupId, OrderByComparator orderByComparator)
803                    throws NoSuchLayoutSetBranchException, SystemException {
804                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
805    
806                    Session session = null;
807    
808                    try {
809                            session = openSession();
810    
811                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
812    
813                            array[0] = getByGroupId_PrevAndNext(session, layoutSetBranch,
814                                            groupId, orderByComparator, true);
815    
816                            array[1] = layoutSetBranch;
817    
818                            array[2] = getByGroupId_PrevAndNext(session, layoutSetBranch,
819                                            groupId, orderByComparator, false);
820    
821                            return array;
822                    }
823                    catch (Exception e) {
824                            throw processException(e);
825                    }
826                    finally {
827                            closeSession(session);
828                    }
829            }
830    
831            protected LayoutSetBranch getByGroupId_PrevAndNext(Session session,
832                    LayoutSetBranch layoutSetBranch, long groupId,
833                    OrderByComparator orderByComparator, boolean previous) {
834                    StringBundler query = null;
835    
836                    if (orderByComparator != null) {
837                            query = new StringBundler(6 +
838                                            (orderByComparator.getOrderByFields().length * 6));
839                    }
840                    else {
841                            query = new StringBundler(3);
842                    }
843    
844                    query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
845    
846                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
847    
848                    if (orderByComparator != null) {
849                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
850    
851                            if (orderByConditionFields.length > 0) {
852                                    query.append(WHERE_AND);
853                            }
854    
855                            for (int i = 0; i < orderByConditionFields.length; i++) {
856                                    query.append(_ORDER_BY_ENTITY_ALIAS);
857                                    query.append(orderByConditionFields[i]);
858    
859                                    if ((i + 1) < orderByConditionFields.length) {
860                                            if (orderByComparator.isAscending() ^ previous) {
861                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
862                                            }
863                                            else {
864                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
865                                            }
866                                    }
867                                    else {
868                                            if (orderByComparator.isAscending() ^ previous) {
869                                                    query.append(WHERE_GREATER_THAN);
870                                            }
871                                            else {
872                                                    query.append(WHERE_LESSER_THAN);
873                                            }
874                                    }
875                            }
876    
877                            query.append(ORDER_BY_CLAUSE);
878    
879                            String[] orderByFields = orderByComparator.getOrderByFields();
880    
881                            for (int i = 0; i < orderByFields.length; i++) {
882                                    query.append(_ORDER_BY_ENTITY_ALIAS);
883                                    query.append(orderByFields[i]);
884    
885                                    if ((i + 1) < orderByFields.length) {
886                                            if (orderByComparator.isAscending() ^ previous) {
887                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
888                                            }
889                                            else {
890                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
891                                            }
892                                    }
893                                    else {
894                                            if (orderByComparator.isAscending() ^ previous) {
895                                                    query.append(ORDER_BY_ASC);
896                                            }
897                                            else {
898                                                    query.append(ORDER_BY_DESC);
899                                            }
900                                    }
901                            }
902                    }
903    
904                    else {
905                            query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
906                    }
907    
908                    String sql = query.toString();
909    
910                    Query q = session.createQuery(sql);
911    
912                    q.setFirstResult(0);
913                    q.setMaxResults(2);
914    
915                    QueryPos qPos = QueryPos.getInstance(q);
916    
917                    qPos.add(groupId);
918    
919                    if (orderByComparator != null) {
920                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
921    
922                            for (Object value : values) {
923                                    qPos.add(value);
924                            }
925                    }
926    
927                    List<LayoutSetBranch> list = q.list();
928    
929                    if (list.size() == 2) {
930                            return list.get(1);
931                    }
932                    else {
933                            return null;
934                    }
935            }
936    
937            /**
938             * Returns all the layout set branchs that the user has permission to view where groupId = &#63;.
939             *
940             * @param groupId the group ID
941             * @return the matching layout set branchs that the user has permission to view
942             * @throws SystemException if a system exception occurred
943             */
944            public List<LayoutSetBranch> filterFindByGroupId(long groupId)
945                    throws SystemException {
946                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
947                            QueryUtil.ALL_POS, null);
948            }
949    
950            /**
951             * Returns a range of all the layout set branchs that the user has permission to view where groupId = &#63;.
952             *
953             * <p>
954             * 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.
955             * </p>
956             *
957             * @param groupId the group ID
958             * @param start the lower bound of the range of layout set branchs
959             * @param end the upper bound of the range of layout set branchs (not inclusive)
960             * @return the range of matching layout set branchs that the user has permission to view
961             * @throws SystemException if a system exception occurred
962             */
963            public List<LayoutSetBranch> filterFindByGroupId(long groupId, int start,
964                    int end) throws SystemException {
965                    return filterFindByGroupId(groupId, start, end, null);
966            }
967    
968            /**
969             * Returns an ordered range of all the layout set branchs that the user has permissions to view where groupId = &#63;.
970             *
971             * <p>
972             * 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.
973             * </p>
974             *
975             * @param groupId the group ID
976             * @param start the lower bound of the range of layout set branchs
977             * @param end the upper bound of the range of layout set branchs (not inclusive)
978             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
979             * @return the ordered range of matching layout set branchs that the user has permission to view
980             * @throws SystemException if a system exception occurred
981             */
982            public List<LayoutSetBranch> filterFindByGroupId(long groupId, int start,
983                    int end, OrderByComparator orderByComparator) throws SystemException {
984                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
985                            return findByGroupId(groupId, start, end, orderByComparator);
986                    }
987    
988                    StringBundler query = null;
989    
990                    if (orderByComparator != null) {
991                            query = new StringBundler(3 +
992                                            (orderByComparator.getOrderByFields().length * 3));
993                    }
994                    else {
995                            query = new StringBundler(3);
996                    }
997    
998                    if (getDB().isSupportsInlineDistinct()) {
999                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
1000                    }
1001                    else {
1002                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
1003                    }
1004    
1005                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1006    
1007                    if (!getDB().isSupportsInlineDistinct()) {
1008                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
1009                    }
1010    
1011                    if (orderByComparator != null) {
1012                            if (getDB().isSupportsInlineDistinct()) {
1013                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1014                                            orderByComparator);
1015                            }
1016                            else {
1017                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1018                                            orderByComparator);
1019                            }
1020                    }
1021    
1022                    else {
1023                            if (getDB().isSupportsInlineDistinct()) {
1024                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
1025                            }
1026                            else {
1027                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
1028                            }
1029                    }
1030    
1031                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1032                                    LayoutSetBranch.class.getName(),
1033                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1034    
1035                    Session session = null;
1036    
1037                    try {
1038                            session = openSession();
1039    
1040                            SQLQuery q = session.createSQLQuery(sql);
1041    
1042                            if (getDB().isSupportsInlineDistinct()) {
1043                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
1044                            }
1045                            else {
1046                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
1047                            }
1048    
1049                            QueryPos qPos = QueryPos.getInstance(q);
1050    
1051                            qPos.add(groupId);
1052    
1053                            return (List<LayoutSetBranch>)QueryUtil.list(q, getDialect(),
1054                                    start, end);
1055                    }
1056                    catch (Exception e) {
1057                            throw processException(e);
1058                    }
1059                    finally {
1060                            closeSession(session);
1061                    }
1062            }
1063    
1064            /**
1065             * 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;.
1066             *
1067             * @param layoutSetBranchId the primary key of the current layout set branch
1068             * @param groupId the group ID
1069             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1070             * @return the previous, current, and next layout set branch
1071             * @throws com.liferay.portal.NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
1072             * @throws SystemException if a system exception occurred
1073             */
1074            public LayoutSetBranch[] filterFindByGroupId_PrevAndNext(
1075                    long layoutSetBranchId, long groupId,
1076                    OrderByComparator orderByComparator)
1077                    throws NoSuchLayoutSetBranchException, SystemException {
1078                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1079                            return findByGroupId_PrevAndNext(layoutSetBranchId, groupId,
1080                                    orderByComparator);
1081                    }
1082    
1083                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
1084    
1085                    Session session = null;
1086    
1087                    try {
1088                            session = openSession();
1089    
1090                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
1091    
1092                            array[0] = filterGetByGroupId_PrevAndNext(session, layoutSetBranch,
1093                                            groupId, orderByComparator, true);
1094    
1095                            array[1] = layoutSetBranch;
1096    
1097                            array[2] = filterGetByGroupId_PrevAndNext(session, layoutSetBranch,
1098                                            groupId, orderByComparator, false);
1099    
1100                            return array;
1101                    }
1102                    catch (Exception e) {
1103                            throw processException(e);
1104                    }
1105                    finally {
1106                            closeSession(session);
1107                    }
1108            }
1109    
1110            protected LayoutSetBranch filterGetByGroupId_PrevAndNext(Session session,
1111                    LayoutSetBranch layoutSetBranch, long groupId,
1112                    OrderByComparator orderByComparator, boolean previous) {
1113                    StringBundler query = null;
1114    
1115                    if (orderByComparator != null) {
1116                            query = new StringBundler(6 +
1117                                            (orderByComparator.getOrderByFields().length * 6));
1118                    }
1119                    else {
1120                            query = new StringBundler(3);
1121                    }
1122    
1123                    if (getDB().isSupportsInlineDistinct()) {
1124                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
1125                    }
1126                    else {
1127                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
1128                    }
1129    
1130                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1131    
1132                    if (!getDB().isSupportsInlineDistinct()) {
1133                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
1134                    }
1135    
1136                    if (orderByComparator != null) {
1137                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1138    
1139                            if (orderByConditionFields.length > 0) {
1140                                    query.append(WHERE_AND);
1141                            }
1142    
1143                            for (int i = 0; i < orderByConditionFields.length; i++) {
1144                                    if (getDB().isSupportsInlineDistinct()) {
1145                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1146                                    }
1147                                    else {
1148                                            query.append(_ORDER_BY_ENTITY_TABLE);
1149                                    }
1150    
1151                                    query.append(orderByConditionFields[i]);
1152    
1153                                    if ((i + 1) < orderByConditionFields.length) {
1154                                            if (orderByComparator.isAscending() ^ previous) {
1155                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1156                                            }
1157                                            else {
1158                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1159                                            }
1160                                    }
1161                                    else {
1162                                            if (orderByComparator.isAscending() ^ previous) {
1163                                                    query.append(WHERE_GREATER_THAN);
1164                                            }
1165                                            else {
1166                                                    query.append(WHERE_LESSER_THAN);
1167                                            }
1168                                    }
1169                            }
1170    
1171                            query.append(ORDER_BY_CLAUSE);
1172    
1173                            String[] orderByFields = orderByComparator.getOrderByFields();
1174    
1175                            for (int i = 0; i < orderByFields.length; i++) {
1176                                    if (getDB().isSupportsInlineDistinct()) {
1177                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1178                                    }
1179                                    else {
1180                                            query.append(_ORDER_BY_ENTITY_TABLE);
1181                                    }
1182    
1183                                    query.append(orderByFields[i]);
1184    
1185                                    if ((i + 1) < orderByFields.length) {
1186                                            if (orderByComparator.isAscending() ^ previous) {
1187                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1188                                            }
1189                                            else {
1190                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1191                                            }
1192                                    }
1193                                    else {
1194                                            if (orderByComparator.isAscending() ^ previous) {
1195                                                    query.append(ORDER_BY_ASC);
1196                                            }
1197                                            else {
1198                                                    query.append(ORDER_BY_DESC);
1199                                            }
1200                                    }
1201                            }
1202                    }
1203    
1204                    else {
1205                            if (getDB().isSupportsInlineDistinct()) {
1206                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
1207                            }
1208                            else {
1209                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
1210                            }
1211                    }
1212    
1213                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1214                                    LayoutSetBranch.class.getName(),
1215                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1216    
1217                    SQLQuery q = session.createSQLQuery(sql);
1218    
1219                    q.setFirstResult(0);
1220                    q.setMaxResults(2);
1221    
1222                    if (getDB().isSupportsInlineDistinct()) {
1223                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
1224                    }
1225                    else {
1226                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
1227                    }
1228    
1229                    QueryPos qPos = QueryPos.getInstance(q);
1230    
1231                    qPos.add(groupId);
1232    
1233                    if (orderByComparator != null) {
1234                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
1235    
1236                            for (Object value : values) {
1237                                    qPos.add(value);
1238                            }
1239                    }
1240    
1241                    List<LayoutSetBranch> list = q.list();
1242    
1243                    if (list.size() == 2) {
1244                            return list.get(1);
1245                    }
1246                    else {
1247                            return null;
1248                    }
1249            }
1250    
1251            /**
1252             * Returns all the layout set branchs where groupId = &#63; and privateLayout = &#63;.
1253             *
1254             * @param groupId the group ID
1255             * @param privateLayout the private layout
1256             * @return the matching layout set branchs
1257             * @throws SystemException if a system exception occurred
1258             */
1259            public List<LayoutSetBranch> findByG_P(long groupId, boolean privateLayout)
1260                    throws SystemException {
1261                    return findByG_P(groupId, privateLayout, QueryUtil.ALL_POS,
1262                            QueryUtil.ALL_POS, null);
1263            }
1264    
1265            /**
1266             * Returns a range of all the layout set branchs where groupId = &#63; and privateLayout = &#63;.
1267             *
1268             * <p>
1269             * 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.
1270             * </p>
1271             *
1272             * @param groupId the group ID
1273             * @param privateLayout the private layout
1274             * @param start the lower bound of the range of layout set branchs
1275             * @param end the upper bound of the range of layout set branchs (not inclusive)
1276             * @return the range of matching layout set branchs
1277             * @throws SystemException if a system exception occurred
1278             */
1279            public List<LayoutSetBranch> findByG_P(long groupId, boolean privateLayout,
1280                    int start, int end) throws SystemException {
1281                    return findByG_P(groupId, privateLayout, start, end, null);
1282            }
1283    
1284            /**
1285             * Returns an ordered range of all the layout set branchs where groupId = &#63; and privateLayout = &#63;.
1286             *
1287             * <p>
1288             * 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.
1289             * </p>
1290             *
1291             * @param groupId the group ID
1292             * @param privateLayout the private layout
1293             * @param start the lower bound of the range of layout set branchs
1294             * @param end the upper bound of the range of layout set branchs (not inclusive)
1295             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1296             * @return the ordered range of matching layout set branchs
1297             * @throws SystemException if a system exception occurred
1298             */
1299            public List<LayoutSetBranch> findByG_P(long groupId, boolean privateLayout,
1300                    int start, int end, OrderByComparator orderByComparator)
1301                    throws SystemException {
1302                    FinderPath finderPath = null;
1303                    Object[] finderArgs = null;
1304    
1305                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1306                                    (orderByComparator == null)) {
1307                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
1308                            finderArgs = new Object[] { groupId, privateLayout };
1309                    }
1310                    else {
1311                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
1312                            finderArgs = new Object[] {
1313                                            groupId, privateLayout,
1314                                            
1315                                            start, end, orderByComparator
1316                                    };
1317                    }
1318    
1319                    List<LayoutSetBranch> list = (List<LayoutSetBranch>)FinderCacheUtil.getResult(finderPath,
1320                                    finderArgs, this);
1321    
1322                    if (list == null) {
1323                            StringBundler query = null;
1324    
1325                            if (orderByComparator != null) {
1326                                    query = new StringBundler(4 +
1327                                                    (orderByComparator.getOrderByFields().length * 3));
1328                            }
1329                            else {
1330                                    query = new StringBundler(4);
1331                            }
1332    
1333                            query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
1334    
1335                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1336    
1337                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1338    
1339                            if (orderByComparator != null) {
1340                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1341                                            orderByComparator);
1342                            }
1343    
1344                            else {
1345                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
1346                            }
1347    
1348                            String sql = query.toString();
1349    
1350                            Session session = null;
1351    
1352                            try {
1353                                    session = openSession();
1354    
1355                                    Query q = session.createQuery(sql);
1356    
1357                                    QueryPos qPos = QueryPos.getInstance(q);
1358    
1359                                    qPos.add(groupId);
1360    
1361                                    qPos.add(privateLayout);
1362    
1363                                    list = (List<LayoutSetBranch>)QueryUtil.list(q, getDialect(),
1364                                                    start, end);
1365                            }
1366                            catch (Exception e) {
1367                                    throw processException(e);
1368                            }
1369                            finally {
1370                                    if (list == null) {
1371                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1372                                    }
1373                                    else {
1374                                            cacheResult(list);
1375    
1376                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1377                                    }
1378    
1379                                    closeSession(session);
1380                            }
1381                    }
1382    
1383                    return list;
1384            }
1385    
1386            /**
1387             * Returns the first layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63;.
1388             *
1389             * <p>
1390             * 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.
1391             * </p>
1392             *
1393             * @param groupId the group ID
1394             * @param privateLayout the private layout
1395             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1396             * @return the first matching layout set branch
1397             * @throws com.liferay.portal.NoSuchLayoutSetBranchException if a matching layout set branch could not be found
1398             * @throws SystemException if a system exception occurred
1399             */
1400            public LayoutSetBranch findByG_P_First(long groupId, boolean privateLayout,
1401                    OrderByComparator orderByComparator)
1402                    throws NoSuchLayoutSetBranchException, SystemException {
1403                    List<LayoutSetBranch> list = findByG_P(groupId, privateLayout, 0, 1,
1404                                    orderByComparator);
1405    
1406                    if (list.isEmpty()) {
1407                            StringBundler msg = new StringBundler(6);
1408    
1409                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1410    
1411                            msg.append("groupId=");
1412                            msg.append(groupId);
1413    
1414                            msg.append(", privateLayout=");
1415                            msg.append(privateLayout);
1416    
1417                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1418    
1419                            throw new NoSuchLayoutSetBranchException(msg.toString());
1420                    }
1421                    else {
1422                            return list.get(0);
1423                    }
1424            }
1425    
1426            /**
1427             * Returns the last layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63;.
1428             *
1429             * <p>
1430             * 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.
1431             * </p>
1432             *
1433             * @param groupId the group ID
1434             * @param privateLayout the private layout
1435             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1436             * @return the last matching layout set branch
1437             * @throws com.liferay.portal.NoSuchLayoutSetBranchException if a matching layout set branch could not be found
1438             * @throws SystemException if a system exception occurred
1439             */
1440            public LayoutSetBranch findByG_P_Last(long groupId, boolean privateLayout,
1441                    OrderByComparator orderByComparator)
1442                    throws NoSuchLayoutSetBranchException, SystemException {
1443                    int count = countByG_P(groupId, privateLayout);
1444    
1445                    List<LayoutSetBranch> list = findByG_P(groupId, privateLayout,
1446                                    count - 1, count, orderByComparator);
1447    
1448                    if (list.isEmpty()) {
1449                            StringBundler msg = new StringBundler(6);
1450    
1451                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1452    
1453                            msg.append("groupId=");
1454                            msg.append(groupId);
1455    
1456                            msg.append(", privateLayout=");
1457                            msg.append(privateLayout);
1458    
1459                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1460    
1461                            throw new NoSuchLayoutSetBranchException(msg.toString());
1462                    }
1463                    else {
1464                            return list.get(0);
1465                    }
1466            }
1467    
1468            /**
1469             * Returns the layout set branchs before and after the current layout set branch in the ordered set where groupId = &#63; and privateLayout = &#63;.
1470             *
1471             * <p>
1472             * 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.
1473             * </p>
1474             *
1475             * @param layoutSetBranchId the primary key of the current layout set branch
1476             * @param groupId the group ID
1477             * @param privateLayout the private layout
1478             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1479             * @return the previous, current, and next layout set branch
1480             * @throws com.liferay.portal.NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
1481             * @throws SystemException if a system exception occurred
1482             */
1483            public LayoutSetBranch[] findByG_P_PrevAndNext(long layoutSetBranchId,
1484                    long groupId, boolean privateLayout, OrderByComparator orderByComparator)
1485                    throws NoSuchLayoutSetBranchException, SystemException {
1486                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
1487    
1488                    Session session = null;
1489    
1490                    try {
1491                            session = openSession();
1492    
1493                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
1494    
1495                            array[0] = getByG_P_PrevAndNext(session, layoutSetBranch, groupId,
1496                                            privateLayout, orderByComparator, true);
1497    
1498                            array[1] = layoutSetBranch;
1499    
1500                            array[2] = getByG_P_PrevAndNext(session, layoutSetBranch, groupId,
1501                                            privateLayout, orderByComparator, false);
1502    
1503                            return array;
1504                    }
1505                    catch (Exception e) {
1506                            throw processException(e);
1507                    }
1508                    finally {
1509                            closeSession(session);
1510                    }
1511            }
1512    
1513            protected LayoutSetBranch getByG_P_PrevAndNext(Session session,
1514                    LayoutSetBranch layoutSetBranch, long groupId, boolean privateLayout,
1515                    OrderByComparator orderByComparator, boolean previous) {
1516                    StringBundler query = null;
1517    
1518                    if (orderByComparator != null) {
1519                            query = new StringBundler(6 +
1520                                            (orderByComparator.getOrderByFields().length * 6));
1521                    }
1522                    else {
1523                            query = new StringBundler(3);
1524                    }
1525    
1526                    query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
1527    
1528                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1529    
1530                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1531    
1532                    if (orderByComparator != null) {
1533                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1534    
1535                            if (orderByConditionFields.length > 0) {
1536                                    query.append(WHERE_AND);
1537                            }
1538    
1539                            for (int i = 0; i < orderByConditionFields.length; i++) {
1540                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1541                                    query.append(orderByConditionFields[i]);
1542    
1543                                    if ((i + 1) < orderByConditionFields.length) {
1544                                            if (orderByComparator.isAscending() ^ previous) {
1545                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1546                                            }
1547                                            else {
1548                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1549                                            }
1550                                    }
1551                                    else {
1552                                            if (orderByComparator.isAscending() ^ previous) {
1553                                                    query.append(WHERE_GREATER_THAN);
1554                                            }
1555                                            else {
1556                                                    query.append(WHERE_LESSER_THAN);
1557                                            }
1558                                    }
1559                            }
1560    
1561                            query.append(ORDER_BY_CLAUSE);
1562    
1563                            String[] orderByFields = orderByComparator.getOrderByFields();
1564    
1565                            for (int i = 0; i < orderByFields.length; i++) {
1566                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1567                                    query.append(orderByFields[i]);
1568    
1569                                    if ((i + 1) < orderByFields.length) {
1570                                            if (orderByComparator.isAscending() ^ previous) {
1571                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1572                                            }
1573                                            else {
1574                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1575                                            }
1576                                    }
1577                                    else {
1578                                            if (orderByComparator.isAscending() ^ previous) {
1579                                                    query.append(ORDER_BY_ASC);
1580                                            }
1581                                            else {
1582                                                    query.append(ORDER_BY_DESC);
1583                                            }
1584                                    }
1585                            }
1586                    }
1587    
1588                    else {
1589                            query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
1590                    }
1591    
1592                    String sql = query.toString();
1593    
1594                    Query q = session.createQuery(sql);
1595    
1596                    q.setFirstResult(0);
1597                    q.setMaxResults(2);
1598    
1599                    QueryPos qPos = QueryPos.getInstance(q);
1600    
1601                    qPos.add(groupId);
1602    
1603                    qPos.add(privateLayout);
1604    
1605                    if (orderByComparator != null) {
1606                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
1607    
1608                            for (Object value : values) {
1609                                    qPos.add(value);
1610                            }
1611                    }
1612    
1613                    List<LayoutSetBranch> list = q.list();
1614    
1615                    if (list.size() == 2) {
1616                            return list.get(1);
1617                    }
1618                    else {
1619                            return null;
1620                    }
1621            }
1622    
1623            /**
1624             * Returns all the layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
1625             *
1626             * @param groupId the group ID
1627             * @param privateLayout the private layout
1628             * @return the matching layout set branchs that the user has permission to view
1629             * @throws SystemException if a system exception occurred
1630             */
1631            public List<LayoutSetBranch> filterFindByG_P(long groupId,
1632                    boolean privateLayout) throws SystemException {
1633                    return filterFindByG_P(groupId, privateLayout, QueryUtil.ALL_POS,
1634                            QueryUtil.ALL_POS, null);
1635            }
1636    
1637            /**
1638             * Returns a range of all the layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
1639             *
1640             * <p>
1641             * 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.
1642             * </p>
1643             *
1644             * @param groupId the group ID
1645             * @param privateLayout the private layout
1646             * @param start the lower bound of the range of layout set branchs
1647             * @param end the upper bound of the range of layout set branchs (not inclusive)
1648             * @return the range of matching layout set branchs that the user has permission to view
1649             * @throws SystemException if a system exception occurred
1650             */
1651            public List<LayoutSetBranch> filterFindByG_P(long groupId,
1652                    boolean privateLayout, int start, int end) throws SystemException {
1653                    return filterFindByG_P(groupId, privateLayout, start, end, null);
1654            }
1655    
1656            /**
1657             * Returns an ordered range of all the layout set branchs that the user has permissions to view where groupId = &#63; and privateLayout = &#63;.
1658             *
1659             * <p>
1660             * 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.
1661             * </p>
1662             *
1663             * @param groupId the group ID
1664             * @param privateLayout the private layout
1665             * @param start the lower bound of the range of layout set branchs
1666             * @param end the upper bound of the range of layout set branchs (not inclusive)
1667             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1668             * @return the ordered range of matching layout set branchs that the user has permission to view
1669             * @throws SystemException if a system exception occurred
1670             */
1671            public List<LayoutSetBranch> filterFindByG_P(long groupId,
1672                    boolean privateLayout, int start, int end,
1673                    OrderByComparator orderByComparator) throws SystemException {
1674                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1675                            return findByG_P(groupId, privateLayout, start, end,
1676                                    orderByComparator);
1677                    }
1678    
1679                    StringBundler query = null;
1680    
1681                    if (orderByComparator != null) {
1682                            query = new StringBundler(4 +
1683                                            (orderByComparator.getOrderByFields().length * 3));
1684                    }
1685                    else {
1686                            query = new StringBundler(4);
1687                    }
1688    
1689                    if (getDB().isSupportsInlineDistinct()) {
1690                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
1691                    }
1692                    else {
1693                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
1694                    }
1695    
1696                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1697    
1698                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1699    
1700                    if (!getDB().isSupportsInlineDistinct()) {
1701                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
1702                    }
1703    
1704                    if (orderByComparator != null) {
1705                            if (getDB().isSupportsInlineDistinct()) {
1706                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1707                                            orderByComparator);
1708                            }
1709                            else {
1710                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1711                                            orderByComparator);
1712                            }
1713                    }
1714    
1715                    else {
1716                            if (getDB().isSupportsInlineDistinct()) {
1717                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
1718                            }
1719                            else {
1720                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
1721                            }
1722                    }
1723    
1724                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1725                                    LayoutSetBranch.class.getName(),
1726                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1727    
1728                    Session session = null;
1729    
1730                    try {
1731                            session = openSession();
1732    
1733                            SQLQuery q = session.createSQLQuery(sql);
1734    
1735                            if (getDB().isSupportsInlineDistinct()) {
1736                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
1737                            }
1738                            else {
1739                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
1740                            }
1741    
1742                            QueryPos qPos = QueryPos.getInstance(q);
1743    
1744                            qPos.add(groupId);
1745    
1746                            qPos.add(privateLayout);
1747    
1748                            return (List<LayoutSetBranch>)QueryUtil.list(q, getDialect(),
1749                                    start, end);
1750                    }
1751                    catch (Exception e) {
1752                            throw processException(e);
1753                    }
1754                    finally {
1755                            closeSession(session);
1756                    }
1757            }
1758    
1759            /**
1760             * 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;.
1761             *
1762             * @param layoutSetBranchId the primary key of the current layout set branch
1763             * @param groupId the group ID
1764             * @param privateLayout the private layout
1765             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1766             * @return the previous, current, and next layout set branch
1767             * @throws com.liferay.portal.NoSuchLayoutSetBranchException if a layout set branch with the primary key could not be found
1768             * @throws SystemException if a system exception occurred
1769             */
1770            public LayoutSetBranch[] filterFindByG_P_PrevAndNext(
1771                    long layoutSetBranchId, long groupId, boolean privateLayout,
1772                    OrderByComparator orderByComparator)
1773                    throws NoSuchLayoutSetBranchException, SystemException {
1774                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1775                            return findByG_P_PrevAndNext(layoutSetBranchId, groupId,
1776                                    privateLayout, orderByComparator);
1777                    }
1778    
1779                    LayoutSetBranch layoutSetBranch = findByPrimaryKey(layoutSetBranchId);
1780    
1781                    Session session = null;
1782    
1783                    try {
1784                            session = openSession();
1785    
1786                            LayoutSetBranch[] array = new LayoutSetBranchImpl[3];
1787    
1788                            array[0] = filterGetByG_P_PrevAndNext(session, layoutSetBranch,
1789                                            groupId, privateLayout, orderByComparator, true);
1790    
1791                            array[1] = layoutSetBranch;
1792    
1793                            array[2] = filterGetByG_P_PrevAndNext(session, layoutSetBranch,
1794                                            groupId, privateLayout, orderByComparator, false);
1795    
1796                            return array;
1797                    }
1798                    catch (Exception e) {
1799                            throw processException(e);
1800                    }
1801                    finally {
1802                            closeSession(session);
1803                    }
1804            }
1805    
1806            protected LayoutSetBranch filterGetByG_P_PrevAndNext(Session session,
1807                    LayoutSetBranch layoutSetBranch, long groupId, boolean privateLayout,
1808                    OrderByComparator orderByComparator, boolean previous) {
1809                    StringBundler query = null;
1810    
1811                    if (orderByComparator != null) {
1812                            query = new StringBundler(6 +
1813                                            (orderByComparator.getOrderByFields().length * 6));
1814                    }
1815                    else {
1816                            query = new StringBundler(3);
1817                    }
1818    
1819                    if (getDB().isSupportsInlineDistinct()) {
1820                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
1821                    }
1822                    else {
1823                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1);
1824                    }
1825    
1826                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1827    
1828                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1829    
1830                    if (!getDB().isSupportsInlineDistinct()) {
1831                            query.append(_FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2);
1832                    }
1833    
1834                    if (orderByComparator != null) {
1835                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1836    
1837                            if (orderByConditionFields.length > 0) {
1838                                    query.append(WHERE_AND);
1839                            }
1840    
1841                            for (int i = 0; i < orderByConditionFields.length; i++) {
1842                                    if (getDB().isSupportsInlineDistinct()) {
1843                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1844                                    }
1845                                    else {
1846                                            query.append(_ORDER_BY_ENTITY_TABLE);
1847                                    }
1848    
1849                                    query.append(orderByConditionFields[i]);
1850    
1851                                    if ((i + 1) < orderByConditionFields.length) {
1852                                            if (orderByComparator.isAscending() ^ previous) {
1853                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1854                                            }
1855                                            else {
1856                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1857                                            }
1858                                    }
1859                                    else {
1860                                            if (orderByComparator.isAscending() ^ previous) {
1861                                                    query.append(WHERE_GREATER_THAN);
1862                                            }
1863                                            else {
1864                                                    query.append(WHERE_LESSER_THAN);
1865                                            }
1866                                    }
1867                            }
1868    
1869                            query.append(ORDER_BY_CLAUSE);
1870    
1871                            String[] orderByFields = orderByComparator.getOrderByFields();
1872    
1873                            for (int i = 0; i < orderByFields.length; i++) {
1874                                    if (getDB().isSupportsInlineDistinct()) {
1875                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1876                                    }
1877                                    else {
1878                                            query.append(_ORDER_BY_ENTITY_TABLE);
1879                                    }
1880    
1881                                    query.append(orderByFields[i]);
1882    
1883                                    if ((i + 1) < orderByFields.length) {
1884                                            if (orderByComparator.isAscending() ^ previous) {
1885                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1886                                            }
1887                                            else {
1888                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1889                                            }
1890                                    }
1891                                    else {
1892                                            if (orderByComparator.isAscending() ^ previous) {
1893                                                    query.append(ORDER_BY_ASC);
1894                                            }
1895                                            else {
1896                                                    query.append(ORDER_BY_DESC);
1897                                            }
1898                                    }
1899                            }
1900                    }
1901    
1902                    else {
1903                            if (getDB().isSupportsInlineDistinct()) {
1904                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
1905                            }
1906                            else {
1907                                    query.append(LayoutSetBranchModelImpl.ORDER_BY_SQL);
1908                            }
1909                    }
1910    
1911                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1912                                    LayoutSetBranch.class.getName(),
1913                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1914    
1915                    SQLQuery q = session.createSQLQuery(sql);
1916    
1917                    q.setFirstResult(0);
1918                    q.setMaxResults(2);
1919    
1920                    if (getDB().isSupportsInlineDistinct()) {
1921                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetBranchImpl.class);
1922                    }
1923                    else {
1924                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetBranchImpl.class);
1925                    }
1926    
1927                    QueryPos qPos = QueryPos.getInstance(q);
1928    
1929                    qPos.add(groupId);
1930    
1931                    qPos.add(privateLayout);
1932    
1933                    if (orderByComparator != null) {
1934                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetBranch);
1935    
1936                            for (Object value : values) {
1937                                    qPos.add(value);
1938                            }
1939                    }
1940    
1941                    List<LayoutSetBranch> list = q.list();
1942    
1943                    if (list.size() == 2) {
1944                            return list.get(1);
1945                    }
1946                    else {
1947                            return null;
1948                    }
1949            }
1950    
1951            /**
1952             * 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.
1953             *
1954             * @param groupId the group ID
1955             * @param privateLayout the private layout
1956             * @param name the name
1957             * @return the matching layout set branch
1958             * @throws com.liferay.portal.NoSuchLayoutSetBranchException if a matching layout set branch could not be found
1959             * @throws SystemException if a system exception occurred
1960             */
1961            public LayoutSetBranch findByG_P_N(long groupId, boolean privateLayout,
1962                    String name) throws NoSuchLayoutSetBranchException, SystemException {
1963                    LayoutSetBranch layoutSetBranch = fetchByG_P_N(groupId, privateLayout,
1964                                    name);
1965    
1966                    if (layoutSetBranch == null) {
1967                            StringBundler msg = new StringBundler(8);
1968    
1969                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1970    
1971                            msg.append("groupId=");
1972                            msg.append(groupId);
1973    
1974                            msg.append(", privateLayout=");
1975                            msg.append(privateLayout);
1976    
1977                            msg.append(", name=");
1978                            msg.append(name);
1979    
1980                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1981    
1982                            if (_log.isWarnEnabled()) {
1983                                    _log.warn(msg.toString());
1984                            }
1985    
1986                            throw new NoSuchLayoutSetBranchException(msg.toString());
1987                    }
1988    
1989                    return layoutSetBranch;
1990            }
1991    
1992            /**
1993             * 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.
1994             *
1995             * @param groupId the group ID
1996             * @param privateLayout the private layout
1997             * @param name the name
1998             * @return the matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
1999             * @throws SystemException if a system exception occurred
2000             */
2001            public LayoutSetBranch fetchByG_P_N(long groupId, boolean privateLayout,
2002                    String name) throws SystemException {
2003                    return fetchByG_P_N(groupId, privateLayout, name, true);
2004            }
2005    
2006            /**
2007             * 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.
2008             *
2009             * @param groupId the group ID
2010             * @param privateLayout the private layout
2011             * @param name the name
2012             * @param retrieveFromCache whether to use the finder cache
2013             * @return the matching layout set branch, or <code>null</code> if a matching layout set branch could not be found
2014             * @throws SystemException if a system exception occurred
2015             */
2016            public LayoutSetBranch fetchByG_P_N(long groupId, boolean privateLayout,
2017                    String name, boolean retrieveFromCache) throws SystemException {
2018                    Object[] finderArgs = new Object[] { groupId, privateLayout, name };
2019    
2020                    Object result = null;
2021    
2022                    if (retrieveFromCache) {
2023                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_N,
2024                                            finderArgs, this);
2025                    }
2026    
2027                    if (result == null) {
2028                            StringBundler query = new StringBundler(5);
2029    
2030                            query.append(_SQL_SELECT_LAYOUTSETBRANCH_WHERE);
2031    
2032                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
2033    
2034                            query.append(_FINDER_COLUMN_G_P_N_PRIVATELAYOUT_2);
2035    
2036                            if (name == null) {
2037                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
2038                            }
2039                            else {
2040                                    if (name.equals(StringPool.BLANK)) {
2041                                            query.append(_FINDER_COLUMN_G_P_N_NAME_3);
2042                                    }
2043                                    else {
2044                                            query.append(_FINDER_COLUMN_G_P_N_NAME_2);
2045                                    }
2046                            }
2047    
2048                            query.append(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
2049    
2050                            String sql = query.toString();
2051    
2052                            Session session = null;
2053    
2054                            try {
2055                                    session = openSession();
2056    
2057                                    Query q = session.createQuery(sql);
2058    
2059                                    QueryPos qPos = QueryPos.getInstance(q);
2060    
2061                                    qPos.add(groupId);
2062    
2063                                    qPos.add(privateLayout);
2064    
2065                                    if (name != null) {
2066                                            qPos.add(name);
2067                                    }
2068    
2069                                    List<LayoutSetBranch> list = q.list();
2070    
2071                                    result = list;
2072    
2073                                    LayoutSetBranch layoutSetBranch = null;
2074    
2075                                    if (list.isEmpty()) {
2076                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
2077                                                    finderArgs, list);
2078                                    }
2079                                    else {
2080                                            layoutSetBranch = list.get(0);
2081    
2082                                            cacheResult(layoutSetBranch);
2083    
2084                                            if ((layoutSetBranch.getGroupId() != groupId) ||
2085                                                            (layoutSetBranch.getPrivateLayout() != privateLayout) ||
2086                                                            (layoutSetBranch.getName() == null) ||
2087                                                            !layoutSetBranch.getName().equals(name)) {
2088                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N,
2089                                                            finderArgs, layoutSetBranch);
2090                                            }
2091                                    }
2092    
2093                                    return layoutSetBranch;
2094                            }
2095                            catch (Exception e) {
2096                                    throw processException(e);
2097                            }
2098                            finally {
2099                                    if (result == null) {
2100                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N,
2101                                                    finderArgs);
2102                                    }
2103    
2104                                    closeSession(session);
2105                            }
2106                    }
2107                    else {
2108                            if (result instanceof List<?>) {
2109                                    return null;
2110                            }
2111                            else {
2112                                    return (LayoutSetBranch)result;
2113                            }
2114                    }
2115            }
2116    
2117            /**
2118             * Returns all the layout set branchs.
2119             *
2120             * @return the layout set branchs
2121             * @throws SystemException if a system exception occurred
2122             */
2123            public List<LayoutSetBranch> findAll() throws SystemException {
2124                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2125            }
2126    
2127            /**
2128             * Returns a range of all the layout set branchs.
2129             *
2130             * <p>
2131             * 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.
2132             * </p>
2133             *
2134             * @param start the lower bound of the range of layout set branchs
2135             * @param end the upper bound of the range of layout set branchs (not inclusive)
2136             * @return the range of layout set branchs
2137             * @throws SystemException if a system exception occurred
2138             */
2139            public List<LayoutSetBranch> findAll(int start, int end)
2140                    throws SystemException {
2141                    return findAll(start, end, null);
2142            }
2143    
2144            /**
2145             * Returns an ordered range of all the layout set branchs.
2146             *
2147             * <p>
2148             * 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.
2149             * </p>
2150             *
2151             * @param start the lower bound of the range of layout set branchs
2152             * @param end the upper bound of the range of layout set branchs (not inclusive)
2153             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2154             * @return the ordered range of layout set branchs
2155             * @throws SystemException if a system exception occurred
2156             */
2157            public List<LayoutSetBranch> findAll(int start, int end,
2158                    OrderByComparator orderByComparator) throws SystemException {
2159                    FinderPath finderPath = null;
2160                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
2161    
2162                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2163                                    (orderByComparator == null)) {
2164                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2165                            finderArgs = FINDER_ARGS_EMPTY;
2166                    }
2167                    else {
2168                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2169                            finderArgs = new Object[] { start, end, orderByComparator };
2170                    }
2171    
2172                    List<LayoutSetBranch> list = (List<LayoutSetBranch>)FinderCacheUtil.getResult(finderPath,
2173                                    finderArgs, this);
2174    
2175                    if (list == null) {
2176                            StringBundler query = null;
2177                            String sql = null;
2178    
2179                            if (orderByComparator != null) {
2180                                    query = new StringBundler(2 +
2181                                                    (orderByComparator.getOrderByFields().length * 3));
2182    
2183                                    query.append(_SQL_SELECT_LAYOUTSETBRANCH);
2184    
2185                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2186                                            orderByComparator);
2187    
2188                                    sql = query.toString();
2189                            }
2190                            else {
2191                                    sql = _SQL_SELECT_LAYOUTSETBRANCH.concat(LayoutSetBranchModelImpl.ORDER_BY_JPQL);
2192                            }
2193    
2194                            Session session = null;
2195    
2196                            try {
2197                                    session = openSession();
2198    
2199                                    Query q = session.createQuery(sql);
2200    
2201                                    if (orderByComparator == null) {
2202                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
2203                                                            getDialect(), start, end, false);
2204    
2205                                            Collections.sort(list);
2206                                    }
2207                                    else {
2208                                            list = (List<LayoutSetBranch>)QueryUtil.list(q,
2209                                                            getDialect(), start, end);
2210                                    }
2211                            }
2212                            catch (Exception e) {
2213                                    throw processException(e);
2214                            }
2215                            finally {
2216                                    if (list == null) {
2217                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2218                                    }
2219                                    else {
2220                                            cacheResult(list);
2221    
2222                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2223                                    }
2224    
2225                                    closeSession(session);
2226                            }
2227                    }
2228    
2229                    return list;
2230            }
2231    
2232            /**
2233             * Removes all the layout set branchs where groupId = &#63; from the database.
2234             *
2235             * @param groupId the group ID
2236             * @throws SystemException if a system exception occurred
2237             */
2238            public void removeByGroupId(long groupId) throws SystemException {
2239                    for (LayoutSetBranch layoutSetBranch : findByGroupId(groupId)) {
2240                            layoutSetBranchPersistence.remove(layoutSetBranch);
2241                    }
2242            }
2243    
2244            /**
2245             * Removes all the layout set branchs where groupId = &#63; and privateLayout = &#63; from the database.
2246             *
2247             * @param groupId the group ID
2248             * @param privateLayout the private layout
2249             * @throws SystemException if a system exception occurred
2250             */
2251            public void removeByG_P(long groupId, boolean privateLayout)
2252                    throws SystemException {
2253                    for (LayoutSetBranch layoutSetBranch : findByG_P(groupId, privateLayout)) {
2254                            layoutSetBranchPersistence.remove(layoutSetBranch);
2255                    }
2256            }
2257    
2258            /**
2259             * Removes the layout set branch where groupId = &#63; and privateLayout = &#63; and name = &#63; from the database.
2260             *
2261             * @param groupId the group ID
2262             * @param privateLayout the private layout
2263             * @param name the name
2264             * @throws SystemException if a system exception occurred
2265             */
2266            public void removeByG_P_N(long groupId, boolean privateLayout, String name)
2267                    throws NoSuchLayoutSetBranchException, SystemException {
2268                    LayoutSetBranch layoutSetBranch = findByG_P_N(groupId, privateLayout,
2269                                    name);
2270    
2271                    layoutSetBranchPersistence.remove(layoutSetBranch);
2272            }
2273    
2274            /**
2275             * Removes all the layout set branchs from the database.
2276             *
2277             * @throws SystemException if a system exception occurred
2278             */
2279            public void removeAll() throws SystemException {
2280                    for (LayoutSetBranch layoutSetBranch : findAll()) {
2281                            layoutSetBranchPersistence.remove(layoutSetBranch);
2282                    }
2283            }
2284    
2285            /**
2286             * Returns the number of layout set branchs where groupId = &#63;.
2287             *
2288             * @param groupId the group ID
2289             * @return the number of matching layout set branchs
2290             * @throws SystemException if a system exception occurred
2291             */
2292            public int countByGroupId(long groupId) throws SystemException {
2293                    Object[] finderArgs = new Object[] { groupId };
2294    
2295                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2296                                    finderArgs, this);
2297    
2298                    if (count == null) {
2299                            StringBundler query = new StringBundler(2);
2300    
2301                            query.append(_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
2302    
2303                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2304    
2305                            String sql = query.toString();
2306    
2307                            Session session = null;
2308    
2309                            try {
2310                                    session = openSession();
2311    
2312                                    Query q = session.createQuery(sql);
2313    
2314                                    QueryPos qPos = QueryPos.getInstance(q);
2315    
2316                                    qPos.add(groupId);
2317    
2318                                    count = (Long)q.uniqueResult();
2319                            }
2320                            catch (Exception e) {
2321                                    throw processException(e);
2322                            }
2323                            finally {
2324                                    if (count == null) {
2325                                            count = Long.valueOf(0);
2326                                    }
2327    
2328                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2329                                            finderArgs, count);
2330    
2331                                    closeSession(session);
2332                            }
2333                    }
2334    
2335                    return count.intValue();
2336            }
2337    
2338            /**
2339             * Returns the number of layout set branchs that the user has permission to view where groupId = &#63;.
2340             *
2341             * @param groupId the group ID
2342             * @return the number of matching layout set branchs that the user has permission to view
2343             * @throws SystemException if a system exception occurred
2344             */
2345            public int filterCountByGroupId(long groupId) throws SystemException {
2346                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2347                            return countByGroupId(groupId);
2348                    }
2349    
2350                    StringBundler query = new StringBundler(2);
2351    
2352                    query.append(_FILTER_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
2353    
2354                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2355    
2356                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2357                                    LayoutSetBranch.class.getName(),
2358                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2359    
2360                    Session session = null;
2361    
2362                    try {
2363                            session = openSession();
2364    
2365                            SQLQuery q = session.createSQLQuery(sql);
2366    
2367                            q.addScalar(COUNT_COLUMN_NAME,
2368                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2369    
2370                            QueryPos qPos = QueryPos.getInstance(q);
2371    
2372                            qPos.add(groupId);
2373    
2374                            Long count = (Long)q.uniqueResult();
2375    
2376                            return count.intValue();
2377                    }
2378                    catch (Exception e) {
2379                            throw processException(e);
2380                    }
2381                    finally {
2382                            closeSession(session);
2383                    }
2384            }
2385    
2386            /**
2387             * Returns the number of layout set branchs where groupId = &#63; and privateLayout = &#63;.
2388             *
2389             * @param groupId the group ID
2390             * @param privateLayout the private layout
2391             * @return the number of matching layout set branchs
2392             * @throws SystemException if a system exception occurred
2393             */
2394            public int countByG_P(long groupId, boolean privateLayout)
2395                    throws SystemException {
2396                    Object[] finderArgs = new Object[] { groupId, privateLayout };
2397    
2398                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
2399                                    finderArgs, this);
2400    
2401                    if (count == null) {
2402                            StringBundler query = new StringBundler(3);
2403    
2404                            query.append(_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
2405    
2406                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2407    
2408                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
2409    
2410                            String sql = query.toString();
2411    
2412                            Session session = null;
2413    
2414                            try {
2415                                    session = openSession();
2416    
2417                                    Query q = session.createQuery(sql);
2418    
2419                                    QueryPos qPos = QueryPos.getInstance(q);
2420    
2421                                    qPos.add(groupId);
2422    
2423                                    qPos.add(privateLayout);
2424    
2425                                    count = (Long)q.uniqueResult();
2426                            }
2427                            catch (Exception e) {
2428                                    throw processException(e);
2429                            }
2430                            finally {
2431                                    if (count == null) {
2432                                            count = Long.valueOf(0);
2433                                    }
2434    
2435                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
2436                                            count);
2437    
2438                                    closeSession(session);
2439                            }
2440                    }
2441    
2442                    return count.intValue();
2443            }
2444    
2445            /**
2446             * Returns the number of layout set branchs that the user has permission to view where groupId = &#63; and privateLayout = &#63;.
2447             *
2448             * @param groupId the group ID
2449             * @param privateLayout the private layout
2450             * @return the number of matching layout set branchs that the user has permission to view
2451             * @throws SystemException if a system exception occurred
2452             */
2453            public int filterCountByG_P(long groupId, boolean privateLayout)
2454                    throws SystemException {
2455                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2456                            return countByG_P(groupId, privateLayout);
2457                    }
2458    
2459                    StringBundler query = new StringBundler(3);
2460    
2461                    query.append(_FILTER_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
2462    
2463                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2464    
2465                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
2466    
2467                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2468                                    LayoutSetBranch.class.getName(),
2469                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2470    
2471                    Session session = null;
2472    
2473                    try {
2474                            session = openSession();
2475    
2476                            SQLQuery q = session.createSQLQuery(sql);
2477    
2478                            q.addScalar(COUNT_COLUMN_NAME,
2479                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2480    
2481                            QueryPos qPos = QueryPos.getInstance(q);
2482    
2483                            qPos.add(groupId);
2484    
2485                            qPos.add(privateLayout);
2486    
2487                            Long count = (Long)q.uniqueResult();
2488    
2489                            return count.intValue();
2490                    }
2491                    catch (Exception e) {
2492                            throw processException(e);
2493                    }
2494                    finally {
2495                            closeSession(session);
2496                    }
2497            }
2498    
2499            /**
2500             * Returns the number of layout set branchs where groupId = &#63; and privateLayout = &#63; and name = &#63;.
2501             *
2502             * @param groupId the group ID
2503             * @param privateLayout the private layout
2504             * @param name the name
2505             * @return the number of matching layout set branchs
2506             * @throws SystemException if a system exception occurred
2507             */
2508            public int countByG_P_N(long groupId, boolean privateLayout, String name)
2509                    throws SystemException {
2510                    Object[] finderArgs = new Object[] { groupId, privateLayout, name };
2511    
2512                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_N,
2513                                    finderArgs, this);
2514    
2515                    if (count == null) {
2516                            StringBundler query = new StringBundler(4);
2517    
2518                            query.append(_SQL_COUNT_LAYOUTSETBRANCH_WHERE);
2519    
2520                            query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
2521    
2522                            query.append(_FINDER_COLUMN_G_P_N_PRIVATELAYOUT_2);
2523    
2524                            if (name == null) {
2525                                    query.append(_FINDER_COLUMN_G_P_N_NAME_1);
2526                            }
2527                            else {
2528                                    if (name.equals(StringPool.BLANK)) {
2529                                            query.append(_FINDER_COLUMN_G_P_N_NAME_3);
2530                                    }
2531                                    else {
2532                                            query.append(_FINDER_COLUMN_G_P_N_NAME_2);
2533                                    }
2534                            }
2535    
2536                            String sql = query.toString();
2537    
2538                            Session session = null;
2539    
2540                            try {
2541                                    session = openSession();
2542    
2543                                    Query q = session.createQuery(sql);
2544    
2545                                    QueryPos qPos = QueryPos.getInstance(q);
2546    
2547                                    qPos.add(groupId);
2548    
2549                                    qPos.add(privateLayout);
2550    
2551                                    if (name != null) {
2552                                            qPos.add(name);
2553                                    }
2554    
2555                                    count = (Long)q.uniqueResult();
2556                            }
2557                            catch (Exception e) {
2558                                    throw processException(e);
2559                            }
2560                            finally {
2561                                    if (count == null) {
2562                                            count = Long.valueOf(0);
2563                                    }
2564    
2565                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_N,
2566                                            finderArgs, count);
2567    
2568                                    closeSession(session);
2569                            }
2570                    }
2571    
2572                    return count.intValue();
2573            }
2574    
2575            /**
2576             * Returns the number of layout set branchs.
2577             *
2578             * @return the number of layout set branchs
2579             * @throws SystemException if a system exception occurred
2580             */
2581            public int countAll() throws SystemException {
2582                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2583                                    FINDER_ARGS_EMPTY, this);
2584    
2585                    if (count == null) {
2586                            Session session = null;
2587    
2588                            try {
2589                                    session = openSession();
2590    
2591                                    Query q = session.createQuery(_SQL_COUNT_LAYOUTSETBRANCH);
2592    
2593                                    count = (Long)q.uniqueResult();
2594                            }
2595                            catch (Exception e) {
2596                                    throw processException(e);
2597                            }
2598                            finally {
2599                                    if (count == null) {
2600                                            count = Long.valueOf(0);
2601                                    }
2602    
2603                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2604                                            FINDER_ARGS_EMPTY, count);
2605    
2606                                    closeSession(session);
2607                            }
2608                    }
2609    
2610                    return count.intValue();
2611            }
2612    
2613            /**
2614             * Initializes the layout set branch persistence.
2615             */
2616            public void afterPropertiesSet() {
2617                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2618                                            com.liferay.portal.util.PropsUtil.get(
2619                                                    "value.object.listener.com.liferay.portal.model.LayoutSetBranch")));
2620    
2621                    if (listenerClassNames.length > 0) {
2622                            try {
2623                                    List<ModelListener<LayoutSetBranch>> listenersList = new ArrayList<ModelListener<LayoutSetBranch>>();
2624    
2625                                    for (String listenerClassName : listenerClassNames) {
2626                                            listenersList.add((ModelListener<LayoutSetBranch>)InstanceFactory.newInstance(
2627                                                            listenerClassName));
2628                                    }
2629    
2630                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2631                            }
2632                            catch (Exception e) {
2633                                    _log.error(e);
2634                            }
2635                    }
2636            }
2637    
2638            public void destroy() {
2639                    EntityCacheUtil.removeCache(LayoutSetBranchImpl.class.getName());
2640                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2641                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2642            }
2643    
2644            @BeanReference(type = AccountPersistence.class)
2645            protected AccountPersistence accountPersistence;
2646            @BeanReference(type = AddressPersistence.class)
2647            protected AddressPersistence addressPersistence;
2648            @BeanReference(type = BrowserTrackerPersistence.class)
2649            protected BrowserTrackerPersistence browserTrackerPersistence;
2650            @BeanReference(type = ClassNamePersistence.class)
2651            protected ClassNamePersistence classNamePersistence;
2652            @BeanReference(type = ClusterGroupPersistence.class)
2653            protected ClusterGroupPersistence clusterGroupPersistence;
2654            @BeanReference(type = CompanyPersistence.class)
2655            protected CompanyPersistence companyPersistence;
2656            @BeanReference(type = ContactPersistence.class)
2657            protected ContactPersistence contactPersistence;
2658            @BeanReference(type = CountryPersistence.class)
2659            protected CountryPersistence countryPersistence;
2660            @BeanReference(type = EmailAddressPersistence.class)
2661            protected EmailAddressPersistence emailAddressPersistence;
2662            @BeanReference(type = GroupPersistence.class)
2663            protected GroupPersistence groupPersistence;
2664            @BeanReference(type = ImagePersistence.class)
2665            protected ImagePersistence imagePersistence;
2666            @BeanReference(type = LayoutPersistence.class)
2667            protected LayoutPersistence layoutPersistence;
2668            @BeanReference(type = LayoutBranchPersistence.class)
2669            protected LayoutBranchPersistence layoutBranchPersistence;
2670            @BeanReference(type = LayoutPrototypePersistence.class)
2671            protected LayoutPrototypePersistence layoutPrototypePersistence;
2672            @BeanReference(type = LayoutRevisionPersistence.class)
2673            protected LayoutRevisionPersistence layoutRevisionPersistence;
2674            @BeanReference(type = LayoutSetPersistence.class)
2675            protected LayoutSetPersistence layoutSetPersistence;
2676            @BeanReference(type = LayoutSetBranchPersistence.class)
2677            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2678            @BeanReference(type = LayoutSetPrototypePersistence.class)
2679            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2680            @BeanReference(type = ListTypePersistence.class)
2681            protected ListTypePersistence listTypePersistence;
2682            @BeanReference(type = LockPersistence.class)
2683            protected LockPersistence lockPersistence;
2684            @BeanReference(type = MembershipRequestPersistence.class)
2685            protected MembershipRequestPersistence membershipRequestPersistence;
2686            @BeanReference(type = OrganizationPersistence.class)
2687            protected OrganizationPersistence organizationPersistence;
2688            @BeanReference(type = OrgGroupPermissionPersistence.class)
2689            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2690            @BeanReference(type = OrgGroupRolePersistence.class)
2691            protected OrgGroupRolePersistence orgGroupRolePersistence;
2692            @BeanReference(type = OrgLaborPersistence.class)
2693            protected OrgLaborPersistence orgLaborPersistence;
2694            @BeanReference(type = PasswordPolicyPersistence.class)
2695            protected PasswordPolicyPersistence passwordPolicyPersistence;
2696            @BeanReference(type = PasswordPolicyRelPersistence.class)
2697            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2698            @BeanReference(type = PasswordTrackerPersistence.class)
2699            protected PasswordTrackerPersistence passwordTrackerPersistence;
2700            @BeanReference(type = PermissionPersistence.class)
2701            protected PermissionPersistence permissionPersistence;
2702            @BeanReference(type = PhonePersistence.class)
2703            protected PhonePersistence phonePersistence;
2704            @BeanReference(type = PluginSettingPersistence.class)
2705            protected PluginSettingPersistence pluginSettingPersistence;
2706            @BeanReference(type = PortalPreferencesPersistence.class)
2707            protected PortalPreferencesPersistence portalPreferencesPersistence;
2708            @BeanReference(type = PortletPersistence.class)
2709            protected PortletPersistence portletPersistence;
2710            @BeanReference(type = PortletItemPersistence.class)
2711            protected PortletItemPersistence portletItemPersistence;
2712            @BeanReference(type = PortletPreferencesPersistence.class)
2713            protected PortletPreferencesPersistence portletPreferencesPersistence;
2714            @BeanReference(type = RegionPersistence.class)
2715            protected RegionPersistence regionPersistence;
2716            @BeanReference(type = ReleasePersistence.class)
2717            protected ReleasePersistence releasePersistence;
2718            @BeanReference(type = RepositoryPersistence.class)
2719            protected RepositoryPersistence repositoryPersistence;
2720            @BeanReference(type = RepositoryEntryPersistence.class)
2721            protected RepositoryEntryPersistence repositoryEntryPersistence;
2722            @BeanReference(type = ResourcePersistence.class)
2723            protected ResourcePersistence resourcePersistence;
2724            @BeanReference(type = ResourceActionPersistence.class)
2725            protected ResourceActionPersistence resourceActionPersistence;
2726            @BeanReference(type = ResourceBlockPersistence.class)
2727            protected ResourceBlockPersistence resourceBlockPersistence;
2728            @BeanReference(type = ResourceBlockPermissionPersistence.class)
2729            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2730            @BeanReference(type = ResourceCodePersistence.class)
2731            protected ResourceCodePersistence resourceCodePersistence;
2732            @BeanReference(type = ResourcePermissionPersistence.class)
2733            protected ResourcePermissionPersistence resourcePermissionPersistence;
2734            @BeanReference(type = ResourceTypePermissionPersistence.class)
2735            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2736            @BeanReference(type = RolePersistence.class)
2737            protected RolePersistence rolePersistence;
2738            @BeanReference(type = ServiceComponentPersistence.class)
2739            protected ServiceComponentPersistence serviceComponentPersistence;
2740            @BeanReference(type = ShardPersistence.class)
2741            protected ShardPersistence shardPersistence;
2742            @BeanReference(type = SubscriptionPersistence.class)
2743            protected SubscriptionPersistence subscriptionPersistence;
2744            @BeanReference(type = TeamPersistence.class)
2745            protected TeamPersistence teamPersistence;
2746            @BeanReference(type = TicketPersistence.class)
2747            protected TicketPersistence ticketPersistence;
2748            @BeanReference(type = UserPersistence.class)
2749            protected UserPersistence userPersistence;
2750            @BeanReference(type = UserGroupPersistence.class)
2751            protected UserGroupPersistence userGroupPersistence;
2752            @BeanReference(type = UserGroupGroupRolePersistence.class)
2753            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2754            @BeanReference(type = UserGroupRolePersistence.class)
2755            protected UserGroupRolePersistence userGroupRolePersistence;
2756            @BeanReference(type = UserIdMapperPersistence.class)
2757            protected UserIdMapperPersistence userIdMapperPersistence;
2758            @BeanReference(type = UserNotificationEventPersistence.class)
2759            protected UserNotificationEventPersistence userNotificationEventPersistence;
2760            @BeanReference(type = UserTrackerPersistence.class)
2761            protected UserTrackerPersistence userTrackerPersistence;
2762            @BeanReference(type = UserTrackerPathPersistence.class)
2763            protected UserTrackerPathPersistence userTrackerPathPersistence;
2764            @BeanReference(type = VirtualHostPersistence.class)
2765            protected VirtualHostPersistence virtualHostPersistence;
2766            @BeanReference(type = WebDAVPropsPersistence.class)
2767            protected WebDAVPropsPersistence webDAVPropsPersistence;
2768            @BeanReference(type = WebsitePersistence.class)
2769            protected WebsitePersistence websitePersistence;
2770            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2771            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2772            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2773            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2774            private static final String _SQL_SELECT_LAYOUTSETBRANCH = "SELECT layoutSetBranch FROM LayoutSetBranch layoutSetBranch";
2775            private static final String _SQL_SELECT_LAYOUTSETBRANCH_WHERE = "SELECT layoutSetBranch FROM LayoutSetBranch layoutSetBranch WHERE ";
2776            private static final String _SQL_COUNT_LAYOUTSETBRANCH = "SELECT COUNT(layoutSetBranch) FROM LayoutSetBranch layoutSetBranch";
2777            private static final String _SQL_COUNT_LAYOUTSETBRANCH_WHERE = "SELECT COUNT(layoutSetBranch) FROM LayoutSetBranch layoutSetBranch WHERE ";
2778            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "layoutSetBranch.groupId = ?";
2779            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "layoutSetBranch.groupId = ? AND ";
2780            private static final String _FINDER_COLUMN_G_P_PRIVATELAYOUT_2 = "layoutSetBranch.privateLayout = ?";
2781            private static final String _FINDER_COLUMN_G_P_N_GROUPID_2 = "layoutSetBranch.groupId = ? AND ";
2782            private static final String _FINDER_COLUMN_G_P_N_PRIVATELAYOUT_2 = "layoutSetBranch.privateLayout = ? AND ";
2783            private static final String _FINDER_COLUMN_G_P_N_NAME_1 = "layoutSetBranch.name IS NULL";
2784            private static final String _FINDER_COLUMN_G_P_N_NAME_2 = "layoutSetBranch.name = ?";
2785            private static final String _FINDER_COLUMN_G_P_N_NAME_3 = "(layoutSetBranch.name IS NULL OR layoutSetBranch.name = ?)";
2786            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "layoutSetBranch.layoutSetBranchId";
2787            private static final String _FILTER_SQL_SELECT_LAYOUTSETBRANCH_WHERE = "SELECT DISTINCT {layoutSetBranch.*} FROM LayoutSetBranch layoutSetBranch WHERE ";
2788            private static final String _FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_1 =
2789                    "SELECT {LayoutSetBranch.*} FROM (SELECT DISTINCT layoutSetBranch.layoutSetBranchId FROM LayoutSetBranch layoutSetBranch WHERE ";
2790            private static final String _FILTER_SQL_SELECT_LAYOUTSETBRANCH_NO_INLINE_DISTINCT_WHERE_2 =
2791                    ") TEMP_TABLE INNER JOIN LayoutSetBranch ON TEMP_TABLE.layoutSetBranchId = LayoutSetBranch.layoutSetBranchId";
2792            private static final String _FILTER_SQL_COUNT_LAYOUTSETBRANCH_WHERE = "SELECT COUNT(DISTINCT layoutSetBranch.layoutSetBranchId) AS COUNT_VALUE FROM LayoutSetBranch layoutSetBranch WHERE ";
2793            private static final String _FILTER_ENTITY_ALIAS = "layoutSetBranch";
2794            private static final String _FILTER_ENTITY_TABLE = "LayoutSetBranch";
2795            private static final String _ORDER_BY_ENTITY_ALIAS = "layoutSetBranch.";
2796            private static final String _ORDER_BY_ENTITY_TABLE = "LayoutSetBranch.";
2797            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutSetBranch exists with the primary key ";
2798            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutSetBranch exists with the key {";
2799            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2800            private static Log _log = LogFactoryUtil.getLog(LayoutSetBranchPersistenceImpl.class);
2801            private static LayoutSetBranch _nullLayoutSetBranch = new LayoutSetBranchImpl() {
2802                            @Override
2803                            public Object clone() {
2804                                    return this;
2805                            }
2806    
2807                            @Override
2808                            public CacheModel<LayoutSetBranch> toCacheModel() {
2809                                    return _nullLayoutSetBranchCacheModel;
2810                            }
2811                    };
2812    
2813            private static CacheModel<LayoutSetBranch> _nullLayoutSetBranchCacheModel = new CacheModel<LayoutSetBranch>() {
2814                            public LayoutSetBranch toEntityModel() {
2815                                    return _nullLayoutSetBranch;
2816                            }
2817                    };
2818    }