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