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