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