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