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