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