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