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