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