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