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