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