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.NoSuchLayoutSetPrototypeException;
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.SQLQuery;
030    import com.liferay.portal.kernel.dao.orm.Session;
031    import com.liferay.portal.kernel.log.Log;
032    import com.liferay.portal.kernel.log.LogFactoryUtil;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.SetUtil;
035    import com.liferay.portal.kernel.util.StringBundler;
036    import com.liferay.portal.kernel.util.StringPool;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.LayoutSetPrototype;
041    import com.liferay.portal.model.MVCCModel;
042    import com.liferay.portal.model.impl.LayoutSetPrototypeImpl;
043    import com.liferay.portal.model.impl.LayoutSetPrototypeModelImpl;
044    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
045    import com.liferay.portal.service.ServiceContext;
046    import com.liferay.portal.service.ServiceContextThreadLocal;
047    import com.liferay.portal.service.persistence.CompanyProvider;
048    import com.liferay.portal.service.persistence.CompanyProviderWrapper;
049    import com.liferay.portal.service.persistence.LayoutSetPrototypePersistence;
050    
051    import java.io.Serializable;
052    
053    import java.util.Collections;
054    import java.util.Date;
055    import java.util.HashMap;
056    import java.util.HashSet;
057    import java.util.Iterator;
058    import java.util.List;
059    import java.util.Map;
060    import java.util.Set;
061    
062    /**
063     * The persistence implementation for the layout set prototype service.
064     *
065     * <p>
066     * Caching information and settings can be found in <code>portal.properties</code>
067     * </p>
068     *
069     * @author Brian Wing Shun Chan
070     * @see LayoutSetPrototypePersistence
071     * @see com.liferay.portal.service.persistence.LayoutSetPrototypeUtil
072     * @generated
073     */
074    @ProviderType
075    public class LayoutSetPrototypePersistenceImpl extends BasePersistenceImpl<LayoutSetPrototype>
076            implements LayoutSetPrototypePersistence {
077            /*
078             * NOTE FOR DEVELOPERS:
079             *
080             * Never modify or reference this class directly. Always use {@link LayoutSetPrototypeUtil} to access the layout set prototype persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
081             */
082            public static final String FINDER_CLASS_NAME_ENTITY = LayoutSetPrototypeImpl.class.getName();
083            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084                    ".List1";
085            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086                    ".List2";
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
088                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
089                            LayoutSetPrototypeImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
091            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
092                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
093                            LayoutSetPrototypeImpl.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
095            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
096                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
098            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
099                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
100                            LayoutSetPrototypeImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
102                            new String[] {
103                                    String.class.getName(),
104                                    
105                            Integer.class.getName(), Integer.class.getName(),
106                                    OrderByComparator.class.getName()
107                            });
108            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
109                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
110                            LayoutSetPrototypeImpl.class,
111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
112                            new String[] { String.class.getName() },
113                            LayoutSetPrototypeModelImpl.UUID_COLUMN_BITMASK);
114            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
115                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
116                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
117                            new String[] { String.class.getName() });
118    
119            /**
120             * Returns all the layout set prototypes where uuid = &#63;.
121             *
122             * @param uuid the uuid
123             * @return the matching layout set prototypes
124             */
125            @Override
126            public List<LayoutSetPrototype> findByUuid(String uuid) {
127                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
128            }
129    
130            /**
131             * Returns a range of all the layout set prototypes where uuid = &#63;.
132             *
133             * <p>
134             * 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 LayoutSetPrototypeModelImpl}. 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.
135             * </p>
136             *
137             * @param uuid the uuid
138             * @param start the lower bound of the range of layout set prototypes
139             * @param end the upper bound of the range of layout set prototypes (not inclusive)
140             * @return the range of matching layout set prototypes
141             */
142            @Override
143            public List<LayoutSetPrototype> findByUuid(String uuid, int start, int end) {
144                    return findByUuid(uuid, start, end, null);
145            }
146    
147            /**
148             * Returns an ordered range of all the layout set prototypes where uuid = &#63;.
149             *
150             * <p>
151             * 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 LayoutSetPrototypeModelImpl}. 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.
152             * </p>
153             *
154             * @param uuid the uuid
155             * @param start the lower bound of the range of layout set prototypes
156             * @param end the upper bound of the range of layout set prototypes (not inclusive)
157             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
158             * @return the ordered range of matching layout set prototypes
159             */
160            @Override
161            public List<LayoutSetPrototype> findByUuid(String uuid, int start, int end,
162                    OrderByComparator<LayoutSetPrototype> orderByComparator) {
163                    return findByUuid(uuid, start, end, orderByComparator, true);
164            }
165    
166            /**
167             * Returns an ordered range of all the layout set prototypes where uuid = &#63;.
168             *
169             * <p>
170             * 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 LayoutSetPrototypeModelImpl}. 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.
171             * </p>
172             *
173             * @param uuid the uuid
174             * @param start the lower bound of the range of layout set prototypes
175             * @param end the upper bound of the range of layout set prototypes (not inclusive)
176             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
177             * @param retrieveFromCache whether to retrieve from the finder cache
178             * @return the ordered range of matching layout set prototypes
179             */
180            @Override
181            public List<LayoutSetPrototype> findByUuid(String uuid, int start, int end,
182                    OrderByComparator<LayoutSetPrototype> orderByComparator,
183                    boolean retrieveFromCache) {
184                    boolean pagination = true;
185                    FinderPath finderPath = null;
186                    Object[] finderArgs = null;
187    
188                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
189                                    (orderByComparator == null)) {
190                            pagination = false;
191                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
192                            finderArgs = new Object[] { uuid };
193                    }
194                    else {
195                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
196                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
197                    }
198    
199                    List<LayoutSetPrototype> list = null;
200    
201                    if (retrieveFromCache) {
202                            list = (List<LayoutSetPrototype>)finderCache.getResult(finderPath,
203                                            finderArgs, this);
204    
205                            if ((list != null) && !list.isEmpty()) {
206                                    for (LayoutSetPrototype layoutSetPrototype : list) {
207                                            if (!Validator.equals(uuid, layoutSetPrototype.getUuid())) {
208                                                    list = null;
209    
210                                                    break;
211                                            }
212                                    }
213                            }
214                    }
215    
216                    if (list == null) {
217                            StringBundler query = null;
218    
219                            if (orderByComparator != null) {
220                                    query = new StringBundler(3 +
221                                                    (orderByComparator.getOrderByFields().length * 3));
222                            }
223                            else {
224                                    query = new StringBundler(3);
225                            }
226    
227                            query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
228    
229                            boolean bindUuid = false;
230    
231                            if (uuid == null) {
232                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
233                            }
234                            else if (uuid.equals(StringPool.BLANK)) {
235                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
236                            }
237                            else {
238                                    bindUuid = true;
239    
240                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
241                            }
242    
243                            if (orderByComparator != null) {
244                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
245                                            orderByComparator);
246                            }
247                            else
248                             if (pagination) {
249                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
250                            }
251    
252                            String sql = query.toString();
253    
254                            Session session = null;
255    
256                            try {
257                                    session = openSession();
258    
259                                    Query q = session.createQuery(sql);
260    
261                                    QueryPos qPos = QueryPos.getInstance(q);
262    
263                                    if (bindUuid) {
264                                            qPos.add(uuid);
265                                    }
266    
267                                    if (!pagination) {
268                                            list = (List<LayoutSetPrototype>)QueryUtil.list(q,
269                                                            getDialect(), start, end, false);
270    
271                                            Collections.sort(list);
272    
273                                            list = Collections.unmodifiableList(list);
274                                    }
275                                    else {
276                                            list = (List<LayoutSetPrototype>)QueryUtil.list(q,
277                                                            getDialect(), start, end);
278                                    }
279    
280                                    cacheResult(list);
281    
282                                    finderCache.putResult(finderPath, finderArgs, list);
283                            }
284                            catch (Exception e) {
285                                    finderCache.removeResult(finderPath, finderArgs);
286    
287                                    throw processException(e);
288                            }
289                            finally {
290                                    closeSession(session);
291                            }
292                    }
293    
294                    return list;
295            }
296    
297            /**
298             * Returns the first layout set prototype in the ordered set where uuid = &#63;.
299             *
300             * @param uuid the uuid
301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
302             * @return the first matching layout set prototype
303             * @throws NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
304             */
305            @Override
306            public LayoutSetPrototype findByUuid_First(String uuid,
307                    OrderByComparator<LayoutSetPrototype> orderByComparator)
308                    throws NoSuchLayoutSetPrototypeException {
309                    LayoutSetPrototype layoutSetPrototype = fetchByUuid_First(uuid,
310                                    orderByComparator);
311    
312                    if (layoutSetPrototype != null) {
313                            return layoutSetPrototype;
314                    }
315    
316                    StringBundler msg = new StringBundler(4);
317    
318                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
319    
320                    msg.append("uuid=");
321                    msg.append(uuid);
322    
323                    msg.append(StringPool.CLOSE_CURLY_BRACE);
324    
325                    throw new NoSuchLayoutSetPrototypeException(msg.toString());
326            }
327    
328            /**
329             * Returns the first layout set prototype in the ordered set where uuid = &#63;.
330             *
331             * @param uuid the uuid
332             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
333             * @return the first matching layout set prototype, or <code>null</code> if a matching layout set prototype could not be found
334             */
335            @Override
336            public LayoutSetPrototype fetchByUuid_First(String uuid,
337                    OrderByComparator<LayoutSetPrototype> orderByComparator) {
338                    List<LayoutSetPrototype> list = findByUuid(uuid, 0, 1, orderByComparator);
339    
340                    if (!list.isEmpty()) {
341                            return list.get(0);
342                    }
343    
344                    return null;
345            }
346    
347            /**
348             * Returns the last layout set prototype in the ordered set where uuid = &#63;.
349             *
350             * @param uuid the uuid
351             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
352             * @return the last matching layout set prototype
353             * @throws NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
354             */
355            @Override
356            public LayoutSetPrototype findByUuid_Last(String uuid,
357                    OrderByComparator<LayoutSetPrototype> orderByComparator)
358                    throws NoSuchLayoutSetPrototypeException {
359                    LayoutSetPrototype layoutSetPrototype = fetchByUuid_Last(uuid,
360                                    orderByComparator);
361    
362                    if (layoutSetPrototype != null) {
363                            return layoutSetPrototype;
364                    }
365    
366                    StringBundler msg = new StringBundler(4);
367    
368                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
369    
370                    msg.append("uuid=");
371                    msg.append(uuid);
372    
373                    msg.append(StringPool.CLOSE_CURLY_BRACE);
374    
375                    throw new NoSuchLayoutSetPrototypeException(msg.toString());
376            }
377    
378            /**
379             * Returns the last layout set prototype in the ordered set where uuid = &#63;.
380             *
381             * @param uuid the uuid
382             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
383             * @return the last matching layout set prototype, or <code>null</code> if a matching layout set prototype could not be found
384             */
385            @Override
386            public LayoutSetPrototype fetchByUuid_Last(String uuid,
387                    OrderByComparator<LayoutSetPrototype> orderByComparator) {
388                    int count = countByUuid(uuid);
389    
390                    if (count == 0) {
391                            return null;
392                    }
393    
394                    List<LayoutSetPrototype> list = findByUuid(uuid, count - 1, count,
395                                    orderByComparator);
396    
397                    if (!list.isEmpty()) {
398                            return list.get(0);
399                    }
400    
401                    return null;
402            }
403    
404            /**
405             * Returns the layout set prototypes before and after the current layout set prototype in the ordered set where uuid = &#63;.
406             *
407             * @param layoutSetPrototypeId the primary key of the current layout set prototype
408             * @param uuid the uuid
409             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
410             * @return the previous, current, and next layout set prototype
411             * @throws NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
412             */
413            @Override
414            public LayoutSetPrototype[] findByUuid_PrevAndNext(
415                    long layoutSetPrototypeId, String uuid,
416                    OrderByComparator<LayoutSetPrototype> orderByComparator)
417                    throws NoSuchLayoutSetPrototypeException {
418                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
419    
420                    Session session = null;
421    
422                    try {
423                            session = openSession();
424    
425                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
426    
427                            array[0] = getByUuid_PrevAndNext(session, layoutSetPrototype, uuid,
428                                            orderByComparator, true);
429    
430                            array[1] = layoutSetPrototype;
431    
432                            array[2] = getByUuid_PrevAndNext(session, layoutSetPrototype, uuid,
433                                            orderByComparator, false);
434    
435                            return array;
436                    }
437                    catch (Exception e) {
438                            throw processException(e);
439                    }
440                    finally {
441                            closeSession(session);
442                    }
443            }
444    
445            protected LayoutSetPrototype getByUuid_PrevAndNext(Session session,
446                    LayoutSetPrototype layoutSetPrototype, String uuid,
447                    OrderByComparator<LayoutSetPrototype> orderByComparator,
448                    boolean previous) {
449                    StringBundler query = null;
450    
451                    if (orderByComparator != null) {
452                            query = new StringBundler(6 +
453                                            (orderByComparator.getOrderByFields().length * 6));
454                    }
455                    else {
456                            query = new StringBundler(3);
457                    }
458    
459                    query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
460    
461                    boolean bindUuid = false;
462    
463                    if (uuid == null) {
464                            query.append(_FINDER_COLUMN_UUID_UUID_1);
465                    }
466                    else if (uuid.equals(StringPool.BLANK)) {
467                            query.append(_FINDER_COLUMN_UUID_UUID_3);
468                    }
469                    else {
470                            bindUuid = true;
471    
472                            query.append(_FINDER_COLUMN_UUID_UUID_2);
473                    }
474    
475                    if (orderByComparator != null) {
476                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
477    
478                            if (orderByConditionFields.length > 0) {
479                                    query.append(WHERE_AND);
480                            }
481    
482                            for (int i = 0; i < orderByConditionFields.length; i++) {
483                                    query.append(_ORDER_BY_ENTITY_ALIAS);
484                                    query.append(orderByConditionFields[i]);
485    
486                                    if ((i + 1) < orderByConditionFields.length) {
487                                            if (orderByComparator.isAscending() ^ previous) {
488                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
489                                            }
490                                            else {
491                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
492                                            }
493                                    }
494                                    else {
495                                            if (orderByComparator.isAscending() ^ previous) {
496                                                    query.append(WHERE_GREATER_THAN);
497                                            }
498                                            else {
499                                                    query.append(WHERE_LESSER_THAN);
500                                            }
501                                    }
502                            }
503    
504                            query.append(ORDER_BY_CLAUSE);
505    
506                            String[] orderByFields = orderByComparator.getOrderByFields();
507    
508                            for (int i = 0; i < orderByFields.length; i++) {
509                                    query.append(_ORDER_BY_ENTITY_ALIAS);
510                                    query.append(orderByFields[i]);
511    
512                                    if ((i + 1) < orderByFields.length) {
513                                            if (orderByComparator.isAscending() ^ previous) {
514                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
515                                            }
516                                            else {
517                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
518                                            }
519                                    }
520                                    else {
521                                            if (orderByComparator.isAscending() ^ previous) {
522                                                    query.append(ORDER_BY_ASC);
523                                            }
524                                            else {
525                                                    query.append(ORDER_BY_DESC);
526                                            }
527                                    }
528                            }
529                    }
530                    else {
531                            query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
532                    }
533    
534                    String sql = query.toString();
535    
536                    Query q = session.createQuery(sql);
537    
538                    q.setFirstResult(0);
539                    q.setMaxResults(2);
540    
541                    QueryPos qPos = QueryPos.getInstance(q);
542    
543                    if (bindUuid) {
544                            qPos.add(uuid);
545                    }
546    
547                    if (orderByComparator != null) {
548                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetPrototype);
549    
550                            for (Object value : values) {
551                                    qPos.add(value);
552                            }
553                    }
554    
555                    List<LayoutSetPrototype> list = q.list();
556    
557                    if (list.size() == 2) {
558                            return list.get(1);
559                    }
560                    else {
561                            return null;
562                    }
563            }
564    
565            /**
566             * Returns all the layout set prototypes that the user has permission to view where uuid = &#63;.
567             *
568             * @param uuid the uuid
569             * @return the matching layout set prototypes that the user has permission to view
570             */
571            @Override
572            public List<LayoutSetPrototype> filterFindByUuid(String uuid) {
573                    return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
574            }
575    
576            /**
577             * Returns a range of all the layout set prototypes that the user has permission to view where uuid = &#63;.
578             *
579             * <p>
580             * 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 LayoutSetPrototypeModelImpl}. 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.
581             * </p>
582             *
583             * @param uuid the uuid
584             * @param start the lower bound of the range of layout set prototypes
585             * @param end the upper bound of the range of layout set prototypes (not inclusive)
586             * @return the range of matching layout set prototypes that the user has permission to view
587             */
588            @Override
589            public List<LayoutSetPrototype> filterFindByUuid(String uuid, int start,
590                    int end) {
591                    return filterFindByUuid(uuid, start, end, null);
592            }
593    
594            /**
595             * Returns an ordered range of all the layout set prototypes that the user has permissions to view where uuid = &#63;.
596             *
597             * <p>
598             * 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 LayoutSetPrototypeModelImpl}. 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.
599             * </p>
600             *
601             * @param uuid the uuid
602             * @param start the lower bound of the range of layout set prototypes
603             * @param end the upper bound of the range of layout set prototypes (not inclusive)
604             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
605             * @return the ordered range of matching layout set prototypes that the user has permission to view
606             */
607            @Override
608            public List<LayoutSetPrototype> filterFindByUuid(String uuid, int start,
609                    int end, OrderByComparator<LayoutSetPrototype> orderByComparator) {
610                    if (!InlineSQLHelperUtil.isEnabled()) {
611                            return findByUuid(uuid, start, end, orderByComparator);
612                    }
613    
614                    StringBundler query = null;
615    
616                    if (orderByComparator != null) {
617                            query = new StringBundler(3 +
618                                            (orderByComparator.getOrderByFields().length * 3));
619                    }
620                    else {
621                            query = new StringBundler(3);
622                    }
623    
624                    if (getDB().isSupportsInlineDistinct()) {
625                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
626                    }
627                    else {
628                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
629                    }
630    
631                    boolean bindUuid = false;
632    
633                    if (uuid == null) {
634                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
635                    }
636                    else if (uuid.equals(StringPool.BLANK)) {
637                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
638                    }
639                    else {
640                            bindUuid = true;
641    
642                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
643                    }
644    
645                    if (!getDB().isSupportsInlineDistinct()) {
646                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
647                    }
648    
649                    if (orderByComparator != null) {
650                            if (getDB().isSupportsInlineDistinct()) {
651                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
652                                            orderByComparator, true);
653                            }
654                            else {
655                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
656                                            orderByComparator, true);
657                            }
658                    }
659                    else {
660                            if (getDB().isSupportsInlineDistinct()) {
661                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
662                            }
663                            else {
664                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_SQL);
665                            }
666                    }
667    
668                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
669                                    LayoutSetPrototype.class.getName(),
670                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
671    
672                    Session session = null;
673    
674                    try {
675                            session = openSession();
676    
677                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
678    
679                            if (getDB().isSupportsInlineDistinct()) {
680                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetPrototypeImpl.class);
681                            }
682                            else {
683                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetPrototypeImpl.class);
684                            }
685    
686                            QueryPos qPos = QueryPos.getInstance(q);
687    
688                            if (bindUuid) {
689                                    qPos.add(uuid);
690                            }
691    
692                            return (List<LayoutSetPrototype>)QueryUtil.list(q, getDialect(),
693                                    start, end);
694                    }
695                    catch (Exception e) {
696                            throw processException(e);
697                    }
698                    finally {
699                            closeSession(session);
700                    }
701            }
702    
703            /**
704             * Returns the layout set prototypes before and after the current layout set prototype in the ordered set of layout set prototypes that the user has permission to view where uuid = &#63;.
705             *
706             * @param layoutSetPrototypeId the primary key of the current layout set prototype
707             * @param uuid the uuid
708             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
709             * @return the previous, current, and next layout set prototype
710             * @throws NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
711             */
712            @Override
713            public LayoutSetPrototype[] filterFindByUuid_PrevAndNext(
714                    long layoutSetPrototypeId, String uuid,
715                    OrderByComparator<LayoutSetPrototype> orderByComparator)
716                    throws NoSuchLayoutSetPrototypeException {
717                    if (!InlineSQLHelperUtil.isEnabled()) {
718                            return findByUuid_PrevAndNext(layoutSetPrototypeId, uuid,
719                                    orderByComparator);
720                    }
721    
722                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
723    
724                    Session session = null;
725    
726                    try {
727                            session = openSession();
728    
729                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
730    
731                            array[0] = filterGetByUuid_PrevAndNext(session, layoutSetPrototype,
732                                            uuid, orderByComparator, true);
733    
734                            array[1] = layoutSetPrototype;
735    
736                            array[2] = filterGetByUuid_PrevAndNext(session, layoutSetPrototype,
737                                            uuid, orderByComparator, false);
738    
739                            return array;
740                    }
741                    catch (Exception e) {
742                            throw processException(e);
743                    }
744                    finally {
745                            closeSession(session);
746                    }
747            }
748    
749            protected LayoutSetPrototype filterGetByUuid_PrevAndNext(Session session,
750                    LayoutSetPrototype layoutSetPrototype, String uuid,
751                    OrderByComparator<LayoutSetPrototype> orderByComparator,
752                    boolean previous) {
753                    StringBundler query = null;
754    
755                    if (orderByComparator != null) {
756                            query = new StringBundler(6 +
757                                            (orderByComparator.getOrderByFields().length * 6));
758                    }
759                    else {
760                            query = new StringBundler(3);
761                    }
762    
763                    if (getDB().isSupportsInlineDistinct()) {
764                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
765                    }
766                    else {
767                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
768                    }
769    
770                    boolean bindUuid = false;
771    
772                    if (uuid == null) {
773                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
774                    }
775                    else if (uuid.equals(StringPool.BLANK)) {
776                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
777                    }
778                    else {
779                            bindUuid = true;
780    
781                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
782                    }
783    
784                    if (!getDB().isSupportsInlineDistinct()) {
785                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
786                    }
787    
788                    if (orderByComparator != null) {
789                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
790    
791                            if (orderByConditionFields.length > 0) {
792                                    query.append(WHERE_AND);
793                            }
794    
795                            for (int i = 0; i < orderByConditionFields.length; i++) {
796                                    if (getDB().isSupportsInlineDistinct()) {
797                                            query.append(_ORDER_BY_ENTITY_ALIAS);
798                                    }
799                                    else {
800                                            query.append(_ORDER_BY_ENTITY_TABLE);
801                                    }
802    
803                                    query.append(orderByConditionFields[i]);
804    
805                                    if ((i + 1) < orderByConditionFields.length) {
806                                            if (orderByComparator.isAscending() ^ previous) {
807                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
808                                            }
809                                            else {
810                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
811                                            }
812                                    }
813                                    else {
814                                            if (orderByComparator.isAscending() ^ previous) {
815                                                    query.append(WHERE_GREATER_THAN);
816                                            }
817                                            else {
818                                                    query.append(WHERE_LESSER_THAN);
819                                            }
820                                    }
821                            }
822    
823                            query.append(ORDER_BY_CLAUSE);
824    
825                            String[] orderByFields = orderByComparator.getOrderByFields();
826    
827                            for (int i = 0; i < orderByFields.length; i++) {
828                                    if (getDB().isSupportsInlineDistinct()) {
829                                            query.append(_ORDER_BY_ENTITY_ALIAS);
830                                    }
831                                    else {
832                                            query.append(_ORDER_BY_ENTITY_TABLE);
833                                    }
834    
835                                    query.append(orderByFields[i]);
836    
837                                    if ((i + 1) < orderByFields.length) {
838                                            if (orderByComparator.isAscending() ^ previous) {
839                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
840                                            }
841                                            else {
842                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
843                                            }
844                                    }
845                                    else {
846                                            if (orderByComparator.isAscending() ^ previous) {
847                                                    query.append(ORDER_BY_ASC);
848                                            }
849                                            else {
850                                                    query.append(ORDER_BY_DESC);
851                                            }
852                                    }
853                            }
854                    }
855                    else {
856                            if (getDB().isSupportsInlineDistinct()) {
857                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
858                            }
859                            else {
860                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_SQL);
861                            }
862                    }
863    
864                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
865                                    LayoutSetPrototype.class.getName(),
866                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
867    
868                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
869    
870                    q.setFirstResult(0);
871                    q.setMaxResults(2);
872    
873                    if (getDB().isSupportsInlineDistinct()) {
874                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetPrototypeImpl.class);
875                    }
876                    else {
877                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetPrototypeImpl.class);
878                    }
879    
880                    QueryPos qPos = QueryPos.getInstance(q);
881    
882                    if (bindUuid) {
883                            qPos.add(uuid);
884                    }
885    
886                    if (orderByComparator != null) {
887                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetPrototype);
888    
889                            for (Object value : values) {
890                                    qPos.add(value);
891                            }
892                    }
893    
894                    List<LayoutSetPrototype> list = q.list();
895    
896                    if (list.size() == 2) {
897                            return list.get(1);
898                    }
899                    else {
900                            return null;
901                    }
902            }
903    
904            /**
905             * Removes all the layout set prototypes where uuid = &#63; from the database.
906             *
907             * @param uuid the uuid
908             */
909            @Override
910            public void removeByUuid(String uuid) {
911                    for (LayoutSetPrototype layoutSetPrototype : findByUuid(uuid,
912                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
913                            remove(layoutSetPrototype);
914                    }
915            }
916    
917            /**
918             * Returns the number of layout set prototypes where uuid = &#63;.
919             *
920             * @param uuid the uuid
921             * @return the number of matching layout set prototypes
922             */
923            @Override
924            public int countByUuid(String uuid) {
925                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
926    
927                    Object[] finderArgs = new Object[] { uuid };
928    
929                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
930    
931                    if (count == null) {
932                            StringBundler query = new StringBundler(2);
933    
934                            query.append(_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
935    
936                            boolean bindUuid = false;
937    
938                            if (uuid == null) {
939                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
940                            }
941                            else if (uuid.equals(StringPool.BLANK)) {
942                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
943                            }
944                            else {
945                                    bindUuid = true;
946    
947                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
948                            }
949    
950                            String sql = query.toString();
951    
952                            Session session = null;
953    
954                            try {
955                                    session = openSession();
956    
957                                    Query q = session.createQuery(sql);
958    
959                                    QueryPos qPos = QueryPos.getInstance(q);
960    
961                                    if (bindUuid) {
962                                            qPos.add(uuid);
963                                    }
964    
965                                    count = (Long)q.uniqueResult();
966    
967                                    finderCache.putResult(finderPath, finderArgs, count);
968                            }
969                            catch (Exception e) {
970                                    finderCache.removeResult(finderPath, finderArgs);
971    
972                                    throw processException(e);
973                            }
974                            finally {
975                                    closeSession(session);
976                            }
977                    }
978    
979                    return count.intValue();
980            }
981    
982            /**
983             * Returns the number of layout set prototypes that the user has permission to view where uuid = &#63;.
984             *
985             * @param uuid the uuid
986             * @return the number of matching layout set prototypes that the user has permission to view
987             */
988            @Override
989            public int filterCountByUuid(String uuid) {
990                    if (!InlineSQLHelperUtil.isEnabled()) {
991                            return countByUuid(uuid);
992                    }
993    
994                    StringBundler query = new StringBundler(2);
995    
996                    query.append(_FILTER_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
997    
998                    boolean bindUuid = false;
999    
1000                    if (uuid == null) {
1001                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
1002                    }
1003                    else if (uuid.equals(StringPool.BLANK)) {
1004                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
1005                    }
1006                    else {
1007                            bindUuid = true;
1008    
1009                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
1010                    }
1011    
1012                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1013                                    LayoutSetPrototype.class.getName(),
1014                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1015    
1016                    Session session = null;
1017    
1018                    try {
1019                            session = openSession();
1020    
1021                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1022    
1023                            q.addScalar(COUNT_COLUMN_NAME,
1024                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1025    
1026                            QueryPos qPos = QueryPos.getInstance(q);
1027    
1028                            if (bindUuid) {
1029                                    qPos.add(uuid);
1030                            }
1031    
1032                            Long count = (Long)q.uniqueResult();
1033    
1034                            return count.intValue();
1035                    }
1036                    catch (Exception e) {
1037                            throw processException(e);
1038                    }
1039                    finally {
1040                            closeSession(session);
1041                    }
1042            }
1043    
1044            private static final String _FINDER_COLUMN_UUID_UUID_1 = "layoutSetPrototype.uuid IS NULL";
1045            private static final String _FINDER_COLUMN_UUID_UUID_2 = "layoutSetPrototype.uuid = ?";
1046            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(layoutSetPrototype.uuid IS NULL OR layoutSetPrototype.uuid = '')";
1047            private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "layoutSetPrototype.uuid_ IS NULL";
1048            private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "layoutSetPrototype.uuid_ = ?";
1049            private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(layoutSetPrototype.uuid_ IS NULL OR layoutSetPrototype.uuid_ = '')";
1050            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
1051                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
1052                            LayoutSetPrototypeImpl.class,
1053                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
1054                            new String[] {
1055                                    String.class.getName(), Long.class.getName(),
1056                                    
1057                            Integer.class.getName(), Integer.class.getName(),
1058                                    OrderByComparator.class.getName()
1059                            });
1060            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1061                    new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
1062                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
1063                            LayoutSetPrototypeImpl.class,
1064                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1065                            new String[] { String.class.getName(), Long.class.getName() },
1066                            LayoutSetPrototypeModelImpl.UUID_COLUMN_BITMASK |
1067                            LayoutSetPrototypeModelImpl.COMPANYID_COLUMN_BITMASK);
1068            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
1069                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
1070                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1071                            new String[] { String.class.getName(), Long.class.getName() });
1072    
1073            /**
1074             * Returns all the layout set prototypes where uuid = &#63; and companyId = &#63;.
1075             *
1076             * @param uuid the uuid
1077             * @param companyId the company ID
1078             * @return the matching layout set prototypes
1079             */
1080            @Override
1081            public List<LayoutSetPrototype> findByUuid_C(String uuid, long companyId) {
1082                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1083                            QueryUtil.ALL_POS, null);
1084            }
1085    
1086            /**
1087             * Returns a range of all the layout set prototypes where uuid = &#63; and companyId = &#63;.
1088             *
1089             * <p>
1090             * 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 LayoutSetPrototypeModelImpl}. 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.
1091             * </p>
1092             *
1093             * @param uuid the uuid
1094             * @param companyId the company ID
1095             * @param start the lower bound of the range of layout set prototypes
1096             * @param end the upper bound of the range of layout set prototypes (not inclusive)
1097             * @return the range of matching layout set prototypes
1098             */
1099            @Override
1100            public List<LayoutSetPrototype> findByUuid_C(String uuid, long companyId,
1101                    int start, int end) {
1102                    return findByUuid_C(uuid, companyId, start, end, null);
1103            }
1104    
1105            /**
1106             * Returns an ordered range of all the layout set prototypes where uuid = &#63; and companyId = &#63;.
1107             *
1108             * <p>
1109             * 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 LayoutSetPrototypeModelImpl}. 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.
1110             * </p>
1111             *
1112             * @param uuid the uuid
1113             * @param companyId the company ID
1114             * @param start the lower bound of the range of layout set prototypes
1115             * @param end the upper bound of the range of layout set prototypes (not inclusive)
1116             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1117             * @return the ordered range of matching layout set prototypes
1118             */
1119            @Override
1120            public List<LayoutSetPrototype> findByUuid_C(String uuid, long companyId,
1121                    int start, int end,
1122                    OrderByComparator<LayoutSetPrototype> orderByComparator) {
1123                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
1124            }
1125    
1126            /**
1127             * Returns an ordered range of all the layout set prototypes where uuid = &#63; and companyId = &#63;.
1128             *
1129             * <p>
1130             * 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 LayoutSetPrototypeModelImpl}. 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.
1131             * </p>
1132             *
1133             * @param uuid the uuid
1134             * @param companyId the company ID
1135             * @param start the lower bound of the range of layout set prototypes
1136             * @param end the upper bound of the range of layout set prototypes (not inclusive)
1137             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1138             * @param retrieveFromCache whether to retrieve from the finder cache
1139             * @return the ordered range of matching layout set prototypes
1140             */
1141            @Override
1142            public List<LayoutSetPrototype> findByUuid_C(String uuid, long companyId,
1143                    int start, int end,
1144                    OrderByComparator<LayoutSetPrototype> orderByComparator,
1145                    boolean retrieveFromCache) {
1146                    boolean pagination = true;
1147                    FinderPath finderPath = null;
1148                    Object[] finderArgs = null;
1149    
1150                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1151                                    (orderByComparator == null)) {
1152                            pagination = false;
1153                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1154                            finderArgs = new Object[] { uuid, companyId };
1155                    }
1156                    else {
1157                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1158                            finderArgs = new Object[] {
1159                                            uuid, companyId,
1160                                            
1161                                            start, end, orderByComparator
1162                                    };
1163                    }
1164    
1165                    List<LayoutSetPrototype> list = null;
1166    
1167                    if (retrieveFromCache) {
1168                            list = (List<LayoutSetPrototype>)finderCache.getResult(finderPath,
1169                                            finderArgs, this);
1170    
1171                            if ((list != null) && !list.isEmpty()) {
1172                                    for (LayoutSetPrototype layoutSetPrototype : list) {
1173                                            if (!Validator.equals(uuid, layoutSetPrototype.getUuid()) ||
1174                                                            (companyId != layoutSetPrototype.getCompanyId())) {
1175                                                    list = null;
1176    
1177                                                    break;
1178                                            }
1179                                    }
1180                            }
1181                    }
1182    
1183                    if (list == null) {
1184                            StringBundler query = null;
1185    
1186                            if (orderByComparator != null) {
1187                                    query = new StringBundler(4 +
1188                                                    (orderByComparator.getOrderByFields().length * 3));
1189                            }
1190                            else {
1191                                    query = new StringBundler(4);
1192                            }
1193    
1194                            query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
1195    
1196                            boolean bindUuid = false;
1197    
1198                            if (uuid == null) {
1199                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1200                            }
1201                            else if (uuid.equals(StringPool.BLANK)) {
1202                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1203                            }
1204                            else {
1205                                    bindUuid = true;
1206    
1207                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1208                            }
1209    
1210                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1211    
1212                            if (orderByComparator != null) {
1213                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1214                                            orderByComparator);
1215                            }
1216                            else
1217                             if (pagination) {
1218                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
1219                            }
1220    
1221                            String sql = query.toString();
1222    
1223                            Session session = null;
1224    
1225                            try {
1226                                    session = openSession();
1227    
1228                                    Query q = session.createQuery(sql);
1229    
1230                                    QueryPos qPos = QueryPos.getInstance(q);
1231    
1232                                    if (bindUuid) {
1233                                            qPos.add(uuid);
1234                                    }
1235    
1236                                    qPos.add(companyId);
1237    
1238                                    if (!pagination) {
1239                                            list = (List<LayoutSetPrototype>)QueryUtil.list(q,
1240                                                            getDialect(), start, end, false);
1241    
1242                                            Collections.sort(list);
1243    
1244                                            list = Collections.unmodifiableList(list);
1245                                    }
1246                                    else {
1247                                            list = (List<LayoutSetPrototype>)QueryUtil.list(q,
1248                                                            getDialect(), start, end);
1249                                    }
1250    
1251                                    cacheResult(list);
1252    
1253                                    finderCache.putResult(finderPath, finderArgs, list);
1254                            }
1255                            catch (Exception e) {
1256                                    finderCache.removeResult(finderPath, finderArgs);
1257    
1258                                    throw processException(e);
1259                            }
1260                            finally {
1261                                    closeSession(session);
1262                            }
1263                    }
1264    
1265                    return list;
1266            }
1267    
1268            /**
1269             * Returns the first layout set prototype in the ordered set where uuid = &#63; and companyId = &#63;.
1270             *
1271             * @param uuid the uuid
1272             * @param companyId the company ID
1273             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1274             * @return the first matching layout set prototype
1275             * @throws NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
1276             */
1277            @Override
1278            public LayoutSetPrototype findByUuid_C_First(String uuid, long companyId,
1279                    OrderByComparator<LayoutSetPrototype> orderByComparator)
1280                    throws NoSuchLayoutSetPrototypeException {
1281                    LayoutSetPrototype layoutSetPrototype = fetchByUuid_C_First(uuid,
1282                                    companyId, orderByComparator);
1283    
1284                    if (layoutSetPrototype != null) {
1285                            return layoutSetPrototype;
1286                    }
1287    
1288                    StringBundler msg = new StringBundler(6);
1289    
1290                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1291    
1292                    msg.append("uuid=");
1293                    msg.append(uuid);
1294    
1295                    msg.append(", companyId=");
1296                    msg.append(companyId);
1297    
1298                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1299    
1300                    throw new NoSuchLayoutSetPrototypeException(msg.toString());
1301            }
1302    
1303            /**
1304             * Returns the first layout set prototype in the ordered set where uuid = &#63; and companyId = &#63;.
1305             *
1306             * @param uuid the uuid
1307             * @param companyId the company ID
1308             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1309             * @return the first matching layout set prototype, or <code>null</code> if a matching layout set prototype could not be found
1310             */
1311            @Override
1312            public LayoutSetPrototype fetchByUuid_C_First(String uuid, long companyId,
1313                    OrderByComparator<LayoutSetPrototype> orderByComparator) {
1314                    List<LayoutSetPrototype> list = findByUuid_C(uuid, companyId, 0, 1,
1315                                    orderByComparator);
1316    
1317                    if (!list.isEmpty()) {
1318                            return list.get(0);
1319                    }
1320    
1321                    return null;
1322            }
1323    
1324            /**
1325             * Returns the last layout set prototype in the ordered set where uuid = &#63; and companyId = &#63;.
1326             *
1327             * @param uuid the uuid
1328             * @param companyId the company ID
1329             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1330             * @return the last matching layout set prototype
1331             * @throws NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
1332             */
1333            @Override
1334            public LayoutSetPrototype findByUuid_C_Last(String uuid, long companyId,
1335                    OrderByComparator<LayoutSetPrototype> orderByComparator)
1336                    throws NoSuchLayoutSetPrototypeException {
1337                    LayoutSetPrototype layoutSetPrototype = fetchByUuid_C_Last(uuid,
1338                                    companyId, orderByComparator);
1339    
1340                    if (layoutSetPrototype != null) {
1341                            return layoutSetPrototype;
1342                    }
1343    
1344                    StringBundler msg = new StringBundler(6);
1345    
1346                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1347    
1348                    msg.append("uuid=");
1349                    msg.append(uuid);
1350    
1351                    msg.append(", companyId=");
1352                    msg.append(companyId);
1353    
1354                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1355    
1356                    throw new NoSuchLayoutSetPrototypeException(msg.toString());
1357            }
1358    
1359            /**
1360             * Returns the last layout set prototype in the ordered set where uuid = &#63; and companyId = &#63;.
1361             *
1362             * @param uuid the uuid
1363             * @param companyId the company ID
1364             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1365             * @return the last matching layout set prototype, or <code>null</code> if a matching layout set prototype could not be found
1366             */
1367            @Override
1368            public LayoutSetPrototype fetchByUuid_C_Last(String uuid, long companyId,
1369                    OrderByComparator<LayoutSetPrototype> orderByComparator) {
1370                    int count = countByUuid_C(uuid, companyId);
1371    
1372                    if (count == 0) {
1373                            return null;
1374                    }
1375    
1376                    List<LayoutSetPrototype> list = findByUuid_C(uuid, companyId,
1377                                    count - 1, count, orderByComparator);
1378    
1379                    if (!list.isEmpty()) {
1380                            return list.get(0);
1381                    }
1382    
1383                    return null;
1384            }
1385    
1386            /**
1387             * Returns the layout set prototypes before and after the current layout set prototype in the ordered set where uuid = &#63; and companyId = &#63;.
1388             *
1389             * @param layoutSetPrototypeId the primary key of the current layout set prototype
1390             * @param uuid the uuid
1391             * @param companyId the company ID
1392             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1393             * @return the previous, current, and next layout set prototype
1394             * @throws NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
1395             */
1396            @Override
1397            public LayoutSetPrototype[] findByUuid_C_PrevAndNext(
1398                    long layoutSetPrototypeId, String uuid, long companyId,
1399                    OrderByComparator<LayoutSetPrototype> orderByComparator)
1400                    throws NoSuchLayoutSetPrototypeException {
1401                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
1402    
1403                    Session session = null;
1404    
1405                    try {
1406                            session = openSession();
1407    
1408                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
1409    
1410                            array[0] = getByUuid_C_PrevAndNext(session, layoutSetPrototype,
1411                                            uuid, companyId, orderByComparator, true);
1412    
1413                            array[1] = layoutSetPrototype;
1414    
1415                            array[2] = getByUuid_C_PrevAndNext(session, layoutSetPrototype,
1416                                            uuid, companyId, orderByComparator, false);
1417    
1418                            return array;
1419                    }
1420                    catch (Exception e) {
1421                            throw processException(e);
1422                    }
1423                    finally {
1424                            closeSession(session);
1425                    }
1426            }
1427    
1428            protected LayoutSetPrototype getByUuid_C_PrevAndNext(Session session,
1429                    LayoutSetPrototype layoutSetPrototype, String uuid, long companyId,
1430                    OrderByComparator<LayoutSetPrototype> orderByComparator,
1431                    boolean previous) {
1432                    StringBundler query = null;
1433    
1434                    if (orderByComparator != null) {
1435                            query = new StringBundler(6 +
1436                                            (orderByComparator.getOrderByFields().length * 6));
1437                    }
1438                    else {
1439                            query = new StringBundler(3);
1440                    }
1441    
1442                    query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
1443    
1444                    boolean bindUuid = false;
1445    
1446                    if (uuid == null) {
1447                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1448                    }
1449                    else if (uuid.equals(StringPool.BLANK)) {
1450                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1451                    }
1452                    else {
1453                            bindUuid = true;
1454    
1455                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1456                    }
1457    
1458                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1459    
1460                    if (orderByComparator != null) {
1461                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1462    
1463                            if (orderByConditionFields.length > 0) {
1464                                    query.append(WHERE_AND);
1465                            }
1466    
1467                            for (int i = 0; i < orderByConditionFields.length; i++) {
1468                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1469                                    query.append(orderByConditionFields[i]);
1470    
1471                                    if ((i + 1) < orderByConditionFields.length) {
1472                                            if (orderByComparator.isAscending() ^ previous) {
1473                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1474                                            }
1475                                            else {
1476                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1477                                            }
1478                                    }
1479                                    else {
1480                                            if (orderByComparator.isAscending() ^ previous) {
1481                                                    query.append(WHERE_GREATER_THAN);
1482                                            }
1483                                            else {
1484                                                    query.append(WHERE_LESSER_THAN);
1485                                            }
1486                                    }
1487                            }
1488    
1489                            query.append(ORDER_BY_CLAUSE);
1490    
1491                            String[] orderByFields = orderByComparator.getOrderByFields();
1492    
1493                            for (int i = 0; i < orderByFields.length; i++) {
1494                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1495                                    query.append(orderByFields[i]);
1496    
1497                                    if ((i + 1) < orderByFields.length) {
1498                                            if (orderByComparator.isAscending() ^ previous) {
1499                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1500                                            }
1501                                            else {
1502                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1503                                            }
1504                                    }
1505                                    else {
1506                                            if (orderByComparator.isAscending() ^ previous) {
1507                                                    query.append(ORDER_BY_ASC);
1508                                            }
1509                                            else {
1510                                                    query.append(ORDER_BY_DESC);
1511                                            }
1512                                    }
1513                            }
1514                    }
1515                    else {
1516                            query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
1517                    }
1518    
1519                    String sql = query.toString();
1520    
1521                    Query q = session.createQuery(sql);
1522    
1523                    q.setFirstResult(0);
1524                    q.setMaxResults(2);
1525    
1526                    QueryPos qPos = QueryPos.getInstance(q);
1527    
1528                    if (bindUuid) {
1529                            qPos.add(uuid);
1530                    }
1531    
1532                    qPos.add(companyId);
1533    
1534                    if (orderByComparator != null) {
1535                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetPrototype);
1536    
1537                            for (Object value : values) {
1538                                    qPos.add(value);
1539                            }
1540                    }
1541    
1542                    List<LayoutSetPrototype> list = q.list();
1543    
1544                    if (list.size() == 2) {
1545                            return list.get(1);
1546                    }
1547                    else {
1548                            return null;
1549                    }
1550            }
1551    
1552            /**
1553             * Returns all the layout set prototypes that the user has permission to view where uuid = &#63; and companyId = &#63;.
1554             *
1555             * @param uuid the uuid
1556             * @param companyId the company ID
1557             * @return the matching layout set prototypes that the user has permission to view
1558             */
1559            @Override
1560            public List<LayoutSetPrototype> filterFindByUuid_C(String uuid,
1561                    long companyId) {
1562                    return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1563                            QueryUtil.ALL_POS, null);
1564            }
1565    
1566            /**
1567             * Returns a range of all the layout set prototypes that the user has permission to view where uuid = &#63; and companyId = &#63;.
1568             *
1569             * <p>
1570             * 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 LayoutSetPrototypeModelImpl}. 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.
1571             * </p>
1572             *
1573             * @param uuid the uuid
1574             * @param companyId the company ID
1575             * @param start the lower bound of the range of layout set prototypes
1576             * @param end the upper bound of the range of layout set prototypes (not inclusive)
1577             * @return the range of matching layout set prototypes that the user has permission to view
1578             */
1579            @Override
1580            public List<LayoutSetPrototype> filterFindByUuid_C(String uuid,
1581                    long companyId, int start, int end) {
1582                    return filterFindByUuid_C(uuid, companyId, start, end, null);
1583            }
1584    
1585            /**
1586             * Returns an ordered range of all the layout set prototypes that the user has permissions to view where uuid = &#63; and companyId = &#63;.
1587             *
1588             * <p>
1589             * 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 LayoutSetPrototypeModelImpl}. 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.
1590             * </p>
1591             *
1592             * @param uuid the uuid
1593             * @param companyId the company ID
1594             * @param start the lower bound of the range of layout set prototypes
1595             * @param end the upper bound of the range of layout set prototypes (not inclusive)
1596             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1597             * @return the ordered range of matching layout set prototypes that the user has permission to view
1598             */
1599            @Override
1600            public List<LayoutSetPrototype> filterFindByUuid_C(String uuid,
1601                    long companyId, int start, int end,
1602                    OrderByComparator<LayoutSetPrototype> orderByComparator) {
1603                    if (!InlineSQLHelperUtil.isEnabled()) {
1604                            return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1605                    }
1606    
1607                    StringBundler query = null;
1608    
1609                    if (orderByComparator != null) {
1610                            query = new StringBundler(4 +
1611                                            (orderByComparator.getOrderByFields().length * 3));
1612                    }
1613                    else {
1614                            query = new StringBundler(4);
1615                    }
1616    
1617                    if (getDB().isSupportsInlineDistinct()) {
1618                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
1619                    }
1620                    else {
1621                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
1622                    }
1623    
1624                    boolean bindUuid = false;
1625    
1626                    if (uuid == null) {
1627                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1628                    }
1629                    else if (uuid.equals(StringPool.BLANK)) {
1630                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1631                    }
1632                    else {
1633                            bindUuid = true;
1634    
1635                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1636                    }
1637    
1638                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1639    
1640                    if (!getDB().isSupportsInlineDistinct()) {
1641                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
1642                    }
1643    
1644                    if (orderByComparator != null) {
1645                            if (getDB().isSupportsInlineDistinct()) {
1646                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1647                                            orderByComparator, true);
1648                            }
1649                            else {
1650                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1651                                            orderByComparator, true);
1652                            }
1653                    }
1654                    else {
1655                            if (getDB().isSupportsInlineDistinct()) {
1656                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
1657                            }
1658                            else {
1659                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_SQL);
1660                            }
1661                    }
1662    
1663                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1664                                    LayoutSetPrototype.class.getName(),
1665                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1666    
1667                    Session session = null;
1668    
1669                    try {
1670                            session = openSession();
1671    
1672                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1673    
1674                            if (getDB().isSupportsInlineDistinct()) {
1675                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetPrototypeImpl.class);
1676                            }
1677                            else {
1678                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetPrototypeImpl.class);
1679                            }
1680    
1681                            QueryPos qPos = QueryPos.getInstance(q);
1682    
1683                            if (bindUuid) {
1684                                    qPos.add(uuid);
1685                            }
1686    
1687                            qPos.add(companyId);
1688    
1689                            return (List<LayoutSetPrototype>)QueryUtil.list(q, getDialect(),
1690                                    start, end);
1691                    }
1692                    catch (Exception e) {
1693                            throw processException(e);
1694                    }
1695                    finally {
1696                            closeSession(session);
1697                    }
1698            }
1699    
1700            /**
1701             * Returns the layout set prototypes before and after the current layout set prototype in the ordered set of layout set prototypes that the user has permission to view where uuid = &#63; and companyId = &#63;.
1702             *
1703             * @param layoutSetPrototypeId the primary key of the current layout set prototype
1704             * @param uuid the uuid
1705             * @param companyId the company ID
1706             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1707             * @return the previous, current, and next layout set prototype
1708             * @throws NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
1709             */
1710            @Override
1711            public LayoutSetPrototype[] filterFindByUuid_C_PrevAndNext(
1712                    long layoutSetPrototypeId, String uuid, long companyId,
1713                    OrderByComparator<LayoutSetPrototype> orderByComparator)
1714                    throws NoSuchLayoutSetPrototypeException {
1715                    if (!InlineSQLHelperUtil.isEnabled()) {
1716                            return findByUuid_C_PrevAndNext(layoutSetPrototypeId, uuid,
1717                                    companyId, orderByComparator);
1718                    }
1719    
1720                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
1721    
1722                    Session session = null;
1723    
1724                    try {
1725                            session = openSession();
1726    
1727                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
1728    
1729                            array[0] = filterGetByUuid_C_PrevAndNext(session,
1730                                            layoutSetPrototype, uuid, companyId, orderByComparator, true);
1731    
1732                            array[1] = layoutSetPrototype;
1733    
1734                            array[2] = filterGetByUuid_C_PrevAndNext(session,
1735                                            layoutSetPrototype, uuid, companyId, orderByComparator,
1736                                            false);
1737    
1738                            return array;
1739                    }
1740                    catch (Exception e) {
1741                            throw processException(e);
1742                    }
1743                    finally {
1744                            closeSession(session);
1745                    }
1746            }
1747    
1748            protected LayoutSetPrototype filterGetByUuid_C_PrevAndNext(
1749                    Session session, LayoutSetPrototype layoutSetPrototype, String uuid,
1750                    long companyId,
1751                    OrderByComparator<LayoutSetPrototype> orderByComparator,
1752                    boolean previous) {
1753                    StringBundler query = null;
1754    
1755                    if (orderByComparator != null) {
1756                            query = new StringBundler(6 +
1757                                            (orderByComparator.getOrderByFields().length * 6));
1758                    }
1759                    else {
1760                            query = new StringBundler(3);
1761                    }
1762    
1763                    if (getDB().isSupportsInlineDistinct()) {
1764                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
1765                    }
1766                    else {
1767                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
1768                    }
1769    
1770                    boolean bindUuid = false;
1771    
1772                    if (uuid == null) {
1773                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1774                    }
1775                    else if (uuid.equals(StringPool.BLANK)) {
1776                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1777                    }
1778                    else {
1779                            bindUuid = true;
1780    
1781                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1782                    }
1783    
1784                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1785    
1786                    if (!getDB().isSupportsInlineDistinct()) {
1787                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
1788                    }
1789    
1790                    if (orderByComparator != null) {
1791                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1792    
1793                            if (orderByConditionFields.length > 0) {
1794                                    query.append(WHERE_AND);
1795                            }
1796    
1797                            for (int i = 0; i < orderByConditionFields.length; i++) {
1798                                    if (getDB().isSupportsInlineDistinct()) {
1799                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1800                                    }
1801                                    else {
1802                                            query.append(_ORDER_BY_ENTITY_TABLE);
1803                                    }
1804    
1805                                    query.append(orderByConditionFields[i]);
1806    
1807                                    if ((i + 1) < orderByConditionFields.length) {
1808                                            if (orderByComparator.isAscending() ^ previous) {
1809                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1810                                            }
1811                                            else {
1812                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1813                                            }
1814                                    }
1815                                    else {
1816                                            if (orderByComparator.isAscending() ^ previous) {
1817                                                    query.append(WHERE_GREATER_THAN);
1818                                            }
1819                                            else {
1820                                                    query.append(WHERE_LESSER_THAN);
1821                                            }
1822                                    }
1823                            }
1824    
1825                            query.append(ORDER_BY_CLAUSE);
1826    
1827                            String[] orderByFields = orderByComparator.getOrderByFields();
1828    
1829                            for (int i = 0; i < orderByFields.length; i++) {
1830                                    if (getDB().isSupportsInlineDistinct()) {
1831                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1832                                    }
1833                                    else {
1834                                            query.append(_ORDER_BY_ENTITY_TABLE);
1835                                    }
1836    
1837                                    query.append(orderByFields[i]);
1838    
1839                                    if ((i + 1) < orderByFields.length) {
1840                                            if (orderByComparator.isAscending() ^ previous) {
1841                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1842                                            }
1843                                            else {
1844                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1845                                            }
1846                                    }
1847                                    else {
1848                                            if (orderByComparator.isAscending() ^ previous) {
1849                                                    query.append(ORDER_BY_ASC);
1850                                            }
1851                                            else {
1852                                                    query.append(ORDER_BY_DESC);
1853                                            }
1854                                    }
1855                            }
1856                    }
1857                    else {
1858                            if (getDB().isSupportsInlineDistinct()) {
1859                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
1860                            }
1861                            else {
1862                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_SQL);
1863                            }
1864                    }
1865    
1866                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1867                                    LayoutSetPrototype.class.getName(),
1868                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1869    
1870                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
1871    
1872                    q.setFirstResult(0);
1873                    q.setMaxResults(2);
1874    
1875                    if (getDB().isSupportsInlineDistinct()) {
1876                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetPrototypeImpl.class);
1877                    }
1878                    else {
1879                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetPrototypeImpl.class);
1880                    }
1881    
1882                    QueryPos qPos = QueryPos.getInstance(q);
1883    
1884                    if (bindUuid) {
1885                            qPos.add(uuid);
1886                    }
1887    
1888                    qPos.add(companyId);
1889    
1890                    if (orderByComparator != null) {
1891                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetPrototype);
1892    
1893                            for (Object value : values) {
1894                                    qPos.add(value);
1895                            }
1896                    }
1897    
1898                    List<LayoutSetPrototype> list = q.list();
1899    
1900                    if (list.size() == 2) {
1901                            return list.get(1);
1902                    }
1903                    else {
1904                            return null;
1905                    }
1906            }
1907    
1908            /**
1909             * Removes all the layout set prototypes where uuid = &#63; and companyId = &#63; from the database.
1910             *
1911             * @param uuid the uuid
1912             * @param companyId the company ID
1913             */
1914            @Override
1915            public void removeByUuid_C(String uuid, long companyId) {
1916                    for (LayoutSetPrototype layoutSetPrototype : findByUuid_C(uuid,
1917                                    companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1918                            remove(layoutSetPrototype);
1919                    }
1920            }
1921    
1922            /**
1923             * Returns the number of layout set prototypes where uuid = &#63; and companyId = &#63;.
1924             *
1925             * @param uuid the uuid
1926             * @param companyId the company ID
1927             * @return the number of matching layout set prototypes
1928             */
1929            @Override
1930            public int countByUuid_C(String uuid, long companyId) {
1931                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1932    
1933                    Object[] finderArgs = new Object[] { uuid, companyId };
1934    
1935                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1936    
1937                    if (count == null) {
1938                            StringBundler query = new StringBundler(3);
1939    
1940                            query.append(_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
1941    
1942                            boolean bindUuid = false;
1943    
1944                            if (uuid == null) {
1945                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1946                            }
1947                            else if (uuid.equals(StringPool.BLANK)) {
1948                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1949                            }
1950                            else {
1951                                    bindUuid = true;
1952    
1953                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1954                            }
1955    
1956                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1957    
1958                            String sql = query.toString();
1959    
1960                            Session session = null;
1961    
1962                            try {
1963                                    session = openSession();
1964    
1965                                    Query q = session.createQuery(sql);
1966    
1967                                    QueryPos qPos = QueryPos.getInstance(q);
1968    
1969                                    if (bindUuid) {
1970                                            qPos.add(uuid);
1971                                    }
1972    
1973                                    qPos.add(companyId);
1974    
1975                                    count = (Long)q.uniqueResult();
1976    
1977                                    finderCache.putResult(finderPath, finderArgs, count);
1978                            }
1979                            catch (Exception e) {
1980                                    finderCache.removeResult(finderPath, finderArgs);
1981    
1982                                    throw processException(e);
1983                            }
1984                            finally {
1985                                    closeSession(session);
1986                            }
1987                    }
1988    
1989                    return count.intValue();
1990            }
1991    
1992            /**
1993             * Returns the number of layout set prototypes that the user has permission to view where uuid = &#63; and companyId = &#63;.
1994             *
1995             * @param uuid the uuid
1996             * @param companyId the company ID
1997             * @return the number of matching layout set prototypes that the user has permission to view
1998             */
1999            @Override
2000            public int filterCountByUuid_C(String uuid, long companyId) {
2001                    if (!InlineSQLHelperUtil.isEnabled()) {
2002                            return countByUuid_C(uuid, companyId);
2003                    }
2004    
2005                    StringBundler query = new StringBundler(3);
2006    
2007                    query.append(_FILTER_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
2008    
2009                    boolean bindUuid = false;
2010    
2011                    if (uuid == null) {
2012                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
2013                    }
2014                    else if (uuid.equals(StringPool.BLANK)) {
2015                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
2016                    }
2017                    else {
2018                            bindUuid = true;
2019    
2020                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
2021                    }
2022    
2023                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
2024    
2025                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2026                                    LayoutSetPrototype.class.getName(),
2027                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2028    
2029                    Session session = null;
2030    
2031                    try {
2032                            session = openSession();
2033    
2034                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2035    
2036                            q.addScalar(COUNT_COLUMN_NAME,
2037                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2038    
2039                            QueryPos qPos = QueryPos.getInstance(q);
2040    
2041                            if (bindUuid) {
2042                                    qPos.add(uuid);
2043                            }
2044    
2045                            qPos.add(companyId);
2046    
2047                            Long count = (Long)q.uniqueResult();
2048    
2049                            return count.intValue();
2050                    }
2051                    catch (Exception e) {
2052                            throw processException(e);
2053                    }
2054                    finally {
2055                            closeSession(session);
2056                    }
2057            }
2058    
2059            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "layoutSetPrototype.uuid IS NULL AND ";
2060            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "layoutSetPrototype.uuid = ? AND ";
2061            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(layoutSetPrototype.uuid IS NULL OR layoutSetPrototype.uuid = '') AND ";
2062            private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "layoutSetPrototype.uuid_ IS NULL AND ";
2063            private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "layoutSetPrototype.uuid_ = ? AND ";
2064            private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(layoutSetPrototype.uuid_ IS NULL OR layoutSetPrototype.uuid_ = '') AND ";
2065            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "layoutSetPrototype.companyId = ?";
2066            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2067                    new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
2068                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
2069                            LayoutSetPrototypeImpl.class,
2070                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2071                            new String[] {
2072                                    Long.class.getName(),
2073                                    
2074                            Integer.class.getName(), Integer.class.getName(),
2075                                    OrderByComparator.class.getName()
2076                            });
2077            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2078                    new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
2079                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
2080                            LayoutSetPrototypeImpl.class,
2081                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2082                            new String[] { Long.class.getName() },
2083                            LayoutSetPrototypeModelImpl.COMPANYID_COLUMN_BITMASK);
2084            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
2085                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
2086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2087                            new String[] { Long.class.getName() });
2088    
2089            /**
2090             * Returns all the layout set prototypes where companyId = &#63;.
2091             *
2092             * @param companyId the company ID
2093             * @return the matching layout set prototypes
2094             */
2095            @Override
2096            public List<LayoutSetPrototype> findByCompanyId(long companyId) {
2097                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2098                            null);
2099            }
2100    
2101            /**
2102             * Returns a range of all the layout set prototypes where companyId = &#63;.
2103             *
2104             * <p>
2105             * 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 LayoutSetPrototypeModelImpl}. 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.
2106             * </p>
2107             *
2108             * @param companyId the company ID
2109             * @param start the lower bound of the range of layout set prototypes
2110             * @param end the upper bound of the range of layout set prototypes (not inclusive)
2111             * @return the range of matching layout set prototypes
2112             */
2113            @Override
2114            public List<LayoutSetPrototype> findByCompanyId(long companyId, int start,
2115                    int end) {
2116                    return findByCompanyId(companyId, start, end, null);
2117            }
2118    
2119            /**
2120             * Returns an ordered range of all the layout set prototypes where companyId = &#63;.
2121             *
2122             * <p>
2123             * 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 LayoutSetPrototypeModelImpl}. 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.
2124             * </p>
2125             *
2126             * @param companyId the company ID
2127             * @param start the lower bound of the range of layout set prototypes
2128             * @param end the upper bound of the range of layout set prototypes (not inclusive)
2129             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2130             * @return the ordered range of matching layout set prototypes
2131             */
2132            @Override
2133            public List<LayoutSetPrototype> findByCompanyId(long companyId, int start,
2134                    int end, OrderByComparator<LayoutSetPrototype> orderByComparator) {
2135                    return findByCompanyId(companyId, start, end, orderByComparator, true);
2136            }
2137    
2138            /**
2139             * Returns an ordered range of all the layout set prototypes where companyId = &#63;.
2140             *
2141             * <p>
2142             * 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 LayoutSetPrototypeModelImpl}. 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.
2143             * </p>
2144             *
2145             * @param companyId the company ID
2146             * @param start the lower bound of the range of layout set prototypes
2147             * @param end the upper bound of the range of layout set prototypes (not inclusive)
2148             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2149             * @param retrieveFromCache whether to retrieve from the finder cache
2150             * @return the ordered range of matching layout set prototypes
2151             */
2152            @Override
2153            public List<LayoutSetPrototype> findByCompanyId(long companyId, int start,
2154                    int end, OrderByComparator<LayoutSetPrototype> orderByComparator,
2155                    boolean retrieveFromCache) {
2156                    boolean pagination = true;
2157                    FinderPath finderPath = null;
2158                    Object[] finderArgs = null;
2159    
2160                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2161                                    (orderByComparator == null)) {
2162                            pagination = false;
2163                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2164                            finderArgs = new Object[] { companyId };
2165                    }
2166                    else {
2167                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2168                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2169                    }
2170    
2171                    List<LayoutSetPrototype> list = null;
2172    
2173                    if (retrieveFromCache) {
2174                            list = (List<LayoutSetPrototype>)finderCache.getResult(finderPath,
2175                                            finderArgs, this);
2176    
2177                            if ((list != null) && !list.isEmpty()) {
2178                                    for (LayoutSetPrototype layoutSetPrototype : list) {
2179                                            if ((companyId != layoutSetPrototype.getCompanyId())) {
2180                                                    list = null;
2181    
2182                                                    break;
2183                                            }
2184                                    }
2185                            }
2186                    }
2187    
2188                    if (list == null) {
2189                            StringBundler query = null;
2190    
2191                            if (orderByComparator != null) {
2192                                    query = new StringBundler(3 +
2193                                                    (orderByComparator.getOrderByFields().length * 3));
2194                            }
2195                            else {
2196                                    query = new StringBundler(3);
2197                            }
2198    
2199                            query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
2200    
2201                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2202    
2203                            if (orderByComparator != null) {
2204                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2205                                            orderByComparator);
2206                            }
2207                            else
2208                             if (pagination) {
2209                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
2210                            }
2211    
2212                            String sql = query.toString();
2213    
2214                            Session session = null;
2215    
2216                            try {
2217                                    session = openSession();
2218    
2219                                    Query q = session.createQuery(sql);
2220    
2221                                    QueryPos qPos = QueryPos.getInstance(q);
2222    
2223                                    qPos.add(companyId);
2224    
2225                                    if (!pagination) {
2226                                            list = (List<LayoutSetPrototype>)QueryUtil.list(q,
2227                                                            getDialect(), start, end, false);
2228    
2229                                            Collections.sort(list);
2230    
2231                                            list = Collections.unmodifiableList(list);
2232                                    }
2233                                    else {
2234                                            list = (List<LayoutSetPrototype>)QueryUtil.list(q,
2235                                                            getDialect(), start, end);
2236                                    }
2237    
2238                                    cacheResult(list);
2239    
2240                                    finderCache.putResult(finderPath, finderArgs, list);
2241                            }
2242                            catch (Exception e) {
2243                                    finderCache.removeResult(finderPath, finderArgs);
2244    
2245                                    throw processException(e);
2246                            }
2247                            finally {
2248                                    closeSession(session);
2249                            }
2250                    }
2251    
2252                    return list;
2253            }
2254    
2255            /**
2256             * Returns the first layout set prototype in the ordered set where companyId = &#63;.
2257             *
2258             * @param companyId the company ID
2259             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2260             * @return the first matching layout set prototype
2261             * @throws NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
2262             */
2263            @Override
2264            public LayoutSetPrototype findByCompanyId_First(long companyId,
2265                    OrderByComparator<LayoutSetPrototype> orderByComparator)
2266                    throws NoSuchLayoutSetPrototypeException {
2267                    LayoutSetPrototype layoutSetPrototype = fetchByCompanyId_First(companyId,
2268                                    orderByComparator);
2269    
2270                    if (layoutSetPrototype != null) {
2271                            return layoutSetPrototype;
2272                    }
2273    
2274                    StringBundler msg = new StringBundler(4);
2275    
2276                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2277    
2278                    msg.append("companyId=");
2279                    msg.append(companyId);
2280    
2281                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2282    
2283                    throw new NoSuchLayoutSetPrototypeException(msg.toString());
2284            }
2285    
2286            /**
2287             * Returns the first layout set prototype in the ordered set where companyId = &#63;.
2288             *
2289             * @param companyId the company ID
2290             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2291             * @return the first matching layout set prototype, or <code>null</code> if a matching layout set prototype could not be found
2292             */
2293            @Override
2294            public LayoutSetPrototype fetchByCompanyId_First(long companyId,
2295                    OrderByComparator<LayoutSetPrototype> orderByComparator) {
2296                    List<LayoutSetPrototype> list = findByCompanyId(companyId, 0, 1,
2297                                    orderByComparator);
2298    
2299                    if (!list.isEmpty()) {
2300                            return list.get(0);
2301                    }
2302    
2303                    return null;
2304            }
2305    
2306            /**
2307             * Returns the last layout set prototype in the ordered set where companyId = &#63;.
2308             *
2309             * @param companyId the company ID
2310             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2311             * @return the last matching layout set prototype
2312             * @throws NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
2313             */
2314            @Override
2315            public LayoutSetPrototype findByCompanyId_Last(long companyId,
2316                    OrderByComparator<LayoutSetPrototype> orderByComparator)
2317                    throws NoSuchLayoutSetPrototypeException {
2318                    LayoutSetPrototype layoutSetPrototype = fetchByCompanyId_Last(companyId,
2319                                    orderByComparator);
2320    
2321                    if (layoutSetPrototype != null) {
2322                            return layoutSetPrototype;
2323                    }
2324    
2325                    StringBundler msg = new StringBundler(4);
2326    
2327                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2328    
2329                    msg.append("companyId=");
2330                    msg.append(companyId);
2331    
2332                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2333    
2334                    throw new NoSuchLayoutSetPrototypeException(msg.toString());
2335            }
2336    
2337            /**
2338             * Returns the last layout set prototype in the ordered set where companyId = &#63;.
2339             *
2340             * @param companyId the company ID
2341             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2342             * @return the last matching layout set prototype, or <code>null</code> if a matching layout set prototype could not be found
2343             */
2344            @Override
2345            public LayoutSetPrototype fetchByCompanyId_Last(long companyId,
2346                    OrderByComparator<LayoutSetPrototype> orderByComparator) {
2347                    int count = countByCompanyId(companyId);
2348    
2349                    if (count == 0) {
2350                            return null;
2351                    }
2352    
2353                    List<LayoutSetPrototype> list = findByCompanyId(companyId, count - 1,
2354                                    count, orderByComparator);
2355    
2356                    if (!list.isEmpty()) {
2357                            return list.get(0);
2358                    }
2359    
2360                    return null;
2361            }
2362    
2363            /**
2364             * Returns the layout set prototypes before and after the current layout set prototype in the ordered set where companyId = &#63;.
2365             *
2366             * @param layoutSetPrototypeId the primary key of the current layout set prototype
2367             * @param companyId the company ID
2368             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2369             * @return the previous, current, and next layout set prototype
2370             * @throws NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
2371             */
2372            @Override
2373            public LayoutSetPrototype[] findByCompanyId_PrevAndNext(
2374                    long layoutSetPrototypeId, long companyId,
2375                    OrderByComparator<LayoutSetPrototype> orderByComparator)
2376                    throws NoSuchLayoutSetPrototypeException {
2377                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
2378    
2379                    Session session = null;
2380    
2381                    try {
2382                            session = openSession();
2383    
2384                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
2385    
2386                            array[0] = getByCompanyId_PrevAndNext(session, layoutSetPrototype,
2387                                            companyId, orderByComparator, true);
2388    
2389                            array[1] = layoutSetPrototype;
2390    
2391                            array[2] = getByCompanyId_PrevAndNext(session, layoutSetPrototype,
2392                                            companyId, orderByComparator, false);
2393    
2394                            return array;
2395                    }
2396                    catch (Exception e) {
2397                            throw processException(e);
2398                    }
2399                    finally {
2400                            closeSession(session);
2401                    }
2402            }
2403    
2404            protected LayoutSetPrototype getByCompanyId_PrevAndNext(Session session,
2405                    LayoutSetPrototype layoutSetPrototype, long companyId,
2406                    OrderByComparator<LayoutSetPrototype> orderByComparator,
2407                    boolean previous) {
2408                    StringBundler query = null;
2409    
2410                    if (orderByComparator != null) {
2411                            query = new StringBundler(6 +
2412                                            (orderByComparator.getOrderByFields().length * 6));
2413                    }
2414                    else {
2415                            query = new StringBundler(3);
2416                    }
2417    
2418                    query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
2419    
2420                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2421    
2422                    if (orderByComparator != null) {
2423                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2424    
2425                            if (orderByConditionFields.length > 0) {
2426                                    query.append(WHERE_AND);
2427                            }
2428    
2429                            for (int i = 0; i < orderByConditionFields.length; i++) {
2430                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2431                                    query.append(orderByConditionFields[i]);
2432    
2433                                    if ((i + 1) < orderByConditionFields.length) {
2434                                            if (orderByComparator.isAscending() ^ previous) {
2435                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2436                                            }
2437                                            else {
2438                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2439                                            }
2440                                    }
2441                                    else {
2442                                            if (orderByComparator.isAscending() ^ previous) {
2443                                                    query.append(WHERE_GREATER_THAN);
2444                                            }
2445                                            else {
2446                                                    query.append(WHERE_LESSER_THAN);
2447                                            }
2448                                    }
2449                            }
2450    
2451                            query.append(ORDER_BY_CLAUSE);
2452    
2453                            String[] orderByFields = orderByComparator.getOrderByFields();
2454    
2455                            for (int i = 0; i < orderByFields.length; i++) {
2456                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2457                                    query.append(orderByFields[i]);
2458    
2459                                    if ((i + 1) < orderByFields.length) {
2460                                            if (orderByComparator.isAscending() ^ previous) {
2461                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2462                                            }
2463                                            else {
2464                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2465                                            }
2466                                    }
2467                                    else {
2468                                            if (orderByComparator.isAscending() ^ previous) {
2469                                                    query.append(ORDER_BY_ASC);
2470                                            }
2471                                            else {
2472                                                    query.append(ORDER_BY_DESC);
2473                                            }
2474                                    }
2475                            }
2476                    }
2477                    else {
2478                            query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
2479                    }
2480    
2481                    String sql = query.toString();
2482    
2483                    Query q = session.createQuery(sql);
2484    
2485                    q.setFirstResult(0);
2486                    q.setMaxResults(2);
2487    
2488                    QueryPos qPos = QueryPos.getInstance(q);
2489    
2490                    qPos.add(companyId);
2491    
2492                    if (orderByComparator != null) {
2493                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetPrototype);
2494    
2495                            for (Object value : values) {
2496                                    qPos.add(value);
2497                            }
2498                    }
2499    
2500                    List<LayoutSetPrototype> list = q.list();
2501    
2502                    if (list.size() == 2) {
2503                            return list.get(1);
2504                    }
2505                    else {
2506                            return null;
2507                    }
2508            }
2509    
2510            /**
2511             * Returns all the layout set prototypes that the user has permission to view where companyId = &#63;.
2512             *
2513             * @param companyId the company ID
2514             * @return the matching layout set prototypes that the user has permission to view
2515             */
2516            @Override
2517            public List<LayoutSetPrototype> filterFindByCompanyId(long companyId) {
2518                    return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
2519                            QueryUtil.ALL_POS, null);
2520            }
2521    
2522            /**
2523             * Returns a range of all the layout set prototypes that the user has permission to view where companyId = &#63;.
2524             *
2525             * <p>
2526             * 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 LayoutSetPrototypeModelImpl}. 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.
2527             * </p>
2528             *
2529             * @param companyId the company ID
2530             * @param start the lower bound of the range of layout set prototypes
2531             * @param end the upper bound of the range of layout set prototypes (not inclusive)
2532             * @return the range of matching layout set prototypes that the user has permission to view
2533             */
2534            @Override
2535            public List<LayoutSetPrototype> filterFindByCompanyId(long companyId,
2536                    int start, int end) {
2537                    return filterFindByCompanyId(companyId, start, end, null);
2538            }
2539    
2540            /**
2541             * Returns an ordered range of all the layout set prototypes that the user has permissions to view where companyId = &#63;.
2542             *
2543             * <p>
2544             * 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 LayoutSetPrototypeModelImpl}. 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.
2545             * </p>
2546             *
2547             * @param companyId the company ID
2548             * @param start the lower bound of the range of layout set prototypes
2549             * @param end the upper bound of the range of layout set prototypes (not inclusive)
2550             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2551             * @return the ordered range of matching layout set prototypes that the user has permission to view
2552             */
2553            @Override
2554            public List<LayoutSetPrototype> filterFindByCompanyId(long companyId,
2555                    int start, int end,
2556                    OrderByComparator<LayoutSetPrototype> orderByComparator) {
2557                    if (!InlineSQLHelperUtil.isEnabled()) {
2558                            return findByCompanyId(companyId, start, end, orderByComparator);
2559                    }
2560    
2561                    StringBundler query = null;
2562    
2563                    if (orderByComparator != null) {
2564                            query = new StringBundler(3 +
2565                                            (orderByComparator.getOrderByFields().length * 3));
2566                    }
2567                    else {
2568                            query = new StringBundler(3);
2569                    }
2570    
2571                    if (getDB().isSupportsInlineDistinct()) {
2572                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
2573                    }
2574                    else {
2575                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
2576                    }
2577    
2578                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2579    
2580                    if (!getDB().isSupportsInlineDistinct()) {
2581                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
2582                    }
2583    
2584                    if (orderByComparator != null) {
2585                            if (getDB().isSupportsInlineDistinct()) {
2586                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2587                                            orderByComparator, true);
2588                            }
2589                            else {
2590                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2591                                            orderByComparator, true);
2592                            }
2593                    }
2594                    else {
2595                            if (getDB().isSupportsInlineDistinct()) {
2596                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
2597                            }
2598                            else {
2599                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_SQL);
2600                            }
2601                    }
2602    
2603                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2604                                    LayoutSetPrototype.class.getName(),
2605                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2606    
2607                    Session session = null;
2608    
2609                    try {
2610                            session = openSession();
2611    
2612                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2613    
2614                            if (getDB().isSupportsInlineDistinct()) {
2615                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetPrototypeImpl.class);
2616                            }
2617                            else {
2618                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetPrototypeImpl.class);
2619                            }
2620    
2621                            QueryPos qPos = QueryPos.getInstance(q);
2622    
2623                            qPos.add(companyId);
2624    
2625                            return (List<LayoutSetPrototype>)QueryUtil.list(q, getDialect(),
2626                                    start, end);
2627                    }
2628                    catch (Exception e) {
2629                            throw processException(e);
2630                    }
2631                    finally {
2632                            closeSession(session);
2633                    }
2634            }
2635    
2636            /**
2637             * Returns the layout set prototypes before and after the current layout set prototype in the ordered set of layout set prototypes that the user has permission to view where companyId = &#63;.
2638             *
2639             * @param layoutSetPrototypeId the primary key of the current layout set prototype
2640             * @param companyId the company ID
2641             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2642             * @return the previous, current, and next layout set prototype
2643             * @throws NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
2644             */
2645            @Override
2646            public LayoutSetPrototype[] filterFindByCompanyId_PrevAndNext(
2647                    long layoutSetPrototypeId, long companyId,
2648                    OrderByComparator<LayoutSetPrototype> orderByComparator)
2649                    throws NoSuchLayoutSetPrototypeException {
2650                    if (!InlineSQLHelperUtil.isEnabled()) {
2651                            return findByCompanyId_PrevAndNext(layoutSetPrototypeId, companyId,
2652                                    orderByComparator);
2653                    }
2654    
2655                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
2656    
2657                    Session session = null;
2658    
2659                    try {
2660                            session = openSession();
2661    
2662                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
2663    
2664                            array[0] = filterGetByCompanyId_PrevAndNext(session,
2665                                            layoutSetPrototype, companyId, orderByComparator, true);
2666    
2667                            array[1] = layoutSetPrototype;
2668    
2669                            array[2] = filterGetByCompanyId_PrevAndNext(session,
2670                                            layoutSetPrototype, companyId, orderByComparator, false);
2671    
2672                            return array;
2673                    }
2674                    catch (Exception e) {
2675                            throw processException(e);
2676                    }
2677                    finally {
2678                            closeSession(session);
2679                    }
2680            }
2681    
2682            protected LayoutSetPrototype filterGetByCompanyId_PrevAndNext(
2683                    Session session, LayoutSetPrototype layoutSetPrototype, long companyId,
2684                    OrderByComparator<LayoutSetPrototype> orderByComparator,
2685                    boolean previous) {
2686                    StringBundler query = null;
2687    
2688                    if (orderByComparator != null) {
2689                            query = new StringBundler(6 +
2690                                            (orderByComparator.getOrderByFields().length * 6));
2691                    }
2692                    else {
2693                            query = new StringBundler(3);
2694                    }
2695    
2696                    if (getDB().isSupportsInlineDistinct()) {
2697                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
2698                    }
2699                    else {
2700                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
2701                    }
2702    
2703                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2704    
2705                    if (!getDB().isSupportsInlineDistinct()) {
2706                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
2707                    }
2708    
2709                    if (orderByComparator != null) {
2710                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2711    
2712                            if (orderByConditionFields.length > 0) {
2713                                    query.append(WHERE_AND);
2714                            }
2715    
2716                            for (int i = 0; i < orderByConditionFields.length; i++) {
2717                                    if (getDB().isSupportsInlineDistinct()) {
2718                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2719                                    }
2720                                    else {
2721                                            query.append(_ORDER_BY_ENTITY_TABLE);
2722                                    }
2723    
2724                                    query.append(orderByConditionFields[i]);
2725    
2726                                    if ((i + 1) < orderByConditionFields.length) {
2727                                            if (orderByComparator.isAscending() ^ previous) {
2728                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2729                                            }
2730                                            else {
2731                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2732                                            }
2733                                    }
2734                                    else {
2735                                            if (orderByComparator.isAscending() ^ previous) {
2736                                                    query.append(WHERE_GREATER_THAN);
2737                                            }
2738                                            else {
2739                                                    query.append(WHERE_LESSER_THAN);
2740                                            }
2741                                    }
2742                            }
2743    
2744                            query.append(ORDER_BY_CLAUSE);
2745    
2746                            String[] orderByFields = orderByComparator.getOrderByFields();
2747    
2748                            for (int i = 0; i < orderByFields.length; i++) {
2749                                    if (getDB().isSupportsInlineDistinct()) {
2750                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2751                                    }
2752                                    else {
2753                                            query.append(_ORDER_BY_ENTITY_TABLE);
2754                                    }
2755    
2756                                    query.append(orderByFields[i]);
2757    
2758                                    if ((i + 1) < orderByFields.length) {
2759                                            if (orderByComparator.isAscending() ^ previous) {
2760                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2761                                            }
2762                                            else {
2763                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2764                                            }
2765                                    }
2766                                    else {
2767                                            if (orderByComparator.isAscending() ^ previous) {
2768                                                    query.append(ORDER_BY_ASC);
2769                                            }
2770                                            else {
2771                                                    query.append(ORDER_BY_DESC);
2772                                            }
2773                                    }
2774                            }
2775                    }
2776                    else {
2777                            if (getDB().isSupportsInlineDistinct()) {
2778                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
2779                            }
2780                            else {
2781                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_SQL);
2782                            }
2783                    }
2784    
2785                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2786                                    LayoutSetPrototype.class.getName(),
2787                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2788    
2789                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2790    
2791                    q.setFirstResult(0);
2792                    q.setMaxResults(2);
2793    
2794                    if (getDB().isSupportsInlineDistinct()) {
2795                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetPrototypeImpl.class);
2796                    }
2797                    else {
2798                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetPrototypeImpl.class);
2799                    }
2800    
2801                    QueryPos qPos = QueryPos.getInstance(q);
2802    
2803                    qPos.add(companyId);
2804    
2805                    if (orderByComparator != null) {
2806                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetPrototype);
2807    
2808                            for (Object value : values) {
2809                                    qPos.add(value);
2810                            }
2811                    }
2812    
2813                    List<LayoutSetPrototype> list = q.list();
2814    
2815                    if (list.size() == 2) {
2816                            return list.get(1);
2817                    }
2818                    else {
2819                            return null;
2820                    }
2821            }
2822    
2823            /**
2824             * Removes all the layout set prototypes where companyId = &#63; from the database.
2825             *
2826             * @param companyId the company ID
2827             */
2828            @Override
2829            public void removeByCompanyId(long companyId) {
2830                    for (LayoutSetPrototype layoutSetPrototype : findByCompanyId(
2831                                    companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2832                            remove(layoutSetPrototype);
2833                    }
2834            }
2835    
2836            /**
2837             * Returns the number of layout set prototypes where companyId = &#63;.
2838             *
2839             * @param companyId the company ID
2840             * @return the number of matching layout set prototypes
2841             */
2842            @Override
2843            public int countByCompanyId(long companyId) {
2844                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2845    
2846                    Object[] finderArgs = new Object[] { companyId };
2847    
2848                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2849    
2850                    if (count == null) {
2851                            StringBundler query = new StringBundler(2);
2852    
2853                            query.append(_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
2854    
2855                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2856    
2857                            String sql = query.toString();
2858    
2859                            Session session = null;
2860    
2861                            try {
2862                                    session = openSession();
2863    
2864                                    Query q = session.createQuery(sql);
2865    
2866                                    QueryPos qPos = QueryPos.getInstance(q);
2867    
2868                                    qPos.add(companyId);
2869    
2870                                    count = (Long)q.uniqueResult();
2871    
2872                                    finderCache.putResult(finderPath, finderArgs, count);
2873                            }
2874                            catch (Exception e) {
2875                                    finderCache.removeResult(finderPath, finderArgs);
2876    
2877                                    throw processException(e);
2878                            }
2879                            finally {
2880                                    closeSession(session);
2881                            }
2882                    }
2883    
2884                    return count.intValue();
2885            }
2886    
2887            /**
2888             * Returns the number of layout set prototypes that the user has permission to view where companyId = &#63;.
2889             *
2890             * @param companyId the company ID
2891             * @return the number of matching layout set prototypes that the user has permission to view
2892             */
2893            @Override
2894            public int filterCountByCompanyId(long companyId) {
2895                    if (!InlineSQLHelperUtil.isEnabled()) {
2896                            return countByCompanyId(companyId);
2897                    }
2898    
2899                    StringBundler query = new StringBundler(2);
2900    
2901                    query.append(_FILTER_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
2902    
2903                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2904    
2905                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2906                                    LayoutSetPrototype.class.getName(),
2907                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2908    
2909                    Session session = null;
2910    
2911                    try {
2912                            session = openSession();
2913    
2914                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2915    
2916                            q.addScalar(COUNT_COLUMN_NAME,
2917                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2918    
2919                            QueryPos qPos = QueryPos.getInstance(q);
2920    
2921                            qPos.add(companyId);
2922    
2923                            Long count = (Long)q.uniqueResult();
2924    
2925                            return count.intValue();
2926                    }
2927                    catch (Exception e) {
2928                            throw processException(e);
2929                    }
2930                    finally {
2931                            closeSession(session);
2932                    }
2933            }
2934    
2935            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "layoutSetPrototype.companyId = ?";
2936            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_A = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
2937                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
2938                            LayoutSetPrototypeImpl.class,
2939                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_A",
2940                            new String[] {
2941                                    Long.class.getName(), Boolean.class.getName(),
2942                                    
2943                            Integer.class.getName(), Integer.class.getName(),
2944                                    OrderByComparator.class.getName()
2945                            });
2946            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
2947                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
2948                            LayoutSetPrototypeImpl.class,
2949                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_A",
2950                            new String[] { Long.class.getName(), Boolean.class.getName() },
2951                            LayoutSetPrototypeModelImpl.COMPANYID_COLUMN_BITMASK |
2952                            LayoutSetPrototypeModelImpl.ACTIVE_COLUMN_BITMASK);
2953            public static final FinderPath FINDER_PATH_COUNT_BY_C_A = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
2954                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
2955                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_A",
2956                            new String[] { Long.class.getName(), Boolean.class.getName() });
2957    
2958            /**
2959             * Returns all the layout set prototypes where companyId = &#63; and active = &#63;.
2960             *
2961             * @param companyId the company ID
2962             * @param active the active
2963             * @return the matching layout set prototypes
2964             */
2965            @Override
2966            public List<LayoutSetPrototype> findByC_A(long companyId, boolean active) {
2967                    return findByC_A(companyId, active, QueryUtil.ALL_POS,
2968                            QueryUtil.ALL_POS, null);
2969            }
2970    
2971            /**
2972             * Returns a range of all the layout set prototypes where companyId = &#63; and active = &#63;.
2973             *
2974             * <p>
2975             * 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 LayoutSetPrototypeModelImpl}. 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.
2976             * </p>
2977             *
2978             * @param companyId the company ID
2979             * @param active the active
2980             * @param start the lower bound of the range of layout set prototypes
2981             * @param end the upper bound of the range of layout set prototypes (not inclusive)
2982             * @return the range of matching layout set prototypes
2983             */
2984            @Override
2985            public List<LayoutSetPrototype> findByC_A(long companyId, boolean active,
2986                    int start, int end) {
2987                    return findByC_A(companyId, active, start, end, null);
2988            }
2989    
2990            /**
2991             * Returns an ordered range of all the layout set prototypes where companyId = &#63; and active = &#63;.
2992             *
2993             * <p>
2994             * 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 LayoutSetPrototypeModelImpl}. 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.
2995             * </p>
2996             *
2997             * @param companyId the company ID
2998             * @param active the active
2999             * @param start the lower bound of the range of layout set prototypes
3000             * @param end the upper bound of the range of layout set prototypes (not inclusive)
3001             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3002             * @return the ordered range of matching layout set prototypes
3003             */
3004            @Override
3005            public List<LayoutSetPrototype> findByC_A(long companyId, boolean active,
3006                    int start, int end,
3007                    OrderByComparator<LayoutSetPrototype> orderByComparator) {
3008                    return findByC_A(companyId, active, start, end, orderByComparator, true);
3009            }
3010    
3011            /**
3012             * Returns an ordered range of all the layout set prototypes where companyId = &#63; and active = &#63;.
3013             *
3014             * <p>
3015             * 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 LayoutSetPrototypeModelImpl}. 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.
3016             * </p>
3017             *
3018             * @param companyId the company ID
3019             * @param active the active
3020             * @param start the lower bound of the range of layout set prototypes
3021             * @param end the upper bound of the range of layout set prototypes (not inclusive)
3022             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3023             * @param retrieveFromCache whether to retrieve from the finder cache
3024             * @return the ordered range of matching layout set prototypes
3025             */
3026            @Override
3027            public List<LayoutSetPrototype> findByC_A(long companyId, boolean active,
3028                    int start, int end,
3029                    OrderByComparator<LayoutSetPrototype> orderByComparator,
3030                    boolean retrieveFromCache) {
3031                    boolean pagination = true;
3032                    FinderPath finderPath = null;
3033                    Object[] finderArgs = null;
3034    
3035                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3036                                    (orderByComparator == null)) {
3037                            pagination = false;
3038                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A;
3039                            finderArgs = new Object[] { companyId, active };
3040                    }
3041                    else {
3042                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_A;
3043                            finderArgs = new Object[] {
3044                                            companyId, active,
3045                                            
3046                                            start, end, orderByComparator
3047                                    };
3048                    }
3049    
3050                    List<LayoutSetPrototype> list = null;
3051    
3052                    if (retrieveFromCache) {
3053                            list = (List<LayoutSetPrototype>)finderCache.getResult(finderPath,
3054                                            finderArgs, this);
3055    
3056                            if ((list != null) && !list.isEmpty()) {
3057                                    for (LayoutSetPrototype layoutSetPrototype : list) {
3058                                            if ((companyId != layoutSetPrototype.getCompanyId()) ||
3059                                                            (active != layoutSetPrototype.getActive())) {
3060                                                    list = null;
3061    
3062                                                    break;
3063                                            }
3064                                    }
3065                            }
3066                    }
3067    
3068                    if (list == null) {
3069                            StringBundler query = null;
3070    
3071                            if (orderByComparator != null) {
3072                                    query = new StringBundler(4 +
3073                                                    (orderByComparator.getOrderByFields().length * 3));
3074                            }
3075                            else {
3076                                    query = new StringBundler(4);
3077                            }
3078    
3079                            query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
3080    
3081                            query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
3082    
3083                            query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
3084    
3085                            if (orderByComparator != null) {
3086                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3087                                            orderByComparator);
3088                            }
3089                            else
3090                             if (pagination) {
3091                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
3092                            }
3093    
3094                            String sql = query.toString();
3095    
3096                            Session session = null;
3097    
3098                            try {
3099                                    session = openSession();
3100    
3101                                    Query q = session.createQuery(sql);
3102    
3103                                    QueryPos qPos = QueryPos.getInstance(q);
3104    
3105                                    qPos.add(companyId);
3106    
3107                                    qPos.add(active);
3108    
3109                                    if (!pagination) {
3110                                            list = (List<LayoutSetPrototype>)QueryUtil.list(q,
3111                                                            getDialect(), start, end, false);
3112    
3113                                            Collections.sort(list);
3114    
3115                                            list = Collections.unmodifiableList(list);
3116                                    }
3117                                    else {
3118                                            list = (List<LayoutSetPrototype>)QueryUtil.list(q,
3119                                                            getDialect(), start, end);
3120                                    }
3121    
3122                                    cacheResult(list);
3123    
3124                                    finderCache.putResult(finderPath, finderArgs, list);
3125                            }
3126                            catch (Exception e) {
3127                                    finderCache.removeResult(finderPath, finderArgs);
3128    
3129                                    throw processException(e);
3130                            }
3131                            finally {
3132                                    closeSession(session);
3133                            }
3134                    }
3135    
3136                    return list;
3137            }
3138    
3139            /**
3140             * Returns the first layout set prototype in the ordered set where companyId = &#63; and active = &#63;.
3141             *
3142             * @param companyId the company ID
3143             * @param active the active
3144             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3145             * @return the first matching layout set prototype
3146             * @throws NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
3147             */
3148            @Override
3149            public LayoutSetPrototype findByC_A_First(long companyId, boolean active,
3150                    OrderByComparator<LayoutSetPrototype> orderByComparator)
3151                    throws NoSuchLayoutSetPrototypeException {
3152                    LayoutSetPrototype layoutSetPrototype = fetchByC_A_First(companyId,
3153                                    active, orderByComparator);
3154    
3155                    if (layoutSetPrototype != null) {
3156                            return layoutSetPrototype;
3157                    }
3158    
3159                    StringBundler msg = new StringBundler(6);
3160    
3161                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3162    
3163                    msg.append("companyId=");
3164                    msg.append(companyId);
3165    
3166                    msg.append(", active=");
3167                    msg.append(active);
3168    
3169                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3170    
3171                    throw new NoSuchLayoutSetPrototypeException(msg.toString());
3172            }
3173    
3174            /**
3175             * Returns the first layout set prototype in the ordered set where companyId = &#63; and active = &#63;.
3176             *
3177             * @param companyId the company ID
3178             * @param active the active
3179             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3180             * @return the first matching layout set prototype, or <code>null</code> if a matching layout set prototype could not be found
3181             */
3182            @Override
3183            public LayoutSetPrototype fetchByC_A_First(long companyId, boolean active,
3184                    OrderByComparator<LayoutSetPrototype> orderByComparator) {
3185                    List<LayoutSetPrototype> list = findByC_A(companyId, active, 0, 1,
3186                                    orderByComparator);
3187    
3188                    if (!list.isEmpty()) {
3189                            return list.get(0);
3190                    }
3191    
3192                    return null;
3193            }
3194    
3195            /**
3196             * Returns the last layout set prototype in the ordered set where companyId = &#63; and active = &#63;.
3197             *
3198             * @param companyId the company ID
3199             * @param active the active
3200             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3201             * @return the last matching layout set prototype
3202             * @throws NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
3203             */
3204            @Override
3205            public LayoutSetPrototype findByC_A_Last(long companyId, boolean active,
3206                    OrderByComparator<LayoutSetPrototype> orderByComparator)
3207                    throws NoSuchLayoutSetPrototypeException {
3208                    LayoutSetPrototype layoutSetPrototype = fetchByC_A_Last(companyId,
3209                                    active, orderByComparator);
3210    
3211                    if (layoutSetPrototype != null) {
3212                            return layoutSetPrototype;
3213                    }
3214    
3215                    StringBundler msg = new StringBundler(6);
3216    
3217                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3218    
3219                    msg.append("companyId=");
3220                    msg.append(companyId);
3221    
3222                    msg.append(", active=");
3223                    msg.append(active);
3224    
3225                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3226    
3227                    throw new NoSuchLayoutSetPrototypeException(msg.toString());
3228            }
3229    
3230            /**
3231             * Returns the last layout set prototype in the ordered set where companyId = &#63; and active = &#63;.
3232             *
3233             * @param companyId the company ID
3234             * @param active the active
3235             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3236             * @return the last matching layout set prototype, or <code>null</code> if a matching layout set prototype could not be found
3237             */
3238            @Override
3239            public LayoutSetPrototype fetchByC_A_Last(long companyId, boolean active,
3240                    OrderByComparator<LayoutSetPrototype> orderByComparator) {
3241                    int count = countByC_A(companyId, active);
3242    
3243                    if (count == 0) {
3244                            return null;
3245                    }
3246    
3247                    List<LayoutSetPrototype> list = findByC_A(companyId, active, count - 1,
3248                                    count, orderByComparator);
3249    
3250                    if (!list.isEmpty()) {
3251                            return list.get(0);
3252                    }
3253    
3254                    return null;
3255            }
3256    
3257            /**
3258             * Returns the layout set prototypes before and after the current layout set prototype in the ordered set where companyId = &#63; and active = &#63;.
3259             *
3260             * @param layoutSetPrototypeId the primary key of the current layout set prototype
3261             * @param companyId the company ID
3262             * @param active the active
3263             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3264             * @return the previous, current, and next layout set prototype
3265             * @throws NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
3266             */
3267            @Override
3268            public LayoutSetPrototype[] findByC_A_PrevAndNext(
3269                    long layoutSetPrototypeId, long companyId, boolean active,
3270                    OrderByComparator<LayoutSetPrototype> orderByComparator)
3271                    throws NoSuchLayoutSetPrototypeException {
3272                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
3273    
3274                    Session session = null;
3275    
3276                    try {
3277                            session = openSession();
3278    
3279                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
3280    
3281                            array[0] = getByC_A_PrevAndNext(session, layoutSetPrototype,
3282                                            companyId, active, orderByComparator, true);
3283    
3284                            array[1] = layoutSetPrototype;
3285    
3286                            array[2] = getByC_A_PrevAndNext(session, layoutSetPrototype,
3287                                            companyId, active, orderByComparator, false);
3288    
3289                            return array;
3290                    }
3291                    catch (Exception e) {
3292                            throw processException(e);
3293                    }
3294                    finally {
3295                            closeSession(session);
3296                    }
3297            }
3298    
3299            protected LayoutSetPrototype getByC_A_PrevAndNext(Session session,
3300                    LayoutSetPrototype layoutSetPrototype, long companyId, boolean active,
3301                    OrderByComparator<LayoutSetPrototype> orderByComparator,
3302                    boolean previous) {
3303                    StringBundler query = null;
3304    
3305                    if (orderByComparator != null) {
3306                            query = new StringBundler(6 +
3307                                            (orderByComparator.getOrderByFields().length * 6));
3308                    }
3309                    else {
3310                            query = new StringBundler(3);
3311                    }
3312    
3313                    query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
3314    
3315                    query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
3316    
3317                    query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
3318    
3319                    if (orderByComparator != null) {
3320                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3321    
3322                            if (orderByConditionFields.length > 0) {
3323                                    query.append(WHERE_AND);
3324                            }
3325    
3326                            for (int i = 0; i < orderByConditionFields.length; i++) {
3327                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3328                                    query.append(orderByConditionFields[i]);
3329    
3330                                    if ((i + 1) < orderByConditionFields.length) {
3331                                            if (orderByComparator.isAscending() ^ previous) {
3332                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3333                                            }
3334                                            else {
3335                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3336                                            }
3337                                    }
3338                                    else {
3339                                            if (orderByComparator.isAscending() ^ previous) {
3340                                                    query.append(WHERE_GREATER_THAN);
3341                                            }
3342                                            else {
3343                                                    query.append(WHERE_LESSER_THAN);
3344                                            }
3345                                    }
3346                            }
3347    
3348                            query.append(ORDER_BY_CLAUSE);
3349    
3350                            String[] orderByFields = orderByComparator.getOrderByFields();
3351    
3352                            for (int i = 0; i < orderByFields.length; i++) {
3353                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3354                                    query.append(orderByFields[i]);
3355    
3356                                    if ((i + 1) < orderByFields.length) {
3357                                            if (orderByComparator.isAscending() ^ previous) {
3358                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3359                                            }
3360                                            else {
3361                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3362                                            }
3363                                    }
3364                                    else {
3365                                            if (orderByComparator.isAscending() ^ previous) {
3366                                                    query.append(ORDER_BY_ASC);
3367                                            }
3368                                            else {
3369                                                    query.append(ORDER_BY_DESC);
3370                                            }
3371                                    }
3372                            }
3373                    }
3374                    else {
3375                            query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
3376                    }
3377    
3378                    String sql = query.toString();
3379    
3380                    Query q = session.createQuery(sql);
3381    
3382                    q.setFirstResult(0);
3383                    q.setMaxResults(2);
3384    
3385                    QueryPos qPos = QueryPos.getInstance(q);
3386    
3387                    qPos.add(companyId);
3388    
3389                    qPos.add(active);
3390    
3391                    if (orderByComparator != null) {
3392                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetPrototype);
3393    
3394                            for (Object value : values) {
3395                                    qPos.add(value);
3396                            }
3397                    }
3398    
3399                    List<LayoutSetPrototype> list = q.list();
3400    
3401                    if (list.size() == 2) {
3402                            return list.get(1);
3403                    }
3404                    else {
3405                            return null;
3406                    }
3407            }
3408    
3409            /**
3410             * Returns all the layout set prototypes that the user has permission to view where companyId = &#63; and active = &#63;.
3411             *
3412             * @param companyId the company ID
3413             * @param active the active
3414             * @return the matching layout set prototypes that the user has permission to view
3415             */
3416            @Override
3417            public List<LayoutSetPrototype> filterFindByC_A(long companyId,
3418                    boolean active) {
3419                    return filterFindByC_A(companyId, active, QueryUtil.ALL_POS,
3420                            QueryUtil.ALL_POS, null);
3421            }
3422    
3423            /**
3424             * Returns a range of all the layout set prototypes that the user has permission to view where companyId = &#63; and active = &#63;.
3425             *
3426             * <p>
3427             * 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 LayoutSetPrototypeModelImpl}. 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.
3428             * </p>
3429             *
3430             * @param companyId the company ID
3431             * @param active the active
3432             * @param start the lower bound of the range of layout set prototypes
3433             * @param end the upper bound of the range of layout set prototypes (not inclusive)
3434             * @return the range of matching layout set prototypes that the user has permission to view
3435             */
3436            @Override
3437            public List<LayoutSetPrototype> filterFindByC_A(long companyId,
3438                    boolean active, int start, int end) {
3439                    return filterFindByC_A(companyId, active, start, end, null);
3440            }
3441    
3442            /**
3443             * Returns an ordered range of all the layout set prototypes that the user has permissions to view where companyId = &#63; and active = &#63;.
3444             *
3445             * <p>
3446             * 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 LayoutSetPrototypeModelImpl}. 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.
3447             * </p>
3448             *
3449             * @param companyId the company ID
3450             * @param active the active
3451             * @param start the lower bound of the range of layout set prototypes
3452             * @param end the upper bound of the range of layout set prototypes (not inclusive)
3453             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3454             * @return the ordered range of matching layout set prototypes that the user has permission to view
3455             */
3456            @Override
3457            public List<LayoutSetPrototype> filterFindByC_A(long companyId,
3458                    boolean active, int start, int end,
3459                    OrderByComparator<LayoutSetPrototype> orderByComparator) {
3460                    if (!InlineSQLHelperUtil.isEnabled()) {
3461                            return findByC_A(companyId, active, start, end, orderByComparator);
3462                    }
3463    
3464                    StringBundler query = null;
3465    
3466                    if (orderByComparator != null) {
3467                            query = new StringBundler(4 +
3468                                            (orderByComparator.getOrderByFields().length * 3));
3469                    }
3470                    else {
3471                            query = new StringBundler(4);
3472                    }
3473    
3474                    if (getDB().isSupportsInlineDistinct()) {
3475                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
3476                    }
3477                    else {
3478                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
3479                    }
3480    
3481                    query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
3482    
3483                    query.append(_FINDER_COLUMN_C_A_ACTIVE_2_SQL);
3484    
3485                    if (!getDB().isSupportsInlineDistinct()) {
3486                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
3487                    }
3488    
3489                    if (orderByComparator != null) {
3490                            if (getDB().isSupportsInlineDistinct()) {
3491                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3492                                            orderByComparator, true);
3493                            }
3494                            else {
3495                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3496                                            orderByComparator, true);
3497                            }
3498                    }
3499                    else {
3500                            if (getDB().isSupportsInlineDistinct()) {
3501                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
3502                            }
3503                            else {
3504                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_SQL);
3505                            }
3506                    }
3507    
3508                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3509                                    LayoutSetPrototype.class.getName(),
3510                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3511    
3512                    Session session = null;
3513    
3514                    try {
3515                            session = openSession();
3516    
3517                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3518    
3519                            if (getDB().isSupportsInlineDistinct()) {
3520                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetPrototypeImpl.class);
3521                            }
3522                            else {
3523                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetPrototypeImpl.class);
3524                            }
3525    
3526                            QueryPos qPos = QueryPos.getInstance(q);
3527    
3528                            qPos.add(companyId);
3529    
3530                            qPos.add(active);
3531    
3532                            return (List<LayoutSetPrototype>)QueryUtil.list(q, getDialect(),
3533                                    start, end);
3534                    }
3535                    catch (Exception e) {
3536                            throw processException(e);
3537                    }
3538                    finally {
3539                            closeSession(session);
3540                    }
3541            }
3542    
3543            /**
3544             * Returns the layout set prototypes before and after the current layout set prototype in the ordered set of layout set prototypes that the user has permission to view where companyId = &#63; and active = &#63;.
3545             *
3546             * @param layoutSetPrototypeId the primary key of the current layout set prototype
3547             * @param companyId the company ID
3548             * @param active the active
3549             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3550             * @return the previous, current, and next layout set prototype
3551             * @throws NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
3552             */
3553            @Override
3554            public LayoutSetPrototype[] filterFindByC_A_PrevAndNext(
3555                    long layoutSetPrototypeId, long companyId, boolean active,
3556                    OrderByComparator<LayoutSetPrototype> orderByComparator)
3557                    throws NoSuchLayoutSetPrototypeException {
3558                    if (!InlineSQLHelperUtil.isEnabled()) {
3559                            return findByC_A_PrevAndNext(layoutSetPrototypeId, companyId,
3560                                    active, orderByComparator);
3561                    }
3562    
3563                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
3564    
3565                    Session session = null;
3566    
3567                    try {
3568                            session = openSession();
3569    
3570                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
3571    
3572                            array[0] = filterGetByC_A_PrevAndNext(session, layoutSetPrototype,
3573                                            companyId, active, orderByComparator, true);
3574    
3575                            array[1] = layoutSetPrototype;
3576    
3577                            array[2] = filterGetByC_A_PrevAndNext(session, layoutSetPrototype,
3578                                            companyId, active, orderByComparator, false);
3579    
3580                            return array;
3581                    }
3582                    catch (Exception e) {
3583                            throw processException(e);
3584                    }
3585                    finally {
3586                            closeSession(session);
3587                    }
3588            }
3589    
3590            protected LayoutSetPrototype filterGetByC_A_PrevAndNext(Session session,
3591                    LayoutSetPrototype layoutSetPrototype, long companyId, boolean active,
3592                    OrderByComparator<LayoutSetPrototype> orderByComparator,
3593                    boolean previous) {
3594                    StringBundler query = null;
3595    
3596                    if (orderByComparator != null) {
3597                            query = new StringBundler(6 +
3598                                            (orderByComparator.getOrderByFields().length * 6));
3599                    }
3600                    else {
3601                            query = new StringBundler(3);
3602                    }
3603    
3604                    if (getDB().isSupportsInlineDistinct()) {
3605                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
3606                    }
3607                    else {
3608                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
3609                    }
3610    
3611                    query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
3612    
3613                    query.append(_FINDER_COLUMN_C_A_ACTIVE_2_SQL);
3614    
3615                    if (!getDB().isSupportsInlineDistinct()) {
3616                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
3617                    }
3618    
3619                    if (orderByComparator != null) {
3620                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3621    
3622                            if (orderByConditionFields.length > 0) {
3623                                    query.append(WHERE_AND);
3624                            }
3625    
3626                            for (int i = 0; i < orderByConditionFields.length; i++) {
3627                                    if (getDB().isSupportsInlineDistinct()) {
3628                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3629                                    }
3630                                    else {
3631                                            query.append(_ORDER_BY_ENTITY_TABLE);
3632                                    }
3633    
3634                                    query.append(orderByConditionFields[i]);
3635    
3636                                    if ((i + 1) < orderByConditionFields.length) {
3637                                            if (orderByComparator.isAscending() ^ previous) {
3638                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3639                                            }
3640                                            else {
3641                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3642                                            }
3643                                    }
3644                                    else {
3645                                            if (orderByComparator.isAscending() ^ previous) {
3646                                                    query.append(WHERE_GREATER_THAN);
3647                                            }
3648                                            else {
3649                                                    query.append(WHERE_LESSER_THAN);
3650                                            }
3651                                    }
3652                            }
3653    
3654                            query.append(ORDER_BY_CLAUSE);
3655    
3656                            String[] orderByFields = orderByComparator.getOrderByFields();
3657    
3658                            for (int i = 0; i < orderByFields.length; i++) {
3659                                    if (getDB().isSupportsInlineDistinct()) {
3660                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3661                                    }
3662                                    else {
3663                                            query.append(_ORDER_BY_ENTITY_TABLE);
3664                                    }
3665    
3666                                    query.append(orderByFields[i]);
3667    
3668                                    if ((i + 1) < orderByFields.length) {
3669                                            if (orderByComparator.isAscending() ^ previous) {
3670                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3671                                            }
3672                                            else {
3673                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3674                                            }
3675                                    }
3676                                    else {
3677                                            if (orderByComparator.isAscending() ^ previous) {
3678                                                    query.append(ORDER_BY_ASC);
3679                                            }
3680                                            else {
3681                                                    query.append(ORDER_BY_DESC);
3682                                            }
3683                                    }
3684                            }
3685                    }
3686                    else {
3687                            if (getDB().isSupportsInlineDistinct()) {
3688                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
3689                            }
3690                            else {
3691                                    query.append(LayoutSetPrototypeModelImpl.ORDER_BY_SQL);
3692                            }
3693                    }
3694    
3695                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3696                                    LayoutSetPrototype.class.getName(),
3697                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3698    
3699                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
3700    
3701                    q.setFirstResult(0);
3702                    q.setMaxResults(2);
3703    
3704                    if (getDB().isSupportsInlineDistinct()) {
3705                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetPrototypeImpl.class);
3706                    }
3707                    else {
3708                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetPrototypeImpl.class);
3709                    }
3710    
3711                    QueryPos qPos = QueryPos.getInstance(q);
3712    
3713                    qPos.add(companyId);
3714    
3715                    qPos.add(active);
3716    
3717                    if (orderByComparator != null) {
3718                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetPrototype);
3719    
3720                            for (Object value : values) {
3721                                    qPos.add(value);
3722                            }
3723                    }
3724    
3725                    List<LayoutSetPrototype> list = q.list();
3726    
3727                    if (list.size() == 2) {
3728                            return list.get(1);
3729                    }
3730                    else {
3731                            return null;
3732                    }
3733            }
3734    
3735            /**
3736             * Removes all the layout set prototypes where companyId = &#63; and active = &#63; from the database.
3737             *
3738             * @param companyId the company ID
3739             * @param active the active
3740             */
3741            @Override
3742            public void removeByC_A(long companyId, boolean active) {
3743                    for (LayoutSetPrototype layoutSetPrototype : findByC_A(companyId,
3744                                    active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3745                            remove(layoutSetPrototype);
3746                    }
3747            }
3748    
3749            /**
3750             * Returns the number of layout set prototypes where companyId = &#63; and active = &#63;.
3751             *
3752             * @param companyId the company ID
3753             * @param active the active
3754             * @return the number of matching layout set prototypes
3755             */
3756            @Override
3757            public int countByC_A(long companyId, boolean active) {
3758                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_A;
3759    
3760                    Object[] finderArgs = new Object[] { companyId, active };
3761    
3762                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3763    
3764                    if (count == null) {
3765                            StringBundler query = new StringBundler(3);
3766    
3767                            query.append(_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
3768    
3769                            query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
3770    
3771                            query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
3772    
3773                            String sql = query.toString();
3774    
3775                            Session session = null;
3776    
3777                            try {
3778                                    session = openSession();
3779    
3780                                    Query q = session.createQuery(sql);
3781    
3782                                    QueryPos qPos = QueryPos.getInstance(q);
3783    
3784                                    qPos.add(companyId);
3785    
3786                                    qPos.add(active);
3787    
3788                                    count = (Long)q.uniqueResult();
3789    
3790                                    finderCache.putResult(finderPath, finderArgs, count);
3791                            }
3792                            catch (Exception e) {
3793                                    finderCache.removeResult(finderPath, finderArgs);
3794    
3795                                    throw processException(e);
3796                            }
3797                            finally {
3798                                    closeSession(session);
3799                            }
3800                    }
3801    
3802                    return count.intValue();
3803            }
3804    
3805            /**
3806             * Returns the number of layout set prototypes that the user has permission to view where companyId = &#63; and active = &#63;.
3807             *
3808             * @param companyId the company ID
3809             * @param active the active
3810             * @return the number of matching layout set prototypes that the user has permission to view
3811             */
3812            @Override
3813            public int filterCountByC_A(long companyId, boolean active) {
3814                    if (!InlineSQLHelperUtil.isEnabled()) {
3815                            return countByC_A(companyId, active);
3816                    }
3817    
3818                    StringBundler query = new StringBundler(3);
3819    
3820                    query.append(_FILTER_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
3821    
3822                    query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
3823    
3824                    query.append(_FINDER_COLUMN_C_A_ACTIVE_2_SQL);
3825    
3826                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3827                                    LayoutSetPrototype.class.getName(),
3828                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3829    
3830                    Session session = null;
3831    
3832                    try {
3833                            session = openSession();
3834    
3835                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3836    
3837                            q.addScalar(COUNT_COLUMN_NAME,
3838                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3839    
3840                            QueryPos qPos = QueryPos.getInstance(q);
3841    
3842                            qPos.add(companyId);
3843    
3844                            qPos.add(active);
3845    
3846                            Long count = (Long)q.uniqueResult();
3847    
3848                            return count.intValue();
3849                    }
3850                    catch (Exception e) {
3851                            throw processException(e);
3852                    }
3853                    finally {
3854                            closeSession(session);
3855                    }
3856            }
3857    
3858            private static final String _FINDER_COLUMN_C_A_COMPANYID_2 = "layoutSetPrototype.companyId = ? AND ";
3859            private static final String _FINDER_COLUMN_C_A_ACTIVE_2 = "layoutSetPrototype.active = ?";
3860            private static final String _FINDER_COLUMN_C_A_ACTIVE_2_SQL = "layoutSetPrototype.active_ = ?";
3861    
3862            public LayoutSetPrototypePersistenceImpl() {
3863                    setModelClass(LayoutSetPrototype.class);
3864            }
3865    
3866            /**
3867             * Caches the layout set prototype in the entity cache if it is enabled.
3868             *
3869             * @param layoutSetPrototype the layout set prototype
3870             */
3871            @Override
3872            public void cacheResult(LayoutSetPrototype layoutSetPrototype) {
3873                    entityCache.putResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
3874                            LayoutSetPrototypeImpl.class, layoutSetPrototype.getPrimaryKey(),
3875                            layoutSetPrototype);
3876    
3877                    layoutSetPrototype.resetOriginalValues();
3878            }
3879    
3880            /**
3881             * Caches the layout set prototypes in the entity cache if it is enabled.
3882             *
3883             * @param layoutSetPrototypes the layout set prototypes
3884             */
3885            @Override
3886            public void cacheResult(List<LayoutSetPrototype> layoutSetPrototypes) {
3887                    for (LayoutSetPrototype layoutSetPrototype : layoutSetPrototypes) {
3888                            if (entityCache.getResult(
3889                                                    LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
3890                                                    LayoutSetPrototypeImpl.class,
3891                                                    layoutSetPrototype.getPrimaryKey()) == null) {
3892                                    cacheResult(layoutSetPrototype);
3893                            }
3894                            else {
3895                                    layoutSetPrototype.resetOriginalValues();
3896                            }
3897                    }
3898            }
3899    
3900            /**
3901             * Clears the cache for all layout set prototypes.
3902             *
3903             * <p>
3904             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
3905             * </p>
3906             */
3907            @Override
3908            public void clearCache() {
3909                    entityCache.clearCache(LayoutSetPrototypeImpl.class);
3910    
3911                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
3912                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3913                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3914            }
3915    
3916            /**
3917             * Clears the cache for the layout set prototype.
3918             *
3919             * <p>
3920             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
3921             * </p>
3922             */
3923            @Override
3924            public void clearCache(LayoutSetPrototype layoutSetPrototype) {
3925                    entityCache.removeResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
3926                            LayoutSetPrototypeImpl.class, layoutSetPrototype.getPrimaryKey());
3927    
3928                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3929                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3930            }
3931    
3932            @Override
3933            public void clearCache(List<LayoutSetPrototype> layoutSetPrototypes) {
3934                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3935                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3936    
3937                    for (LayoutSetPrototype layoutSetPrototype : layoutSetPrototypes) {
3938                            entityCache.removeResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
3939                                    LayoutSetPrototypeImpl.class, layoutSetPrototype.getPrimaryKey());
3940                    }
3941            }
3942    
3943            /**
3944             * Creates a new layout set prototype with the primary key. Does not add the layout set prototype to the database.
3945             *
3946             * @param layoutSetPrototypeId the primary key for the new layout set prototype
3947             * @return the new layout set prototype
3948             */
3949            @Override
3950            public LayoutSetPrototype create(long layoutSetPrototypeId) {
3951                    LayoutSetPrototype layoutSetPrototype = new LayoutSetPrototypeImpl();
3952    
3953                    layoutSetPrototype.setNew(true);
3954                    layoutSetPrototype.setPrimaryKey(layoutSetPrototypeId);
3955    
3956                    String uuid = PortalUUIDUtil.generate();
3957    
3958                    layoutSetPrototype.setUuid(uuid);
3959    
3960                    layoutSetPrototype.setCompanyId(companyProvider.getCompanyId());
3961    
3962                    return layoutSetPrototype;
3963            }
3964    
3965            /**
3966             * Removes the layout set prototype with the primary key from the database. Also notifies the appropriate model listeners.
3967             *
3968             * @param layoutSetPrototypeId the primary key of the layout set prototype
3969             * @return the layout set prototype that was removed
3970             * @throws NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
3971             */
3972            @Override
3973            public LayoutSetPrototype remove(long layoutSetPrototypeId)
3974                    throws NoSuchLayoutSetPrototypeException {
3975                    return remove((Serializable)layoutSetPrototypeId);
3976            }
3977    
3978            /**
3979             * Removes the layout set prototype with the primary key from the database. Also notifies the appropriate model listeners.
3980             *
3981             * @param primaryKey the primary key of the layout set prototype
3982             * @return the layout set prototype that was removed
3983             * @throws NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
3984             */
3985            @Override
3986            public LayoutSetPrototype remove(Serializable primaryKey)
3987                    throws NoSuchLayoutSetPrototypeException {
3988                    Session session = null;
3989    
3990                    try {
3991                            session = openSession();
3992    
3993                            LayoutSetPrototype layoutSetPrototype = (LayoutSetPrototype)session.get(LayoutSetPrototypeImpl.class,
3994                                            primaryKey);
3995    
3996                            if (layoutSetPrototype == null) {
3997                                    if (_log.isWarnEnabled()) {
3998                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3999                                    }
4000    
4001                                    throw new NoSuchLayoutSetPrototypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4002                                            primaryKey);
4003                            }
4004    
4005                            return remove(layoutSetPrototype);
4006                    }
4007                    catch (NoSuchLayoutSetPrototypeException nsee) {
4008                            throw nsee;
4009                    }
4010                    catch (Exception e) {
4011                            throw processException(e);
4012                    }
4013                    finally {
4014                            closeSession(session);
4015                    }
4016            }
4017    
4018            @Override
4019            protected LayoutSetPrototype removeImpl(
4020                    LayoutSetPrototype layoutSetPrototype) {
4021                    layoutSetPrototype = toUnwrappedModel(layoutSetPrototype);
4022    
4023                    Session session = null;
4024    
4025                    try {
4026                            session = openSession();
4027    
4028                            if (!session.contains(layoutSetPrototype)) {
4029                                    layoutSetPrototype = (LayoutSetPrototype)session.get(LayoutSetPrototypeImpl.class,
4030                                                    layoutSetPrototype.getPrimaryKeyObj());
4031                            }
4032    
4033                            if (layoutSetPrototype != null) {
4034                                    session.delete(layoutSetPrototype);
4035                            }
4036                    }
4037                    catch (Exception e) {
4038                            throw processException(e);
4039                    }
4040                    finally {
4041                            closeSession(session);
4042                    }
4043    
4044                    if (layoutSetPrototype != null) {
4045                            clearCache(layoutSetPrototype);
4046                    }
4047    
4048                    return layoutSetPrototype;
4049            }
4050    
4051            @Override
4052            public LayoutSetPrototype updateImpl(LayoutSetPrototype layoutSetPrototype) {
4053                    layoutSetPrototype = toUnwrappedModel(layoutSetPrototype);
4054    
4055                    boolean isNew = layoutSetPrototype.isNew();
4056    
4057                    LayoutSetPrototypeModelImpl layoutSetPrototypeModelImpl = (LayoutSetPrototypeModelImpl)layoutSetPrototype;
4058    
4059                    if (Validator.isNull(layoutSetPrototype.getUuid())) {
4060                            String uuid = PortalUUIDUtil.generate();
4061    
4062                            layoutSetPrototype.setUuid(uuid);
4063                    }
4064    
4065                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
4066    
4067                    Date now = new Date();
4068    
4069                    if (isNew && (layoutSetPrototype.getCreateDate() == null)) {
4070                            if (serviceContext == null) {
4071                                    layoutSetPrototype.setCreateDate(now);
4072                            }
4073                            else {
4074                                    layoutSetPrototype.setCreateDate(serviceContext.getCreateDate(
4075                                                    now));
4076                            }
4077                    }
4078    
4079                    if (!layoutSetPrototypeModelImpl.hasSetModifiedDate()) {
4080                            if (serviceContext == null) {
4081                                    layoutSetPrototype.setModifiedDate(now);
4082                            }
4083                            else {
4084                                    layoutSetPrototype.setModifiedDate(serviceContext.getModifiedDate(
4085                                                    now));
4086                            }
4087                    }
4088    
4089                    Session session = null;
4090    
4091                    try {
4092                            session = openSession();
4093    
4094                            if (layoutSetPrototype.isNew()) {
4095                                    session.save(layoutSetPrototype);
4096    
4097                                    layoutSetPrototype.setNew(false);
4098                            }
4099                            else {
4100                                    layoutSetPrototype = (LayoutSetPrototype)session.merge(layoutSetPrototype);
4101                            }
4102                    }
4103                    catch (Exception e) {
4104                            throw processException(e);
4105                    }
4106                    finally {
4107                            closeSession(session);
4108                    }
4109    
4110                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4111    
4112                    if (isNew || !LayoutSetPrototypeModelImpl.COLUMN_BITMASK_ENABLED) {
4113                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4114                    }
4115    
4116                    else {
4117                            if ((layoutSetPrototypeModelImpl.getColumnBitmask() &
4118                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4119                                    Object[] args = new Object[] {
4120                                                    layoutSetPrototypeModelImpl.getOriginalUuid()
4121                                            };
4122    
4123                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4124                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4125                                            args);
4126    
4127                                    args = new Object[] { layoutSetPrototypeModelImpl.getUuid() };
4128    
4129                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4130                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4131                                            args);
4132                            }
4133    
4134                            if ((layoutSetPrototypeModelImpl.getColumnBitmask() &
4135                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4136                                    Object[] args = new Object[] {
4137                                                    layoutSetPrototypeModelImpl.getOriginalUuid(),
4138                                                    layoutSetPrototypeModelImpl.getOriginalCompanyId()
4139                                            };
4140    
4141                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4142                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4143                                            args);
4144    
4145                                    args = new Object[] {
4146                                                    layoutSetPrototypeModelImpl.getUuid(),
4147                                                    layoutSetPrototypeModelImpl.getCompanyId()
4148                                            };
4149    
4150                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4151                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4152                                            args);
4153                            }
4154    
4155                            if ((layoutSetPrototypeModelImpl.getColumnBitmask() &
4156                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
4157                                    Object[] args = new Object[] {
4158                                                    layoutSetPrototypeModelImpl.getOriginalCompanyId()
4159                                            };
4160    
4161                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
4162                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4163                                            args);
4164    
4165                                    args = new Object[] { layoutSetPrototypeModelImpl.getCompanyId() };
4166    
4167                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
4168                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4169                                            args);
4170                            }
4171    
4172                            if ((layoutSetPrototypeModelImpl.getColumnBitmask() &
4173                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A.getColumnBitmask()) != 0) {
4174                                    Object[] args = new Object[] {
4175                                                    layoutSetPrototypeModelImpl.getOriginalCompanyId(),
4176                                                    layoutSetPrototypeModelImpl.getOriginalActive()
4177                                            };
4178    
4179                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_A, args);
4180                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A,
4181                                            args);
4182    
4183                                    args = new Object[] {
4184                                                    layoutSetPrototypeModelImpl.getCompanyId(),
4185                                                    layoutSetPrototypeModelImpl.getActive()
4186                                            };
4187    
4188                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_A, args);
4189                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A,
4190                                            args);
4191                            }
4192                    }
4193    
4194                    entityCache.putResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
4195                            LayoutSetPrototypeImpl.class, layoutSetPrototype.getPrimaryKey(),
4196                            layoutSetPrototype, false);
4197    
4198                    layoutSetPrototype.resetOriginalValues();
4199    
4200                    return layoutSetPrototype;
4201            }
4202    
4203            protected LayoutSetPrototype toUnwrappedModel(
4204                    LayoutSetPrototype layoutSetPrototype) {
4205                    if (layoutSetPrototype instanceof LayoutSetPrototypeImpl) {
4206                            return layoutSetPrototype;
4207                    }
4208    
4209                    LayoutSetPrototypeImpl layoutSetPrototypeImpl = new LayoutSetPrototypeImpl();
4210    
4211                    layoutSetPrototypeImpl.setNew(layoutSetPrototype.isNew());
4212                    layoutSetPrototypeImpl.setPrimaryKey(layoutSetPrototype.getPrimaryKey());
4213    
4214                    layoutSetPrototypeImpl.setMvccVersion(layoutSetPrototype.getMvccVersion());
4215                    layoutSetPrototypeImpl.setUuid(layoutSetPrototype.getUuid());
4216                    layoutSetPrototypeImpl.setLayoutSetPrototypeId(layoutSetPrototype.getLayoutSetPrototypeId());
4217                    layoutSetPrototypeImpl.setCompanyId(layoutSetPrototype.getCompanyId());
4218                    layoutSetPrototypeImpl.setUserId(layoutSetPrototype.getUserId());
4219                    layoutSetPrototypeImpl.setUserName(layoutSetPrototype.getUserName());
4220                    layoutSetPrototypeImpl.setCreateDate(layoutSetPrototype.getCreateDate());
4221                    layoutSetPrototypeImpl.setModifiedDate(layoutSetPrototype.getModifiedDate());
4222                    layoutSetPrototypeImpl.setName(layoutSetPrototype.getName());
4223                    layoutSetPrototypeImpl.setDescription(layoutSetPrototype.getDescription());
4224                    layoutSetPrototypeImpl.setSettings(layoutSetPrototype.getSettings());
4225                    layoutSetPrototypeImpl.setActive(layoutSetPrototype.isActive());
4226    
4227                    return layoutSetPrototypeImpl;
4228            }
4229    
4230            /**
4231             * Returns the layout set prototype with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
4232             *
4233             * @param primaryKey the primary key of the layout set prototype
4234             * @return the layout set prototype
4235             * @throws NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
4236             */
4237            @Override
4238            public LayoutSetPrototype findByPrimaryKey(Serializable primaryKey)
4239                    throws NoSuchLayoutSetPrototypeException {
4240                    LayoutSetPrototype layoutSetPrototype = fetchByPrimaryKey(primaryKey);
4241    
4242                    if (layoutSetPrototype == null) {
4243                            if (_log.isWarnEnabled()) {
4244                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4245                            }
4246    
4247                            throw new NoSuchLayoutSetPrototypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4248                                    primaryKey);
4249                    }
4250    
4251                    return layoutSetPrototype;
4252            }
4253    
4254            /**
4255             * Returns the layout set prototype with the primary key or throws a {@link NoSuchLayoutSetPrototypeException} if it could not be found.
4256             *
4257             * @param layoutSetPrototypeId the primary key of the layout set prototype
4258             * @return the layout set prototype
4259             * @throws NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
4260             */
4261            @Override
4262            public LayoutSetPrototype findByPrimaryKey(long layoutSetPrototypeId)
4263                    throws NoSuchLayoutSetPrototypeException {
4264                    return findByPrimaryKey((Serializable)layoutSetPrototypeId);
4265            }
4266    
4267            /**
4268             * Returns the layout set prototype with the primary key or returns <code>null</code> if it could not be found.
4269             *
4270             * @param primaryKey the primary key of the layout set prototype
4271             * @return the layout set prototype, or <code>null</code> if a layout set prototype with the primary key could not be found
4272             */
4273            @Override
4274            public LayoutSetPrototype fetchByPrimaryKey(Serializable primaryKey) {
4275                    LayoutSetPrototype layoutSetPrototype = (LayoutSetPrototype)entityCache.getResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
4276                                    LayoutSetPrototypeImpl.class, primaryKey);
4277    
4278                    if (layoutSetPrototype == _nullLayoutSetPrototype) {
4279                            return null;
4280                    }
4281    
4282                    if (layoutSetPrototype == null) {
4283                            Session session = null;
4284    
4285                            try {
4286                                    session = openSession();
4287    
4288                                    layoutSetPrototype = (LayoutSetPrototype)session.get(LayoutSetPrototypeImpl.class,
4289                                                    primaryKey);
4290    
4291                                    if (layoutSetPrototype != null) {
4292                                            cacheResult(layoutSetPrototype);
4293                                    }
4294                                    else {
4295                                            entityCache.putResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
4296                                                    LayoutSetPrototypeImpl.class, primaryKey,
4297                                                    _nullLayoutSetPrototype);
4298                                    }
4299                            }
4300                            catch (Exception e) {
4301                                    entityCache.removeResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
4302                                            LayoutSetPrototypeImpl.class, primaryKey);
4303    
4304                                    throw processException(e);
4305                            }
4306                            finally {
4307                                    closeSession(session);
4308                            }
4309                    }
4310    
4311                    return layoutSetPrototype;
4312            }
4313    
4314            /**
4315             * Returns the layout set prototype with the primary key or returns <code>null</code> if it could not be found.
4316             *
4317             * @param layoutSetPrototypeId the primary key of the layout set prototype
4318             * @return the layout set prototype, or <code>null</code> if a layout set prototype with the primary key could not be found
4319             */
4320            @Override
4321            public LayoutSetPrototype fetchByPrimaryKey(long layoutSetPrototypeId) {
4322                    return fetchByPrimaryKey((Serializable)layoutSetPrototypeId);
4323            }
4324    
4325            @Override
4326            public Map<Serializable, LayoutSetPrototype> fetchByPrimaryKeys(
4327                    Set<Serializable> primaryKeys) {
4328                    if (primaryKeys.isEmpty()) {
4329                            return Collections.emptyMap();
4330                    }
4331    
4332                    Map<Serializable, LayoutSetPrototype> map = new HashMap<Serializable, LayoutSetPrototype>();
4333    
4334                    if (primaryKeys.size() == 1) {
4335                            Iterator<Serializable> iterator = primaryKeys.iterator();
4336    
4337                            Serializable primaryKey = iterator.next();
4338    
4339                            LayoutSetPrototype layoutSetPrototype = fetchByPrimaryKey(primaryKey);
4340    
4341                            if (layoutSetPrototype != null) {
4342                                    map.put(primaryKey, layoutSetPrototype);
4343                            }
4344    
4345                            return map;
4346                    }
4347    
4348                    Set<Serializable> uncachedPrimaryKeys = null;
4349    
4350                    for (Serializable primaryKey : primaryKeys) {
4351                            LayoutSetPrototype layoutSetPrototype = (LayoutSetPrototype)entityCache.getResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
4352                                            LayoutSetPrototypeImpl.class, primaryKey);
4353    
4354                            if (layoutSetPrototype == null) {
4355                                    if (uncachedPrimaryKeys == null) {
4356                                            uncachedPrimaryKeys = new HashSet<Serializable>();
4357                                    }
4358    
4359                                    uncachedPrimaryKeys.add(primaryKey);
4360                            }
4361                            else {
4362                                    map.put(primaryKey, layoutSetPrototype);
4363                            }
4364                    }
4365    
4366                    if (uncachedPrimaryKeys == null) {
4367                            return map;
4368                    }
4369    
4370                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
4371                                    1);
4372    
4373                    query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE_PKS_IN);
4374    
4375                    for (Serializable primaryKey : uncachedPrimaryKeys) {
4376                            query.append(String.valueOf(primaryKey));
4377    
4378                            query.append(StringPool.COMMA);
4379                    }
4380    
4381                    query.setIndex(query.index() - 1);
4382    
4383                    query.append(StringPool.CLOSE_PARENTHESIS);
4384    
4385                    String sql = query.toString();
4386    
4387                    Session session = null;
4388    
4389                    try {
4390                            session = openSession();
4391    
4392                            Query q = session.createQuery(sql);
4393    
4394                            for (LayoutSetPrototype layoutSetPrototype : (List<LayoutSetPrototype>)q.list()) {
4395                                    map.put(layoutSetPrototype.getPrimaryKeyObj(),
4396                                            layoutSetPrototype);
4397    
4398                                    cacheResult(layoutSetPrototype);
4399    
4400                                    uncachedPrimaryKeys.remove(layoutSetPrototype.getPrimaryKeyObj());
4401                            }
4402    
4403                            for (Serializable primaryKey : uncachedPrimaryKeys) {
4404                                    entityCache.putResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
4405                                            LayoutSetPrototypeImpl.class, primaryKey,
4406                                            _nullLayoutSetPrototype);
4407                            }
4408                    }
4409                    catch (Exception e) {
4410                            throw processException(e);
4411                    }
4412                    finally {
4413                            closeSession(session);
4414                    }
4415    
4416                    return map;
4417            }
4418    
4419            /**
4420             * Returns all the layout set prototypes.
4421             *
4422             * @return the layout set prototypes
4423             */
4424            @Override
4425            public List<LayoutSetPrototype> findAll() {
4426                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4427            }
4428    
4429            /**
4430             * Returns a range of all the layout set prototypes.
4431             *
4432             * <p>
4433             * 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 LayoutSetPrototypeModelImpl}. 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.
4434             * </p>
4435             *
4436             * @param start the lower bound of the range of layout set prototypes
4437             * @param end the upper bound of the range of layout set prototypes (not inclusive)
4438             * @return the range of layout set prototypes
4439             */
4440            @Override
4441            public List<LayoutSetPrototype> findAll(int start, int end) {
4442                    return findAll(start, end, null);
4443            }
4444    
4445            /**
4446             * Returns an ordered range of all the layout set prototypes.
4447             *
4448             * <p>
4449             * 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 LayoutSetPrototypeModelImpl}. 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.
4450             * </p>
4451             *
4452             * @param start the lower bound of the range of layout set prototypes
4453             * @param end the upper bound of the range of layout set prototypes (not inclusive)
4454             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4455             * @return the ordered range of layout set prototypes
4456             */
4457            @Override
4458            public List<LayoutSetPrototype> findAll(int start, int end,
4459                    OrderByComparator<LayoutSetPrototype> orderByComparator) {
4460                    return findAll(start, end, orderByComparator, true);
4461            }
4462    
4463            /**
4464             * Returns an ordered range of all the layout set prototypes.
4465             *
4466             * <p>
4467             * 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 LayoutSetPrototypeModelImpl}. 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.
4468             * </p>
4469             *
4470             * @param start the lower bound of the range of layout set prototypes
4471             * @param end the upper bound of the range of layout set prototypes (not inclusive)
4472             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4473             * @param retrieveFromCache whether to retrieve from the finder cache
4474             * @return the ordered range of layout set prototypes
4475             */
4476            @Override
4477            public List<LayoutSetPrototype> findAll(int start, int end,
4478                    OrderByComparator<LayoutSetPrototype> orderByComparator,
4479                    boolean retrieveFromCache) {
4480                    boolean pagination = true;
4481                    FinderPath finderPath = null;
4482                    Object[] finderArgs = null;
4483    
4484                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4485                                    (orderByComparator == null)) {
4486                            pagination = false;
4487                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4488                            finderArgs = FINDER_ARGS_EMPTY;
4489                    }
4490                    else {
4491                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4492                            finderArgs = new Object[] { start, end, orderByComparator };
4493                    }
4494    
4495                    List<LayoutSetPrototype> list = null;
4496    
4497                    if (retrieveFromCache) {
4498                            list = (List<LayoutSetPrototype>)finderCache.getResult(finderPath,
4499                                            finderArgs, this);
4500                    }
4501    
4502                    if (list == null) {
4503                            StringBundler query = null;
4504                            String sql = null;
4505    
4506                            if (orderByComparator != null) {
4507                                    query = new StringBundler(2 +
4508                                                    (orderByComparator.getOrderByFields().length * 3));
4509    
4510                                    query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE);
4511    
4512                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4513                                            orderByComparator);
4514    
4515                                    sql = query.toString();
4516                            }
4517                            else {
4518                                    sql = _SQL_SELECT_LAYOUTSETPROTOTYPE;
4519    
4520                                    if (pagination) {
4521                                            sql = sql.concat(LayoutSetPrototypeModelImpl.ORDER_BY_JPQL);
4522                                    }
4523                            }
4524    
4525                            Session session = null;
4526    
4527                            try {
4528                                    session = openSession();
4529    
4530                                    Query q = session.createQuery(sql);
4531    
4532                                    if (!pagination) {
4533                                            list = (List<LayoutSetPrototype>)QueryUtil.list(q,
4534                                                            getDialect(), start, end, false);
4535    
4536                                            Collections.sort(list);
4537    
4538                                            list = Collections.unmodifiableList(list);
4539                                    }
4540                                    else {
4541                                            list = (List<LayoutSetPrototype>)QueryUtil.list(q,
4542                                                            getDialect(), start, end);
4543                                    }
4544    
4545                                    cacheResult(list);
4546    
4547                                    finderCache.putResult(finderPath, finderArgs, list);
4548                            }
4549                            catch (Exception e) {
4550                                    finderCache.removeResult(finderPath, finderArgs);
4551    
4552                                    throw processException(e);
4553                            }
4554                            finally {
4555                                    closeSession(session);
4556                            }
4557                    }
4558    
4559                    return list;
4560            }
4561    
4562            /**
4563             * Removes all the layout set prototypes from the database.
4564             *
4565             */
4566            @Override
4567            public void removeAll() {
4568                    for (LayoutSetPrototype layoutSetPrototype : findAll()) {
4569                            remove(layoutSetPrototype);
4570                    }
4571            }
4572    
4573            /**
4574             * Returns the number of layout set prototypes.
4575             *
4576             * @return the number of layout set prototypes
4577             */
4578            @Override
4579            public int countAll() {
4580                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
4581                                    FINDER_ARGS_EMPTY, this);
4582    
4583                    if (count == null) {
4584                            Session session = null;
4585    
4586                            try {
4587                                    session = openSession();
4588    
4589                                    Query q = session.createQuery(_SQL_COUNT_LAYOUTSETPROTOTYPE);
4590    
4591                                    count = (Long)q.uniqueResult();
4592    
4593                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
4594                                            count);
4595                            }
4596                            catch (Exception e) {
4597                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
4598                                            FINDER_ARGS_EMPTY);
4599    
4600                                    throw processException(e);
4601                            }
4602                            finally {
4603                                    closeSession(session);
4604                            }
4605                    }
4606    
4607                    return count.intValue();
4608            }
4609    
4610            @Override
4611            public Set<String> getBadColumnNames() {
4612                    return _badColumnNames;
4613            }
4614    
4615            @Override
4616            protected Map<String, Integer> getTableColumnsMap() {
4617                    return LayoutSetPrototypeModelImpl.TABLE_COLUMNS_MAP;
4618            }
4619    
4620            /**
4621             * Initializes the layout set prototype persistence.
4622             */
4623            public void afterPropertiesSet() {
4624            }
4625    
4626            public void destroy() {
4627                    entityCache.removeCache(LayoutSetPrototypeImpl.class.getName());
4628                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
4629                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4630                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4631            }
4632    
4633            @BeanReference(type = CompanyProviderWrapper.class)
4634            protected CompanyProvider companyProvider;
4635            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
4636            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
4637            private static final String _SQL_SELECT_LAYOUTSETPROTOTYPE = "SELECT layoutSetPrototype FROM LayoutSetPrototype layoutSetPrototype";
4638            private static final String _SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE_PKS_IN = "SELECT layoutSetPrototype FROM LayoutSetPrototype layoutSetPrototype WHERE layoutSetPrototypeId IN (";
4639            private static final String _SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE = "SELECT layoutSetPrototype FROM LayoutSetPrototype layoutSetPrototype WHERE ";
4640            private static final String _SQL_COUNT_LAYOUTSETPROTOTYPE = "SELECT COUNT(layoutSetPrototype) FROM LayoutSetPrototype layoutSetPrototype";
4641            private static final String _SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE = "SELECT COUNT(layoutSetPrototype) FROM LayoutSetPrototype layoutSetPrototype WHERE ";
4642            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "layoutSetPrototype.layoutSetPrototypeId";
4643            private static final String _FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE = "SELECT DISTINCT {layoutSetPrototype.*} FROM LayoutSetPrototype layoutSetPrototype WHERE ";
4644            private static final String _FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1 =
4645                    "SELECT {LayoutSetPrototype.*} FROM (SELECT DISTINCT layoutSetPrototype.layoutSetPrototypeId FROM LayoutSetPrototype layoutSetPrototype WHERE ";
4646            private static final String _FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2 =
4647                    ") TEMP_TABLE INNER JOIN LayoutSetPrototype ON TEMP_TABLE.layoutSetPrototypeId = LayoutSetPrototype.layoutSetPrototypeId";
4648            private static final String _FILTER_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE = "SELECT COUNT(DISTINCT layoutSetPrototype.layoutSetPrototypeId) AS COUNT_VALUE FROM LayoutSetPrototype layoutSetPrototype WHERE ";
4649            private static final String _FILTER_ENTITY_ALIAS = "layoutSetPrototype";
4650            private static final String _FILTER_ENTITY_TABLE = "LayoutSetPrototype";
4651            private static final String _ORDER_BY_ENTITY_ALIAS = "layoutSetPrototype.";
4652            private static final String _ORDER_BY_ENTITY_TABLE = "LayoutSetPrototype.";
4653            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutSetPrototype exists with the primary key ";
4654            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutSetPrototype exists with the key {";
4655            private static final Log _log = LogFactoryUtil.getLog(LayoutSetPrototypePersistenceImpl.class);
4656            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
4657                                    "uuid", "settings", "active"
4658                            });
4659            private static final LayoutSetPrototype _nullLayoutSetPrototype = new LayoutSetPrototypeImpl() {
4660                            @Override
4661                            public Object clone() {
4662                                    return this;
4663                            }
4664    
4665                            @Override
4666                            public CacheModel<LayoutSetPrototype> toCacheModel() {
4667                                    return _nullLayoutSetPrototypeCacheModel;
4668                            }
4669                    };
4670    
4671            private static final CacheModel<LayoutSetPrototype> _nullLayoutSetPrototypeCacheModel =
4672                    new NullCacheModel();
4673    
4674            private static class NullCacheModel implements CacheModel<LayoutSetPrototype>,
4675                    MVCCModel {
4676                    @Override
4677                    public long getMvccVersion() {
4678                            return -1;
4679                    }
4680    
4681                    @Override
4682                    public void setMvccVersion(long mvccVersion) {
4683                    }
4684    
4685                    @Override
4686                    public LayoutSetPrototype toEntityModel() {
4687                            return _nullLayoutSetPrototype;
4688                    }
4689            }
4690    }