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