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