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