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