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