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