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