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