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            public LayoutBranchPersistenceImpl() {
1972                    setModelClass(LayoutBranch.class);
1973            }
1974    
1975            /**
1976             * Caches the layout branch in the entity cache if it is enabled.
1977             *
1978             * @param layoutBranch the layout branch
1979             */
1980            @Override
1981            public void cacheResult(LayoutBranch layoutBranch) {
1982                    EntityCacheUtil.putResult(LayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
1983                            LayoutBranchImpl.class, layoutBranch.getPrimaryKey(), layoutBranch);
1984    
1985                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_L_P_N,
1986                            new Object[] {
1987                                    layoutBranch.getLayoutSetBranchId(), layoutBranch.getPlid(),
1988                                    layoutBranch.getName()
1989                            }, layoutBranch);
1990    
1991                    layoutBranch.resetOriginalValues();
1992            }
1993    
1994            /**
1995             * Caches the layout branchs in the entity cache if it is enabled.
1996             *
1997             * @param layoutBranchs the layout branchs
1998             */
1999            @Override
2000            public void cacheResult(List<LayoutBranch> layoutBranchs) {
2001                    for (LayoutBranch layoutBranch : layoutBranchs) {
2002                            if (EntityCacheUtil.getResult(
2003                                                    LayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2004                                                    LayoutBranchImpl.class, layoutBranch.getPrimaryKey()) == null) {
2005                                    cacheResult(layoutBranch);
2006                            }
2007                            else {
2008                                    layoutBranch.resetOriginalValues();
2009                            }
2010                    }
2011            }
2012    
2013            /**
2014             * Clears the cache for all layout branchs.
2015             *
2016             * <p>
2017             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2018             * </p>
2019             */
2020            @Override
2021            public void clearCache() {
2022                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2023                            CacheRegistryUtil.clear(LayoutBranchImpl.class.getName());
2024                    }
2025    
2026                    EntityCacheUtil.clearCache(LayoutBranchImpl.class.getName());
2027    
2028                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2029                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2030                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2031            }
2032    
2033            /**
2034             * Clears the cache for the layout branch.
2035             *
2036             * <p>
2037             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2038             * </p>
2039             */
2040            @Override
2041            public void clearCache(LayoutBranch layoutBranch) {
2042                    EntityCacheUtil.removeResult(LayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2043                            LayoutBranchImpl.class, layoutBranch.getPrimaryKey());
2044    
2045                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2046                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2047    
2048                    clearUniqueFindersCache(layoutBranch);
2049            }
2050    
2051            @Override
2052            public void clearCache(List<LayoutBranch> layoutBranchs) {
2053                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2054                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2055    
2056                    for (LayoutBranch layoutBranch : layoutBranchs) {
2057                            EntityCacheUtil.removeResult(LayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2058                                    LayoutBranchImpl.class, layoutBranch.getPrimaryKey());
2059    
2060                            clearUniqueFindersCache(layoutBranch);
2061                    }
2062            }
2063    
2064            protected void cacheUniqueFindersCache(LayoutBranch layoutBranch) {
2065                    if (layoutBranch.isNew()) {
2066                            Object[] args = new Object[] {
2067                                            layoutBranch.getLayoutSetBranchId(), layoutBranch.getPlid(),
2068                                            layoutBranch.getName()
2069                                    };
2070    
2071                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_L_P_N, args,
2072                                    Long.valueOf(1));
2073                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_L_P_N, args,
2074                                    layoutBranch);
2075                    }
2076                    else {
2077                            LayoutBranchModelImpl layoutBranchModelImpl = (LayoutBranchModelImpl)layoutBranch;
2078    
2079                            if ((layoutBranchModelImpl.getColumnBitmask() &
2080                                            FINDER_PATH_FETCH_BY_L_P_N.getColumnBitmask()) != 0) {
2081                                    Object[] args = new Object[] {
2082                                                    layoutBranch.getLayoutSetBranchId(),
2083                                                    layoutBranch.getPlid(), layoutBranch.getName()
2084                                            };
2085    
2086                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_L_P_N, args,
2087                                            Long.valueOf(1));
2088                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_L_P_N, args,
2089                                            layoutBranch);
2090                            }
2091                    }
2092            }
2093    
2094            protected void clearUniqueFindersCache(LayoutBranch layoutBranch) {
2095                    LayoutBranchModelImpl layoutBranchModelImpl = (LayoutBranchModelImpl)layoutBranch;
2096    
2097                    Object[] args = new Object[] {
2098                                    layoutBranch.getLayoutSetBranchId(), layoutBranch.getPlid(),
2099                                    layoutBranch.getName()
2100                            };
2101    
2102                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P_N, args);
2103                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_L_P_N, args);
2104    
2105                    if ((layoutBranchModelImpl.getColumnBitmask() &
2106                                    FINDER_PATH_FETCH_BY_L_P_N.getColumnBitmask()) != 0) {
2107                            args = new Object[] {
2108                                            layoutBranchModelImpl.getOriginalLayoutSetBranchId(),
2109                                            layoutBranchModelImpl.getOriginalPlid(),
2110                                            layoutBranchModelImpl.getOriginalName()
2111                                    };
2112    
2113                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P_N, args);
2114                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_L_P_N, args);
2115                    }
2116            }
2117    
2118            /**
2119             * Creates a new layout branch with the primary key. Does not add the layout branch to the database.
2120             *
2121             * @param LayoutBranchId the primary key for the new layout branch
2122             * @return the new layout branch
2123             */
2124            @Override
2125            public LayoutBranch create(long LayoutBranchId) {
2126                    LayoutBranch layoutBranch = new LayoutBranchImpl();
2127    
2128                    layoutBranch.setNew(true);
2129                    layoutBranch.setPrimaryKey(LayoutBranchId);
2130    
2131                    return layoutBranch;
2132            }
2133    
2134            /**
2135             * Removes the layout branch with the primary key from the database. Also notifies the appropriate model listeners.
2136             *
2137             * @param LayoutBranchId the primary key of the layout branch
2138             * @return the layout branch that was removed
2139             * @throws com.liferay.portal.NoSuchLayoutBranchException if a layout branch with the primary key could not be found
2140             * @throws SystemException if a system exception occurred
2141             */
2142            @Override
2143            public LayoutBranch remove(long LayoutBranchId)
2144                    throws NoSuchLayoutBranchException, SystemException {
2145                    return remove((Serializable)LayoutBranchId);
2146            }
2147    
2148            /**
2149             * Removes the layout branch with the primary key from the database. Also notifies the appropriate model listeners.
2150             *
2151             * @param primaryKey the primary key of the layout branch
2152             * @return the layout branch that was removed
2153             * @throws com.liferay.portal.NoSuchLayoutBranchException if a layout branch with the primary key could not be found
2154             * @throws SystemException if a system exception occurred
2155             */
2156            @Override
2157            public LayoutBranch remove(Serializable primaryKey)
2158                    throws NoSuchLayoutBranchException, SystemException {
2159                    Session session = null;
2160    
2161                    try {
2162                            session = openSession();
2163    
2164                            LayoutBranch layoutBranch = (LayoutBranch)session.get(LayoutBranchImpl.class,
2165                                            primaryKey);
2166    
2167                            if (layoutBranch == null) {
2168                                    if (_log.isWarnEnabled()) {
2169                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2170                                    }
2171    
2172                                    throw new NoSuchLayoutBranchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2173                                            primaryKey);
2174                            }
2175    
2176                            return remove(layoutBranch);
2177                    }
2178                    catch (NoSuchLayoutBranchException nsee) {
2179                            throw nsee;
2180                    }
2181                    catch (Exception e) {
2182                            throw processException(e);
2183                    }
2184                    finally {
2185                            closeSession(session);
2186                    }
2187            }
2188    
2189            @Override
2190            protected LayoutBranch removeImpl(LayoutBranch layoutBranch)
2191                    throws SystemException {
2192                    layoutBranch = toUnwrappedModel(layoutBranch);
2193    
2194                    Session session = null;
2195    
2196                    try {
2197                            session = openSession();
2198    
2199                            if (!session.contains(layoutBranch)) {
2200                                    layoutBranch = (LayoutBranch)session.get(LayoutBranchImpl.class,
2201                                                    layoutBranch.getPrimaryKeyObj());
2202                            }
2203    
2204                            if (layoutBranch != null) {
2205                                    session.delete(layoutBranch);
2206                            }
2207                    }
2208                    catch (Exception e) {
2209                            throw processException(e);
2210                    }
2211                    finally {
2212                            closeSession(session);
2213                    }
2214    
2215                    if (layoutBranch != null) {
2216                            clearCache(layoutBranch);
2217                    }
2218    
2219                    return layoutBranch;
2220            }
2221    
2222            @Override
2223            public LayoutBranch updateImpl(
2224                    com.liferay.portal.model.LayoutBranch layoutBranch)
2225                    throws SystemException {
2226                    layoutBranch = toUnwrappedModel(layoutBranch);
2227    
2228                    boolean isNew = layoutBranch.isNew();
2229    
2230                    LayoutBranchModelImpl layoutBranchModelImpl = (LayoutBranchModelImpl)layoutBranch;
2231    
2232                    Session session = null;
2233    
2234                    try {
2235                            session = openSession();
2236    
2237                            if (layoutBranch.isNew()) {
2238                                    session.save(layoutBranch);
2239    
2240                                    layoutBranch.setNew(false);
2241                            }
2242                            else {
2243                                    session.merge(layoutBranch);
2244                            }
2245                    }
2246                    catch (Exception e) {
2247                            throw processException(e);
2248                    }
2249                    finally {
2250                            closeSession(session);
2251                    }
2252    
2253                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2254    
2255                    if (isNew || !LayoutBranchModelImpl.COLUMN_BITMASK_ENABLED) {
2256                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2257                    }
2258    
2259                    else {
2260                            if ((layoutBranchModelImpl.getColumnBitmask() &
2261                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETBRANCHID.getColumnBitmask()) != 0) {
2262                                    Object[] args = new Object[] {
2263                                                    layoutBranchModelImpl.getOriginalLayoutSetBranchId()
2264                                            };
2265    
2266                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LAYOUTSETBRANCHID,
2267                                            args);
2268                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETBRANCHID,
2269                                            args);
2270    
2271                                    args = new Object[] { layoutBranchModelImpl.getLayoutSetBranchId() };
2272    
2273                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LAYOUTSETBRANCHID,
2274                                            args);
2275                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTSETBRANCHID,
2276                                            args);
2277                            }
2278    
2279                            if ((layoutBranchModelImpl.getColumnBitmask() &
2280                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P.getColumnBitmask()) != 0) {
2281                                    Object[] args = new Object[] {
2282                                                    layoutBranchModelImpl.getOriginalLayoutSetBranchId(),
2283                                                    layoutBranchModelImpl.getOriginalPlid()
2284                                            };
2285    
2286                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
2287                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
2288                                            args);
2289    
2290                                    args = new Object[] {
2291                                                    layoutBranchModelImpl.getLayoutSetBranchId(),
2292                                                    layoutBranchModelImpl.getPlid()
2293                                            };
2294    
2295                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
2296                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
2297                                            args);
2298                            }
2299    
2300                            if ((layoutBranchModelImpl.getColumnBitmask() &
2301                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P_M.getColumnBitmask()) != 0) {
2302                                    Object[] args = new Object[] {
2303                                                    layoutBranchModelImpl.getOriginalLayoutSetBranchId(),
2304                                                    layoutBranchModelImpl.getOriginalPlid(),
2305                                                    layoutBranchModelImpl.getOriginalMaster()
2306                                            };
2307    
2308                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P_M, args);
2309                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P_M,
2310                                            args);
2311    
2312                                    args = new Object[] {
2313                                                    layoutBranchModelImpl.getLayoutSetBranchId(),
2314                                                    layoutBranchModelImpl.getPlid(),
2315                                                    layoutBranchModelImpl.getMaster()
2316                                            };
2317    
2318                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P_M, args);
2319                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P_M,
2320                                            args);
2321                            }
2322                    }
2323    
2324                    EntityCacheUtil.putResult(LayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2325                            LayoutBranchImpl.class, layoutBranch.getPrimaryKey(), layoutBranch);
2326    
2327                    clearUniqueFindersCache(layoutBranch);
2328                    cacheUniqueFindersCache(layoutBranch);
2329    
2330                    return layoutBranch;
2331            }
2332    
2333            protected LayoutBranch toUnwrappedModel(LayoutBranch layoutBranch) {
2334                    if (layoutBranch instanceof LayoutBranchImpl) {
2335                            return layoutBranch;
2336                    }
2337    
2338                    LayoutBranchImpl layoutBranchImpl = new LayoutBranchImpl();
2339    
2340                    layoutBranchImpl.setNew(layoutBranch.isNew());
2341                    layoutBranchImpl.setPrimaryKey(layoutBranch.getPrimaryKey());
2342    
2343                    layoutBranchImpl.setLayoutBranchId(layoutBranch.getLayoutBranchId());
2344                    layoutBranchImpl.setGroupId(layoutBranch.getGroupId());
2345                    layoutBranchImpl.setCompanyId(layoutBranch.getCompanyId());
2346                    layoutBranchImpl.setUserId(layoutBranch.getUserId());
2347                    layoutBranchImpl.setUserName(layoutBranch.getUserName());
2348                    layoutBranchImpl.setLayoutSetBranchId(layoutBranch.getLayoutSetBranchId());
2349                    layoutBranchImpl.setPlid(layoutBranch.getPlid());
2350                    layoutBranchImpl.setName(layoutBranch.getName());
2351                    layoutBranchImpl.setDescription(layoutBranch.getDescription());
2352                    layoutBranchImpl.setMaster(layoutBranch.isMaster());
2353    
2354                    return layoutBranchImpl;
2355            }
2356    
2357            /**
2358             * Returns the layout branch with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2359             *
2360             * @param primaryKey the primary key of the layout branch
2361             * @return the layout branch
2362             * @throws com.liferay.portal.NoSuchLayoutBranchException if a layout branch with the primary key could not be found
2363             * @throws SystemException if a system exception occurred
2364             */
2365            @Override
2366            public LayoutBranch findByPrimaryKey(Serializable primaryKey)
2367                    throws NoSuchLayoutBranchException, SystemException {
2368                    LayoutBranch layoutBranch = fetchByPrimaryKey(primaryKey);
2369    
2370                    if (layoutBranch == null) {
2371                            if (_log.isWarnEnabled()) {
2372                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2373                            }
2374    
2375                            throw new NoSuchLayoutBranchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2376                                    primaryKey);
2377                    }
2378    
2379                    return layoutBranch;
2380            }
2381    
2382            /**
2383             * Returns the layout branch with the primary key or throws a {@link com.liferay.portal.NoSuchLayoutBranchException} if it could not be found.
2384             *
2385             * @param LayoutBranchId the primary key of the layout branch
2386             * @return the layout branch
2387             * @throws com.liferay.portal.NoSuchLayoutBranchException if a layout branch with the primary key could not be found
2388             * @throws SystemException if a system exception occurred
2389             */
2390            @Override
2391            public LayoutBranch findByPrimaryKey(long LayoutBranchId)
2392                    throws NoSuchLayoutBranchException, SystemException {
2393                    return findByPrimaryKey((Serializable)LayoutBranchId);
2394            }
2395    
2396            /**
2397             * Returns the layout branch with the primary key or returns <code>null</code> if it could not be found.
2398             *
2399             * @param primaryKey the primary key of the layout branch
2400             * @return the layout branch, or <code>null</code> if a layout branch with the primary key could not be found
2401             * @throws SystemException if a system exception occurred
2402             */
2403            @Override
2404            public LayoutBranch fetchByPrimaryKey(Serializable primaryKey)
2405                    throws SystemException {
2406                    LayoutBranch layoutBranch = (LayoutBranch)EntityCacheUtil.getResult(LayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2407                                    LayoutBranchImpl.class, primaryKey);
2408    
2409                    if (layoutBranch == _nullLayoutBranch) {
2410                            return null;
2411                    }
2412    
2413                    if (layoutBranch == null) {
2414                            Session session = null;
2415    
2416                            try {
2417                                    session = openSession();
2418    
2419                                    layoutBranch = (LayoutBranch)session.get(LayoutBranchImpl.class,
2420                                                    primaryKey);
2421    
2422                                    if (layoutBranch != null) {
2423                                            cacheResult(layoutBranch);
2424                                    }
2425                                    else {
2426                                            EntityCacheUtil.putResult(LayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2427                                                    LayoutBranchImpl.class, primaryKey, _nullLayoutBranch);
2428                                    }
2429                            }
2430                            catch (Exception e) {
2431                                    EntityCacheUtil.removeResult(LayoutBranchModelImpl.ENTITY_CACHE_ENABLED,
2432                                            LayoutBranchImpl.class, primaryKey);
2433    
2434                                    throw processException(e);
2435                            }
2436                            finally {
2437                                    closeSession(session);
2438                            }
2439                    }
2440    
2441                    return layoutBranch;
2442            }
2443    
2444            /**
2445             * Returns the layout branch with the primary key or returns <code>null</code> if it could not be found.
2446             *
2447             * @param LayoutBranchId the primary key of the layout branch
2448             * @return the layout branch, or <code>null</code> if a layout branch with the primary key could not be found
2449             * @throws SystemException if a system exception occurred
2450             */
2451            @Override
2452            public LayoutBranch fetchByPrimaryKey(long LayoutBranchId)
2453                    throws SystemException {
2454                    return fetchByPrimaryKey((Serializable)LayoutBranchId);
2455            }
2456    
2457            /**
2458             * Returns all the layout branchs.
2459             *
2460             * @return the layout branchs
2461             * @throws SystemException if a system exception occurred
2462             */
2463            @Override
2464            public List<LayoutBranch> findAll() throws SystemException {
2465                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2466            }
2467    
2468            /**
2469             * Returns a range of all the layout branchs.
2470             *
2471             * <p>
2472             * 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.
2473             * </p>
2474             *
2475             * @param start the lower bound of the range of layout branchs
2476             * @param end the upper bound of the range of layout branchs (not inclusive)
2477             * @return the range of layout branchs
2478             * @throws SystemException if a system exception occurred
2479             */
2480            @Override
2481            public List<LayoutBranch> findAll(int start, int end)
2482                    throws SystemException {
2483                    return findAll(start, end, null);
2484            }
2485    
2486            /**
2487             * Returns an ordered range of all the layout branchs.
2488             *
2489             * <p>
2490             * 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.
2491             * </p>
2492             *
2493             * @param start the lower bound of the range of layout branchs
2494             * @param end the upper bound of the range of layout branchs (not inclusive)
2495             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2496             * @return the ordered range of layout branchs
2497             * @throws SystemException if a system exception occurred
2498             */
2499            @Override
2500            public List<LayoutBranch> findAll(int start, int end,
2501                    OrderByComparator orderByComparator) throws SystemException {
2502                    boolean pagination = true;
2503                    FinderPath finderPath = null;
2504                    Object[] finderArgs = null;
2505    
2506                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2507                                    (orderByComparator == null)) {
2508                            pagination = false;
2509                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2510                            finderArgs = FINDER_ARGS_EMPTY;
2511                    }
2512                    else {
2513                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2514                            finderArgs = new Object[] { start, end, orderByComparator };
2515                    }
2516    
2517                    List<LayoutBranch> list = (List<LayoutBranch>)FinderCacheUtil.getResult(finderPath,
2518                                    finderArgs, this);
2519    
2520                    if (list == null) {
2521                            StringBundler query = null;
2522                            String sql = null;
2523    
2524                            if (orderByComparator != null) {
2525                                    query = new StringBundler(2 +
2526                                                    (orderByComparator.getOrderByFields().length * 3));
2527    
2528                                    query.append(_SQL_SELECT_LAYOUTBRANCH);
2529    
2530                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2531                                            orderByComparator);
2532    
2533                                    sql = query.toString();
2534                            }
2535                            else {
2536                                    sql = _SQL_SELECT_LAYOUTBRANCH;
2537    
2538                                    if (pagination) {
2539                                            sql = sql.concat(LayoutBranchModelImpl.ORDER_BY_JPQL);
2540                                    }
2541                            }
2542    
2543                            Session session = null;
2544    
2545                            try {
2546                                    session = openSession();
2547    
2548                                    Query q = session.createQuery(sql);
2549    
2550                                    if (!pagination) {
2551                                            list = (List<LayoutBranch>)QueryUtil.list(q, getDialect(),
2552                                                            start, end, false);
2553    
2554                                            Collections.sort(list);
2555    
2556                                            list = new UnmodifiableList<LayoutBranch>(list);
2557                                    }
2558                                    else {
2559                                            list = (List<LayoutBranch>)QueryUtil.list(q, getDialect(),
2560                                                            start, end);
2561                                    }
2562    
2563                                    cacheResult(list);
2564    
2565                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2566                            }
2567                            catch (Exception e) {
2568                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2569    
2570                                    throw processException(e);
2571                            }
2572                            finally {
2573                                    closeSession(session);
2574                            }
2575                    }
2576    
2577                    return list;
2578            }
2579    
2580            /**
2581             * Removes all the layout branchs from the database.
2582             *
2583             * @throws SystemException if a system exception occurred
2584             */
2585            @Override
2586            public void removeAll() throws SystemException {
2587                    for (LayoutBranch layoutBranch : findAll()) {
2588                            remove(layoutBranch);
2589                    }
2590            }
2591    
2592            /**
2593             * Returns the number of layout branchs.
2594             *
2595             * @return the number of layout branchs
2596             * @throws SystemException if a system exception occurred
2597             */
2598            @Override
2599            public int countAll() throws SystemException {
2600                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2601                                    FINDER_ARGS_EMPTY, this);
2602    
2603                    if (count == null) {
2604                            Session session = null;
2605    
2606                            try {
2607                                    session = openSession();
2608    
2609                                    Query q = session.createQuery(_SQL_COUNT_LAYOUTBRANCH);
2610    
2611                                    count = (Long)q.uniqueResult();
2612    
2613                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2614                                            FINDER_ARGS_EMPTY, count);
2615                            }
2616                            catch (Exception e) {
2617                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2618                                            FINDER_ARGS_EMPTY);
2619    
2620                                    throw processException(e);
2621                            }
2622                            finally {
2623                                    closeSession(session);
2624                            }
2625                    }
2626    
2627                    return count.intValue();
2628            }
2629    
2630            /**
2631             * Initializes the layout branch persistence.
2632             */
2633            public void afterPropertiesSet() {
2634                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2635                                            com.liferay.portal.util.PropsUtil.get(
2636                                                    "value.object.listener.com.liferay.portal.model.LayoutBranch")));
2637    
2638                    if (listenerClassNames.length > 0) {
2639                            try {
2640                                    List<ModelListener<LayoutBranch>> listenersList = new ArrayList<ModelListener<LayoutBranch>>();
2641    
2642                                    for (String listenerClassName : listenerClassNames) {
2643                                            listenersList.add((ModelListener<LayoutBranch>)InstanceFactory.newInstance(
2644                                                            getClassLoader(), listenerClassName));
2645                                    }
2646    
2647                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2648                            }
2649                            catch (Exception e) {
2650                                    _log.error(e);
2651                            }
2652                    }
2653            }
2654    
2655            public void destroy() {
2656                    EntityCacheUtil.removeCache(LayoutBranchImpl.class.getName());
2657                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2658                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2659                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2660            }
2661    
2662            private static final String _SQL_SELECT_LAYOUTBRANCH = "SELECT layoutBranch FROM LayoutBranch layoutBranch";
2663            private static final String _SQL_SELECT_LAYOUTBRANCH_WHERE = "SELECT layoutBranch FROM LayoutBranch layoutBranch WHERE ";
2664            private static final String _SQL_COUNT_LAYOUTBRANCH = "SELECT COUNT(layoutBranch) FROM LayoutBranch layoutBranch";
2665            private static final String _SQL_COUNT_LAYOUTBRANCH_WHERE = "SELECT COUNT(layoutBranch) FROM LayoutBranch layoutBranch WHERE ";
2666            private static final String _ORDER_BY_ENTITY_ALIAS = "layoutBranch.";
2667            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutBranch exists with the primary key ";
2668            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutBranch exists with the key {";
2669            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2670            private static Log _log = LogFactoryUtil.getLog(LayoutBranchPersistenceImpl.class);
2671            private static LayoutBranch _nullLayoutBranch = new LayoutBranchImpl() {
2672                            @Override
2673                            public Object clone() {
2674                                    return this;
2675                            }
2676    
2677                            @Override
2678                            public CacheModel<LayoutBranch> toCacheModel() {
2679                                    return _nullLayoutBranchCacheModel;
2680                            }
2681                    };
2682    
2683            private static CacheModel<LayoutBranch> _nullLayoutBranchCacheModel = new CacheModel<LayoutBranch>() {
2684                            @Override
2685                            public LayoutBranch toEntityModel() {
2686                                    return _nullLayoutBranch;
2687                            }
2688                    };
2689    }