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