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