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