001    /**
002     * Copyright (c) 2000-2012 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.NoSuchLayoutSetPrototypeException;
018    import com.liferay.portal.NoSuchModelException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.SQLQuery;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.exception.SystemException;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
032    import com.liferay.portal.kernel.util.GetterUtil;
033    import com.liferay.portal.kernel.util.InstanceFactory;
034    import com.liferay.portal.kernel.util.OrderByComparator;
035    import com.liferay.portal.kernel.util.StringBundler;
036    import com.liferay.portal.kernel.util.StringPool;
037    import com.liferay.portal.kernel.util.StringUtil;
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.LayoutSetPrototype;
042    import com.liferay.portal.model.ModelListener;
043    import com.liferay.portal.model.impl.LayoutSetPrototypeImpl;
044    import com.liferay.portal.model.impl.LayoutSetPrototypeModelImpl;
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    
054    /**
055     * The persistence implementation for the layout set prototype service.
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see LayoutSetPrototypePersistence
063     * @see LayoutSetPrototypeUtil
064     * @generated
065     */
066    public class LayoutSetPrototypePersistenceImpl extends BasePersistenceImpl<LayoutSetPrototype>
067            implements LayoutSetPrototypePersistence {
068            /*
069             * NOTE FOR DEVELOPERS:
070             *
071             * Never modify or reference this class directly. Always use {@link LayoutSetPrototypeUtil} to access the layout set prototype persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
072             */
073            public static final String FINDER_CLASS_NAME_ENTITY = LayoutSetPrototypeImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List1";
076            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List2";
078            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
079                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
080                            LayoutSetPrototypeImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
082                            new String[] {
083                                    String.class.getName(),
084                                    
085                            "java.lang.Integer", "java.lang.Integer",
086                                    "com.liferay.portal.kernel.util.OrderByComparator"
087                            });
088            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
089                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
090                            LayoutSetPrototypeImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
092                            new String[] { String.class.getName() },
093                            LayoutSetPrototypeModelImpl.UUID_COLUMN_BITMASK);
094            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
095                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
097                            new String[] { String.class.getName() });
098            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
099                    new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
100                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
101                            LayoutSetPrototypeImpl.class,
102                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
103                            new String[] {
104                                    Long.class.getName(),
105                                    
106                            "java.lang.Integer", "java.lang.Integer",
107                                    "com.liferay.portal.kernel.util.OrderByComparator"
108                            });
109            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
110                    new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
111                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
112                            LayoutSetPrototypeImpl.class,
113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
114                            new String[] { Long.class.getName() },
115                            LayoutSetPrototypeModelImpl.COMPANYID_COLUMN_BITMASK);
116            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
117                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
118                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
119                            new String[] { Long.class.getName() });
120            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_A = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
121                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
122                            LayoutSetPrototypeImpl.class,
123                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_A",
124                            new String[] {
125                                    Long.class.getName(), Boolean.class.getName(),
126                                    
127                            "java.lang.Integer", "java.lang.Integer",
128                                    "com.liferay.portal.kernel.util.OrderByComparator"
129                            });
130            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
131                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
132                            LayoutSetPrototypeImpl.class,
133                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_A",
134                            new String[] { Long.class.getName(), Boolean.class.getName() },
135                            LayoutSetPrototypeModelImpl.COMPANYID_COLUMN_BITMASK |
136                            LayoutSetPrototypeModelImpl.ACTIVE_COLUMN_BITMASK);
137            public static final FinderPath FINDER_PATH_COUNT_BY_C_A = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
138                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
139                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_A",
140                            new String[] { Long.class.getName(), Boolean.class.getName() });
141            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
142                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
143                            LayoutSetPrototypeImpl.class,
144                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
145            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
146                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
147                            LayoutSetPrototypeImpl.class,
148                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
149            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
150                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED, Long.class,
151                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
152    
153            /**
154             * Caches the layout set prototype in the entity cache if it is enabled.
155             *
156             * @param layoutSetPrototype the layout set prototype
157             */
158            public void cacheResult(LayoutSetPrototype layoutSetPrototype) {
159                    EntityCacheUtil.putResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
160                            LayoutSetPrototypeImpl.class, layoutSetPrototype.getPrimaryKey(),
161                            layoutSetPrototype);
162    
163                    layoutSetPrototype.resetOriginalValues();
164            }
165    
166            /**
167             * Caches the layout set prototypes in the entity cache if it is enabled.
168             *
169             * @param layoutSetPrototypes the layout set prototypes
170             */
171            public void cacheResult(List<LayoutSetPrototype> layoutSetPrototypes) {
172                    for (LayoutSetPrototype layoutSetPrototype : layoutSetPrototypes) {
173                            if (EntityCacheUtil.getResult(
174                                                    LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
175                                                    LayoutSetPrototypeImpl.class,
176                                                    layoutSetPrototype.getPrimaryKey()) == null) {
177                                    cacheResult(layoutSetPrototype);
178                            }
179                            else {
180                                    layoutSetPrototype.resetOriginalValues();
181                            }
182                    }
183            }
184    
185            /**
186             * Clears the cache for all layout set prototypes.
187             *
188             * <p>
189             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
190             * </p>
191             */
192            @Override
193            public void clearCache() {
194                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
195                            CacheRegistryUtil.clear(LayoutSetPrototypeImpl.class.getName());
196                    }
197    
198                    EntityCacheUtil.clearCache(LayoutSetPrototypeImpl.class.getName());
199    
200                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
201                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
202                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
203            }
204    
205            /**
206             * Clears the cache for the layout set prototype.
207             *
208             * <p>
209             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
210             * </p>
211             */
212            @Override
213            public void clearCache(LayoutSetPrototype layoutSetPrototype) {
214                    EntityCacheUtil.removeResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
215                            LayoutSetPrototypeImpl.class, layoutSetPrototype.getPrimaryKey());
216    
217                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
218                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
219            }
220    
221            @Override
222            public void clearCache(List<LayoutSetPrototype> layoutSetPrototypes) {
223                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
224                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
225    
226                    for (LayoutSetPrototype layoutSetPrototype : layoutSetPrototypes) {
227                            EntityCacheUtil.removeResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
228                                    LayoutSetPrototypeImpl.class, layoutSetPrototype.getPrimaryKey());
229                    }
230            }
231    
232            /**
233             * Creates a new layout set prototype with the primary key. Does not add the layout set prototype to the database.
234             *
235             * @param layoutSetPrototypeId the primary key for the new layout set prototype
236             * @return the new layout set prototype
237             */
238            public LayoutSetPrototype create(long layoutSetPrototypeId) {
239                    LayoutSetPrototype layoutSetPrototype = new LayoutSetPrototypeImpl();
240    
241                    layoutSetPrototype.setNew(true);
242                    layoutSetPrototype.setPrimaryKey(layoutSetPrototypeId);
243    
244                    String uuid = PortalUUIDUtil.generate();
245    
246                    layoutSetPrototype.setUuid(uuid);
247    
248                    return layoutSetPrototype;
249            }
250    
251            /**
252             * Removes the layout set prototype with the primary key from the database. Also notifies the appropriate model listeners.
253             *
254             * @param layoutSetPrototypeId the primary key of the layout set prototype
255             * @return the layout set prototype that was removed
256             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
257             * @throws SystemException if a system exception occurred
258             */
259            public LayoutSetPrototype remove(long layoutSetPrototypeId)
260                    throws NoSuchLayoutSetPrototypeException, SystemException {
261                    return remove(Long.valueOf(layoutSetPrototypeId));
262            }
263    
264            /**
265             * Removes the layout set prototype with the primary key from the database. Also notifies the appropriate model listeners.
266             *
267             * @param primaryKey the primary key of the layout set prototype
268             * @return the layout set prototype that was removed
269             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
270             * @throws SystemException if a system exception occurred
271             */
272            @Override
273            public LayoutSetPrototype remove(Serializable primaryKey)
274                    throws NoSuchLayoutSetPrototypeException, SystemException {
275                    Session session = null;
276    
277                    try {
278                            session = openSession();
279    
280                            LayoutSetPrototype layoutSetPrototype = (LayoutSetPrototype)session.get(LayoutSetPrototypeImpl.class,
281                                            primaryKey);
282    
283                            if (layoutSetPrototype == null) {
284                                    if (_log.isWarnEnabled()) {
285                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
286                                    }
287    
288                                    throw new NoSuchLayoutSetPrototypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
289                                            primaryKey);
290                            }
291    
292                            return remove(layoutSetPrototype);
293                    }
294                    catch (NoSuchLayoutSetPrototypeException nsee) {
295                            throw nsee;
296                    }
297                    catch (Exception e) {
298                            throw processException(e);
299                    }
300                    finally {
301                            closeSession(session);
302                    }
303            }
304    
305            @Override
306            protected LayoutSetPrototype removeImpl(
307                    LayoutSetPrototype layoutSetPrototype) throws SystemException {
308                    layoutSetPrototype = toUnwrappedModel(layoutSetPrototype);
309    
310                    Session session = null;
311    
312                    try {
313                            session = openSession();
314    
315                            BatchSessionUtil.delete(session, layoutSetPrototype);
316                    }
317                    catch (Exception e) {
318                            throw processException(e);
319                    }
320                    finally {
321                            closeSession(session);
322                    }
323    
324                    clearCache(layoutSetPrototype);
325    
326                    return layoutSetPrototype;
327            }
328    
329            @Override
330            public LayoutSetPrototype updateImpl(
331                    com.liferay.portal.model.LayoutSetPrototype layoutSetPrototype,
332                    boolean merge) throws SystemException {
333                    layoutSetPrototype = toUnwrappedModel(layoutSetPrototype);
334    
335                    boolean isNew = layoutSetPrototype.isNew();
336    
337                    LayoutSetPrototypeModelImpl layoutSetPrototypeModelImpl = (LayoutSetPrototypeModelImpl)layoutSetPrototype;
338    
339                    if (Validator.isNull(layoutSetPrototype.getUuid())) {
340                            String uuid = PortalUUIDUtil.generate();
341    
342                            layoutSetPrototype.setUuid(uuid);
343                    }
344    
345                    Session session = null;
346    
347                    try {
348                            session = openSession();
349    
350                            BatchSessionUtil.update(session, layoutSetPrototype, merge);
351    
352                            layoutSetPrototype.setNew(false);
353                    }
354                    catch (Exception e) {
355                            throw processException(e);
356                    }
357                    finally {
358                            closeSession(session);
359                    }
360    
361                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
362    
363                    if (isNew || !LayoutSetPrototypeModelImpl.COLUMN_BITMASK_ENABLED) {
364                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
365                    }
366                    else {
367                            if ((layoutSetPrototypeModelImpl.getColumnBitmask() &
368                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
369                                    Object[] args = new Object[] {
370                                                    layoutSetPrototypeModelImpl.getOriginalUuid()
371                                            };
372    
373                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
374                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
375                                            args);
376    
377                                    args = new Object[] { layoutSetPrototypeModelImpl.getUuid() };
378    
379                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
380                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
381                                            args);
382                            }
383    
384                            if ((layoutSetPrototypeModelImpl.getColumnBitmask() &
385                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
386                                    Object[] args = new Object[] {
387                                                    Long.valueOf(layoutSetPrototypeModelImpl.getOriginalCompanyId())
388                                            };
389    
390                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
391                                            args);
392                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
393                                            args);
394    
395                                    args = new Object[] {
396                                                    Long.valueOf(layoutSetPrototypeModelImpl.getCompanyId())
397                                            };
398    
399                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
400                                            args);
401                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
402                                            args);
403                            }
404    
405                            if ((layoutSetPrototypeModelImpl.getColumnBitmask() &
406                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A.getColumnBitmask()) != 0) {
407                                    Object[] args = new Object[] {
408                                                    Long.valueOf(layoutSetPrototypeModelImpl.getOriginalCompanyId()),
409                                                    Boolean.valueOf(layoutSetPrototypeModelImpl.getOriginalActive())
410                                            };
411    
412                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_A, args);
413                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A,
414                                            args);
415    
416                                    args = new Object[] {
417                                                    Long.valueOf(layoutSetPrototypeModelImpl.getCompanyId()),
418                                                    Boolean.valueOf(layoutSetPrototypeModelImpl.getActive())
419                                            };
420    
421                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_A, args);
422                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A,
423                                            args);
424                            }
425                    }
426    
427                    EntityCacheUtil.putResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
428                            LayoutSetPrototypeImpl.class, layoutSetPrototype.getPrimaryKey(),
429                            layoutSetPrototype);
430    
431                    return layoutSetPrototype;
432            }
433    
434            protected LayoutSetPrototype toUnwrappedModel(
435                    LayoutSetPrototype layoutSetPrototype) {
436                    if (layoutSetPrototype instanceof LayoutSetPrototypeImpl) {
437                            return layoutSetPrototype;
438                    }
439    
440                    LayoutSetPrototypeImpl layoutSetPrototypeImpl = new LayoutSetPrototypeImpl();
441    
442                    layoutSetPrototypeImpl.setNew(layoutSetPrototype.isNew());
443                    layoutSetPrototypeImpl.setPrimaryKey(layoutSetPrototype.getPrimaryKey());
444    
445                    layoutSetPrototypeImpl.setUuid(layoutSetPrototype.getUuid());
446                    layoutSetPrototypeImpl.setLayoutSetPrototypeId(layoutSetPrototype.getLayoutSetPrototypeId());
447                    layoutSetPrototypeImpl.setCompanyId(layoutSetPrototype.getCompanyId());
448                    layoutSetPrototypeImpl.setCreateDate(layoutSetPrototype.getCreateDate());
449                    layoutSetPrototypeImpl.setModifiedDate(layoutSetPrototype.getModifiedDate());
450                    layoutSetPrototypeImpl.setName(layoutSetPrototype.getName());
451                    layoutSetPrototypeImpl.setDescription(layoutSetPrototype.getDescription());
452                    layoutSetPrototypeImpl.setSettings(layoutSetPrototype.getSettings());
453                    layoutSetPrototypeImpl.setActive(layoutSetPrototype.isActive());
454    
455                    return layoutSetPrototypeImpl;
456            }
457    
458            /**
459             * Returns the layout set prototype with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
460             *
461             * @param primaryKey the primary key of the layout set prototype
462             * @return the layout set prototype
463             * @throws com.liferay.portal.NoSuchModelException if a layout set prototype with the primary key could not be found
464             * @throws SystemException if a system exception occurred
465             */
466            @Override
467            public LayoutSetPrototype findByPrimaryKey(Serializable primaryKey)
468                    throws NoSuchModelException, SystemException {
469                    return findByPrimaryKey(((Long)primaryKey).longValue());
470            }
471    
472            /**
473             * Returns the layout set prototype with the primary key or throws a {@link com.liferay.portal.NoSuchLayoutSetPrototypeException} if it could not be found.
474             *
475             * @param layoutSetPrototypeId the primary key of the layout set prototype
476             * @return the layout set prototype
477             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
478             * @throws SystemException if a system exception occurred
479             */
480            public LayoutSetPrototype findByPrimaryKey(long layoutSetPrototypeId)
481                    throws NoSuchLayoutSetPrototypeException, SystemException {
482                    LayoutSetPrototype layoutSetPrototype = fetchByPrimaryKey(layoutSetPrototypeId);
483    
484                    if (layoutSetPrototype == null) {
485                            if (_log.isWarnEnabled()) {
486                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
487                                            layoutSetPrototypeId);
488                            }
489    
490                            throw new NoSuchLayoutSetPrototypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
491                                    layoutSetPrototypeId);
492                    }
493    
494                    return layoutSetPrototype;
495            }
496    
497            /**
498             * Returns the layout set prototype with the primary key or returns <code>null</code> if it could not be found.
499             *
500             * @param primaryKey the primary key of the layout set prototype
501             * @return the layout set prototype, or <code>null</code> if a layout set prototype with the primary key could not be found
502             * @throws SystemException if a system exception occurred
503             */
504            @Override
505            public LayoutSetPrototype fetchByPrimaryKey(Serializable primaryKey)
506                    throws SystemException {
507                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
508            }
509    
510            /**
511             * Returns the layout set prototype with the primary key or returns <code>null</code> if it could not be found.
512             *
513             * @param layoutSetPrototypeId the primary key of the layout set prototype
514             * @return the layout set prototype, or <code>null</code> if a layout set prototype with the primary key could not be found
515             * @throws SystemException if a system exception occurred
516             */
517            public LayoutSetPrototype fetchByPrimaryKey(long layoutSetPrototypeId)
518                    throws SystemException {
519                    LayoutSetPrototype layoutSetPrototype = (LayoutSetPrototype)EntityCacheUtil.getResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
520                                    LayoutSetPrototypeImpl.class, layoutSetPrototypeId);
521    
522                    if (layoutSetPrototype == _nullLayoutSetPrototype) {
523                            return null;
524                    }
525    
526                    if (layoutSetPrototype == null) {
527                            Session session = null;
528    
529                            boolean hasException = false;
530    
531                            try {
532                                    session = openSession();
533    
534                                    layoutSetPrototype = (LayoutSetPrototype)session.get(LayoutSetPrototypeImpl.class,
535                                                    Long.valueOf(layoutSetPrototypeId));
536                            }
537                            catch (Exception e) {
538                                    hasException = true;
539    
540                                    throw processException(e);
541                            }
542                            finally {
543                                    if (layoutSetPrototype != null) {
544                                            cacheResult(layoutSetPrototype);
545                                    }
546                                    else if (!hasException) {
547                                            EntityCacheUtil.putResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
548                                                    LayoutSetPrototypeImpl.class, layoutSetPrototypeId,
549                                                    _nullLayoutSetPrototype);
550                                    }
551    
552                                    closeSession(session);
553                            }
554                    }
555    
556                    return layoutSetPrototype;
557            }
558    
559            /**
560             * Returns all the layout set prototypes where uuid = &#63;.
561             *
562             * @param uuid the uuid
563             * @return the matching layout set prototypes
564             * @throws SystemException if a system exception occurred
565             */
566            public List<LayoutSetPrototype> findByUuid(String uuid)
567                    throws SystemException {
568                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
569            }
570    
571            /**
572             * Returns a range of all the layout set prototypes where uuid = &#63;.
573             *
574             * <p>
575             * 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.
576             * </p>
577             *
578             * @param uuid the uuid
579             * @param start the lower bound of the range of layout set prototypes
580             * @param end the upper bound of the range of layout set prototypes (not inclusive)
581             * @return the range of matching layout set prototypes
582             * @throws SystemException if a system exception occurred
583             */
584            public List<LayoutSetPrototype> findByUuid(String uuid, int start, int end)
585                    throws SystemException {
586                    return findByUuid(uuid, start, end, null);
587            }
588    
589            /**
590             * Returns an ordered range of all the layout set prototypes where uuid = &#63;.
591             *
592             * <p>
593             * 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.
594             * </p>
595             *
596             * @param uuid the uuid
597             * @param start the lower bound of the range of layout set prototypes
598             * @param end the upper bound of the range of layout set prototypes (not inclusive)
599             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
600             * @return the ordered range of matching layout set prototypes
601             * @throws SystemException if a system exception occurred
602             */
603            public List<LayoutSetPrototype> findByUuid(String uuid, int start, int end,
604                    OrderByComparator orderByComparator) throws SystemException {
605                    FinderPath finderPath = null;
606                    Object[] finderArgs = null;
607    
608                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
609                                    (orderByComparator == null)) {
610                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
611                            finderArgs = new Object[] { uuid };
612                    }
613                    else {
614                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
615                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
616                    }
617    
618                    List<LayoutSetPrototype> list = (List<LayoutSetPrototype>)FinderCacheUtil.getResult(finderPath,
619                                    finderArgs, this);
620    
621                    if ((list != null) && !list.isEmpty()) {
622                            for (LayoutSetPrototype layoutSetPrototype : list) {
623                                    if (!Validator.equals(uuid, layoutSetPrototype.getUuid())) {
624                                            list = null;
625    
626                                            break;
627                                    }
628                            }
629                    }
630    
631                    if (list == null) {
632                            StringBundler query = null;
633    
634                            if (orderByComparator != null) {
635                                    query = new StringBundler(3 +
636                                                    (orderByComparator.getOrderByFields().length * 3));
637                            }
638                            else {
639                                    query = new StringBundler(2);
640                            }
641    
642                            query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
643    
644                            if (uuid == null) {
645                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
646                            }
647                            else {
648                                    if (uuid.equals(StringPool.BLANK)) {
649                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
650                                    }
651                                    else {
652                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
653                                    }
654                            }
655    
656                            if (orderByComparator != null) {
657                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
658                                            orderByComparator);
659                            }
660    
661                            String sql = query.toString();
662    
663                            Session session = null;
664    
665                            try {
666                                    session = openSession();
667    
668                                    Query q = session.createQuery(sql);
669    
670                                    QueryPos qPos = QueryPos.getInstance(q);
671    
672                                    if (uuid != null) {
673                                            qPos.add(uuid);
674                                    }
675    
676                                    list = (List<LayoutSetPrototype>)QueryUtil.list(q,
677                                                    getDialect(), start, end);
678                            }
679                            catch (Exception e) {
680                                    throw processException(e);
681                            }
682                            finally {
683                                    if (list == null) {
684                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
685                                    }
686                                    else {
687                                            cacheResult(list);
688    
689                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
690                                    }
691    
692                                    closeSession(session);
693                            }
694                    }
695    
696                    return list;
697            }
698    
699            /**
700             * Returns the first layout set prototype in the ordered set where uuid = &#63;.
701             *
702             * <p>
703             * 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.
704             * </p>
705             *
706             * @param uuid the uuid
707             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
708             * @return the first matching layout set prototype
709             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
710             * @throws SystemException if a system exception occurred
711             */
712            public LayoutSetPrototype findByUuid_First(String uuid,
713                    OrderByComparator orderByComparator)
714                    throws NoSuchLayoutSetPrototypeException, SystemException {
715                    List<LayoutSetPrototype> list = findByUuid(uuid, 0, 1, orderByComparator);
716    
717                    if (list.isEmpty()) {
718                            StringBundler msg = new StringBundler(4);
719    
720                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
721    
722                            msg.append("uuid=");
723                            msg.append(uuid);
724    
725                            msg.append(StringPool.CLOSE_CURLY_BRACE);
726    
727                            throw new NoSuchLayoutSetPrototypeException(msg.toString());
728                    }
729                    else {
730                            return list.get(0);
731                    }
732            }
733    
734            /**
735             * Returns the last layout set prototype in the ordered set where uuid = &#63;.
736             *
737             * <p>
738             * 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.
739             * </p>
740             *
741             * @param uuid the uuid
742             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
743             * @return the last matching layout set prototype
744             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
745             * @throws SystemException if a system exception occurred
746             */
747            public LayoutSetPrototype findByUuid_Last(String uuid,
748                    OrderByComparator orderByComparator)
749                    throws NoSuchLayoutSetPrototypeException, SystemException {
750                    int count = countByUuid(uuid);
751    
752                    List<LayoutSetPrototype> list = findByUuid(uuid, count - 1, count,
753                                    orderByComparator);
754    
755                    if (list.isEmpty()) {
756                            StringBundler msg = new StringBundler(4);
757    
758                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
759    
760                            msg.append("uuid=");
761                            msg.append(uuid);
762    
763                            msg.append(StringPool.CLOSE_CURLY_BRACE);
764    
765                            throw new NoSuchLayoutSetPrototypeException(msg.toString());
766                    }
767                    else {
768                            return list.get(0);
769                    }
770            }
771    
772            /**
773             * Returns the layout set prototypes before and after the current layout set prototype in the ordered set where uuid = &#63;.
774             *
775             * <p>
776             * 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.
777             * </p>
778             *
779             * @param layoutSetPrototypeId the primary key of the current layout set prototype
780             * @param uuid the uuid
781             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
782             * @return the previous, current, and next layout set prototype
783             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
784             * @throws SystemException if a system exception occurred
785             */
786            public LayoutSetPrototype[] findByUuid_PrevAndNext(
787                    long layoutSetPrototypeId, String uuid,
788                    OrderByComparator orderByComparator)
789                    throws NoSuchLayoutSetPrototypeException, SystemException {
790                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
791    
792                    Session session = null;
793    
794                    try {
795                            session = openSession();
796    
797                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
798    
799                            array[0] = getByUuid_PrevAndNext(session, layoutSetPrototype, uuid,
800                                            orderByComparator, true);
801    
802                            array[1] = layoutSetPrototype;
803    
804                            array[2] = getByUuid_PrevAndNext(session, layoutSetPrototype, uuid,
805                                            orderByComparator, false);
806    
807                            return array;
808                    }
809                    catch (Exception e) {
810                            throw processException(e);
811                    }
812                    finally {
813                            closeSession(session);
814                    }
815            }
816    
817            protected LayoutSetPrototype getByUuid_PrevAndNext(Session session,
818                    LayoutSetPrototype layoutSetPrototype, String uuid,
819                    OrderByComparator orderByComparator, boolean previous) {
820                    StringBundler query = null;
821    
822                    if (orderByComparator != null) {
823                            query = new StringBundler(6 +
824                                            (orderByComparator.getOrderByFields().length * 6));
825                    }
826                    else {
827                            query = new StringBundler(3);
828                    }
829    
830                    query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
831    
832                    if (uuid == null) {
833                            query.append(_FINDER_COLUMN_UUID_UUID_1);
834                    }
835                    else {
836                            if (uuid.equals(StringPool.BLANK)) {
837                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
838                            }
839                            else {
840                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
841                            }
842                    }
843    
844                    if (orderByComparator != null) {
845                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
846    
847                            if (orderByConditionFields.length > 0) {
848                                    query.append(WHERE_AND);
849                            }
850    
851                            for (int i = 0; i < orderByConditionFields.length; i++) {
852                                    query.append(_ORDER_BY_ENTITY_ALIAS);
853                                    query.append(orderByConditionFields[i]);
854    
855                                    if ((i + 1) < orderByConditionFields.length) {
856                                            if (orderByComparator.isAscending() ^ previous) {
857                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
858                                            }
859                                            else {
860                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
861                                            }
862                                    }
863                                    else {
864                                            if (orderByComparator.isAscending() ^ previous) {
865                                                    query.append(WHERE_GREATER_THAN);
866                                            }
867                                            else {
868                                                    query.append(WHERE_LESSER_THAN);
869                                            }
870                                    }
871                            }
872    
873                            query.append(ORDER_BY_CLAUSE);
874    
875                            String[] orderByFields = orderByComparator.getOrderByFields();
876    
877                            for (int i = 0; i < orderByFields.length; i++) {
878                                    query.append(_ORDER_BY_ENTITY_ALIAS);
879                                    query.append(orderByFields[i]);
880    
881                                    if ((i + 1) < orderByFields.length) {
882                                            if (orderByComparator.isAscending() ^ previous) {
883                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
884                                            }
885                                            else {
886                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
887                                            }
888                                    }
889                                    else {
890                                            if (orderByComparator.isAscending() ^ previous) {
891                                                    query.append(ORDER_BY_ASC);
892                                            }
893                                            else {
894                                                    query.append(ORDER_BY_DESC);
895                                            }
896                                    }
897                            }
898                    }
899    
900                    String sql = query.toString();
901    
902                    Query q = session.createQuery(sql);
903    
904                    q.setFirstResult(0);
905                    q.setMaxResults(2);
906    
907                    QueryPos qPos = QueryPos.getInstance(q);
908    
909                    if (uuid != null) {
910                            qPos.add(uuid);
911                    }
912    
913                    if (orderByComparator != null) {
914                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetPrototype);
915    
916                            for (Object value : values) {
917                                    qPos.add(value);
918                            }
919                    }
920    
921                    List<LayoutSetPrototype> list = q.list();
922    
923                    if (list.size() == 2) {
924                            return list.get(1);
925                    }
926                    else {
927                            return null;
928                    }
929            }
930    
931            /**
932             * Returns all the layout set prototypes that the user has permission to view where uuid = &#63;.
933             *
934             * @param uuid the uuid
935             * @return the matching layout set prototypes that the user has permission to view
936             * @throws SystemException if a system exception occurred
937             */
938            public List<LayoutSetPrototype> filterFindByUuid(String uuid)
939                    throws SystemException {
940                    return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
941            }
942    
943            /**
944             * Returns a range of all the layout set prototypes that the user has permission to view where uuid = &#63;.
945             *
946             * <p>
947             * 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.
948             * </p>
949             *
950             * @param uuid the uuid
951             * @param start the lower bound of the range of layout set prototypes
952             * @param end the upper bound of the range of layout set prototypes (not inclusive)
953             * @return the range of matching layout set prototypes that the user has permission to view
954             * @throws SystemException if a system exception occurred
955             */
956            public List<LayoutSetPrototype> filterFindByUuid(String uuid, int start,
957                    int end) throws SystemException {
958                    return filterFindByUuid(uuid, start, end, null);
959            }
960    
961            /**
962             * Returns an ordered range of all the layout set prototypes that the user has permissions to view where uuid = &#63;.
963             *
964             * <p>
965             * 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.
966             * </p>
967             *
968             * @param uuid the uuid
969             * @param start the lower bound of the range of layout set prototypes
970             * @param end the upper bound of the range of layout set prototypes (not inclusive)
971             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
972             * @return the ordered range of matching layout set prototypes that the user has permission to view
973             * @throws SystemException if a system exception occurred
974             */
975            public List<LayoutSetPrototype> filterFindByUuid(String uuid, int start,
976                    int end, OrderByComparator orderByComparator) throws SystemException {
977                    if (!InlineSQLHelperUtil.isEnabled()) {
978                            return findByUuid(uuid, start, end, orderByComparator);
979                    }
980    
981                    StringBundler query = null;
982    
983                    if (orderByComparator != null) {
984                            query = new StringBundler(3 +
985                                            (orderByComparator.getOrderByFields().length * 3));
986                    }
987                    else {
988                            query = new StringBundler(2);
989                    }
990    
991                    if (getDB().isSupportsInlineDistinct()) {
992                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
993                    }
994                    else {
995                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
996                    }
997    
998                    if (uuid == null) {
999                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1000                    }
1001                    else {
1002                            if (uuid.equals(StringPool.BLANK)) {
1003                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1004                            }
1005                            else {
1006                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1007                            }
1008                    }
1009    
1010                    if (!getDB().isSupportsInlineDistinct()) {
1011                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
1012                    }
1013    
1014                    if (orderByComparator != null) {
1015                            if (getDB().isSupportsInlineDistinct()) {
1016                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1017                                            orderByComparator);
1018                            }
1019                            else {
1020                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1021                                            orderByComparator);
1022                            }
1023                    }
1024    
1025                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1026                                    LayoutSetPrototype.class.getName(),
1027                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1028    
1029                    Session session = null;
1030    
1031                    try {
1032                            session = openSession();
1033    
1034                            SQLQuery q = session.createSQLQuery(sql);
1035    
1036                            if (getDB().isSupportsInlineDistinct()) {
1037                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetPrototypeImpl.class);
1038                            }
1039                            else {
1040                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetPrototypeImpl.class);
1041                            }
1042    
1043                            QueryPos qPos = QueryPos.getInstance(q);
1044    
1045                            if (uuid != null) {
1046                                    qPos.add(uuid);
1047                            }
1048    
1049                            return (List<LayoutSetPrototype>)QueryUtil.list(q, getDialect(),
1050                                    start, end);
1051                    }
1052                    catch (Exception e) {
1053                            throw processException(e);
1054                    }
1055                    finally {
1056                            closeSession(session);
1057                    }
1058            }
1059    
1060            /**
1061             * Returns the layout set prototypes before and after the current layout set prototype in the ordered set of layout set prototypes that the user has permission to view where uuid = &#63;.
1062             *
1063             * @param layoutSetPrototypeId the primary key of the current layout set prototype
1064             * @param uuid the uuid
1065             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1066             * @return the previous, current, and next layout set prototype
1067             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
1068             * @throws SystemException if a system exception occurred
1069             */
1070            public LayoutSetPrototype[] filterFindByUuid_PrevAndNext(
1071                    long layoutSetPrototypeId, String uuid,
1072                    OrderByComparator orderByComparator)
1073                    throws NoSuchLayoutSetPrototypeException, SystemException {
1074                    if (!InlineSQLHelperUtil.isEnabled()) {
1075                            return findByUuid_PrevAndNext(layoutSetPrototypeId, uuid,
1076                                    orderByComparator);
1077                    }
1078    
1079                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
1080    
1081                    Session session = null;
1082    
1083                    try {
1084                            session = openSession();
1085    
1086                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
1087    
1088                            array[0] = filterGetByUuid_PrevAndNext(session, layoutSetPrototype,
1089                                            uuid, orderByComparator, true);
1090    
1091                            array[1] = layoutSetPrototype;
1092    
1093                            array[2] = filterGetByUuid_PrevAndNext(session, layoutSetPrototype,
1094                                            uuid, orderByComparator, false);
1095    
1096                            return array;
1097                    }
1098                    catch (Exception e) {
1099                            throw processException(e);
1100                    }
1101                    finally {
1102                            closeSession(session);
1103                    }
1104            }
1105    
1106            protected LayoutSetPrototype filterGetByUuid_PrevAndNext(Session session,
1107                    LayoutSetPrototype layoutSetPrototype, String uuid,
1108                    OrderByComparator orderByComparator, boolean previous) {
1109                    StringBundler query = null;
1110    
1111                    if (orderByComparator != null) {
1112                            query = new StringBundler(6 +
1113                                            (orderByComparator.getOrderByFields().length * 6));
1114                    }
1115                    else {
1116                            query = new StringBundler(3);
1117                    }
1118    
1119                    if (getDB().isSupportsInlineDistinct()) {
1120                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
1121                    }
1122                    else {
1123                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
1124                    }
1125    
1126                    if (uuid == null) {
1127                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1128                    }
1129                    else {
1130                            if (uuid.equals(StringPool.BLANK)) {
1131                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1132                            }
1133                            else {
1134                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1135                            }
1136                    }
1137    
1138                    if (!getDB().isSupportsInlineDistinct()) {
1139                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
1140                    }
1141    
1142                    if (orderByComparator != null) {
1143                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1144    
1145                            if (orderByConditionFields.length > 0) {
1146                                    query.append(WHERE_AND);
1147                            }
1148    
1149                            for (int i = 0; i < orderByConditionFields.length; i++) {
1150                                    if (getDB().isSupportsInlineDistinct()) {
1151                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1152                                    }
1153                                    else {
1154                                            query.append(_ORDER_BY_ENTITY_TABLE);
1155                                    }
1156    
1157                                    query.append(orderByConditionFields[i]);
1158    
1159                                    if ((i + 1) < orderByConditionFields.length) {
1160                                            if (orderByComparator.isAscending() ^ previous) {
1161                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1162                                            }
1163                                            else {
1164                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1165                                            }
1166                                    }
1167                                    else {
1168                                            if (orderByComparator.isAscending() ^ previous) {
1169                                                    query.append(WHERE_GREATER_THAN);
1170                                            }
1171                                            else {
1172                                                    query.append(WHERE_LESSER_THAN);
1173                                            }
1174                                    }
1175                            }
1176    
1177                            query.append(ORDER_BY_CLAUSE);
1178    
1179                            String[] orderByFields = orderByComparator.getOrderByFields();
1180    
1181                            for (int i = 0; i < orderByFields.length; i++) {
1182                                    if (getDB().isSupportsInlineDistinct()) {
1183                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1184                                    }
1185                                    else {
1186                                            query.append(_ORDER_BY_ENTITY_TABLE);
1187                                    }
1188    
1189                                    query.append(orderByFields[i]);
1190    
1191                                    if ((i + 1) < orderByFields.length) {
1192                                            if (orderByComparator.isAscending() ^ previous) {
1193                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1194                                            }
1195                                            else {
1196                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1197                                            }
1198                                    }
1199                                    else {
1200                                            if (orderByComparator.isAscending() ^ previous) {
1201                                                    query.append(ORDER_BY_ASC);
1202                                            }
1203                                            else {
1204                                                    query.append(ORDER_BY_DESC);
1205                                            }
1206                                    }
1207                            }
1208                    }
1209    
1210                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1211                                    LayoutSetPrototype.class.getName(),
1212                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1213    
1214                    SQLQuery q = session.createSQLQuery(sql);
1215    
1216                    q.setFirstResult(0);
1217                    q.setMaxResults(2);
1218    
1219                    if (getDB().isSupportsInlineDistinct()) {
1220                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetPrototypeImpl.class);
1221                    }
1222                    else {
1223                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetPrototypeImpl.class);
1224                    }
1225    
1226                    QueryPos qPos = QueryPos.getInstance(q);
1227    
1228                    if (uuid != null) {
1229                            qPos.add(uuid);
1230                    }
1231    
1232                    if (orderByComparator != null) {
1233                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetPrototype);
1234    
1235                            for (Object value : values) {
1236                                    qPos.add(value);
1237                            }
1238                    }
1239    
1240                    List<LayoutSetPrototype> list = q.list();
1241    
1242                    if (list.size() == 2) {
1243                            return list.get(1);
1244                    }
1245                    else {
1246                            return null;
1247                    }
1248            }
1249    
1250            /**
1251             * Returns all the layout set prototypes where companyId = &#63;.
1252             *
1253             * @param companyId the company ID
1254             * @return the matching layout set prototypes
1255             * @throws SystemException if a system exception occurred
1256             */
1257            public List<LayoutSetPrototype> findByCompanyId(long companyId)
1258                    throws SystemException {
1259                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1260                            null);
1261            }
1262    
1263            /**
1264             * Returns a range of all the layout set prototypes where companyId = &#63;.
1265             *
1266             * <p>
1267             * 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.
1268             * </p>
1269             *
1270             * @param companyId the company ID
1271             * @param start the lower bound of the range of layout set prototypes
1272             * @param end the upper bound of the range of layout set prototypes (not inclusive)
1273             * @return the range of matching layout set prototypes
1274             * @throws SystemException if a system exception occurred
1275             */
1276            public List<LayoutSetPrototype> findByCompanyId(long companyId, int start,
1277                    int end) throws SystemException {
1278                    return findByCompanyId(companyId, start, end, null);
1279            }
1280    
1281            /**
1282             * Returns an ordered range of all the layout set prototypes where companyId = &#63;.
1283             *
1284             * <p>
1285             * 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.
1286             * </p>
1287             *
1288             * @param companyId the company ID
1289             * @param start the lower bound of the range of layout set prototypes
1290             * @param end the upper bound of the range of layout set prototypes (not inclusive)
1291             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1292             * @return the ordered range of matching layout set prototypes
1293             * @throws SystemException if a system exception occurred
1294             */
1295            public List<LayoutSetPrototype> findByCompanyId(long companyId, int start,
1296                    int end, OrderByComparator orderByComparator) throws SystemException {
1297                    FinderPath finderPath = null;
1298                    Object[] finderArgs = null;
1299    
1300                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1301                                    (orderByComparator == null)) {
1302                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1303                            finderArgs = new Object[] { companyId };
1304                    }
1305                    else {
1306                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1307                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1308                    }
1309    
1310                    List<LayoutSetPrototype> list = (List<LayoutSetPrototype>)FinderCacheUtil.getResult(finderPath,
1311                                    finderArgs, this);
1312    
1313                    if ((list != null) && !list.isEmpty()) {
1314                            for (LayoutSetPrototype layoutSetPrototype : list) {
1315                                    if ((companyId != layoutSetPrototype.getCompanyId())) {
1316                                            list = null;
1317    
1318                                            break;
1319                                    }
1320                            }
1321                    }
1322    
1323                    if (list == null) {
1324                            StringBundler query = null;
1325    
1326                            if (orderByComparator != null) {
1327                                    query = new StringBundler(3 +
1328                                                    (orderByComparator.getOrderByFields().length * 3));
1329                            }
1330                            else {
1331                                    query = new StringBundler(2);
1332                            }
1333    
1334                            query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
1335    
1336                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1337    
1338                            if (orderByComparator != null) {
1339                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1340                                            orderByComparator);
1341                            }
1342    
1343                            String sql = query.toString();
1344    
1345                            Session session = null;
1346    
1347                            try {
1348                                    session = openSession();
1349    
1350                                    Query q = session.createQuery(sql);
1351    
1352                                    QueryPos qPos = QueryPos.getInstance(q);
1353    
1354                                    qPos.add(companyId);
1355    
1356                                    list = (List<LayoutSetPrototype>)QueryUtil.list(q,
1357                                                    getDialect(), start, end);
1358                            }
1359                            catch (Exception e) {
1360                                    throw processException(e);
1361                            }
1362                            finally {
1363                                    if (list == null) {
1364                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1365                                    }
1366                                    else {
1367                                            cacheResult(list);
1368    
1369                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1370                                    }
1371    
1372                                    closeSession(session);
1373                            }
1374                    }
1375    
1376                    return list;
1377            }
1378    
1379            /**
1380             * Returns the first layout set prototype in the ordered set where companyId = &#63;.
1381             *
1382             * <p>
1383             * 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.
1384             * </p>
1385             *
1386             * @param companyId the company ID
1387             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1388             * @return the first matching layout set prototype
1389             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
1390             * @throws SystemException if a system exception occurred
1391             */
1392            public LayoutSetPrototype findByCompanyId_First(long companyId,
1393                    OrderByComparator orderByComparator)
1394                    throws NoSuchLayoutSetPrototypeException, SystemException {
1395                    List<LayoutSetPrototype> list = findByCompanyId(companyId, 0, 1,
1396                                    orderByComparator);
1397    
1398                    if (list.isEmpty()) {
1399                            StringBundler msg = new StringBundler(4);
1400    
1401                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1402    
1403                            msg.append("companyId=");
1404                            msg.append(companyId);
1405    
1406                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1407    
1408                            throw new NoSuchLayoutSetPrototypeException(msg.toString());
1409                    }
1410                    else {
1411                            return list.get(0);
1412                    }
1413            }
1414    
1415            /**
1416             * Returns the last layout set prototype in the ordered set where companyId = &#63;.
1417             *
1418             * <p>
1419             * 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.
1420             * </p>
1421             *
1422             * @param companyId the company ID
1423             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1424             * @return the last matching layout set prototype
1425             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
1426             * @throws SystemException if a system exception occurred
1427             */
1428            public LayoutSetPrototype findByCompanyId_Last(long companyId,
1429                    OrderByComparator orderByComparator)
1430                    throws NoSuchLayoutSetPrototypeException, SystemException {
1431                    int count = countByCompanyId(companyId);
1432    
1433                    List<LayoutSetPrototype> list = findByCompanyId(companyId, count - 1,
1434                                    count, orderByComparator);
1435    
1436                    if (list.isEmpty()) {
1437                            StringBundler msg = new StringBundler(4);
1438    
1439                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1440    
1441                            msg.append("companyId=");
1442                            msg.append(companyId);
1443    
1444                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1445    
1446                            throw new NoSuchLayoutSetPrototypeException(msg.toString());
1447                    }
1448                    else {
1449                            return list.get(0);
1450                    }
1451            }
1452    
1453            /**
1454             * Returns the layout set prototypes before and after the current layout set prototype in the ordered set where companyId = &#63;.
1455             *
1456             * <p>
1457             * 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.
1458             * </p>
1459             *
1460             * @param layoutSetPrototypeId the primary key of the current layout set prototype
1461             * @param companyId the company ID
1462             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1463             * @return the previous, current, and next layout set prototype
1464             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
1465             * @throws SystemException if a system exception occurred
1466             */
1467            public LayoutSetPrototype[] findByCompanyId_PrevAndNext(
1468                    long layoutSetPrototypeId, long companyId,
1469                    OrderByComparator orderByComparator)
1470                    throws NoSuchLayoutSetPrototypeException, SystemException {
1471                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
1472    
1473                    Session session = null;
1474    
1475                    try {
1476                            session = openSession();
1477    
1478                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
1479    
1480                            array[0] = getByCompanyId_PrevAndNext(session, layoutSetPrototype,
1481                                            companyId, orderByComparator, true);
1482    
1483                            array[1] = layoutSetPrototype;
1484    
1485                            array[2] = getByCompanyId_PrevAndNext(session, layoutSetPrototype,
1486                                            companyId, orderByComparator, false);
1487    
1488                            return array;
1489                    }
1490                    catch (Exception e) {
1491                            throw processException(e);
1492                    }
1493                    finally {
1494                            closeSession(session);
1495                    }
1496            }
1497    
1498            protected LayoutSetPrototype getByCompanyId_PrevAndNext(Session session,
1499                    LayoutSetPrototype layoutSetPrototype, long companyId,
1500                    OrderByComparator orderByComparator, boolean previous) {
1501                    StringBundler query = null;
1502    
1503                    if (orderByComparator != null) {
1504                            query = new StringBundler(6 +
1505                                            (orderByComparator.getOrderByFields().length * 6));
1506                    }
1507                    else {
1508                            query = new StringBundler(3);
1509                    }
1510    
1511                    query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
1512    
1513                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1514    
1515                    if (orderByComparator != null) {
1516                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1517    
1518                            if (orderByConditionFields.length > 0) {
1519                                    query.append(WHERE_AND);
1520                            }
1521    
1522                            for (int i = 0; i < orderByConditionFields.length; i++) {
1523                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1524                                    query.append(orderByConditionFields[i]);
1525    
1526                                    if ((i + 1) < orderByConditionFields.length) {
1527                                            if (orderByComparator.isAscending() ^ previous) {
1528                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1529                                            }
1530                                            else {
1531                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1532                                            }
1533                                    }
1534                                    else {
1535                                            if (orderByComparator.isAscending() ^ previous) {
1536                                                    query.append(WHERE_GREATER_THAN);
1537                                            }
1538                                            else {
1539                                                    query.append(WHERE_LESSER_THAN);
1540                                            }
1541                                    }
1542                            }
1543    
1544                            query.append(ORDER_BY_CLAUSE);
1545    
1546                            String[] orderByFields = orderByComparator.getOrderByFields();
1547    
1548                            for (int i = 0; i < orderByFields.length; i++) {
1549                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1550                                    query.append(orderByFields[i]);
1551    
1552                                    if ((i + 1) < orderByFields.length) {
1553                                            if (orderByComparator.isAscending() ^ previous) {
1554                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1555                                            }
1556                                            else {
1557                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1558                                            }
1559                                    }
1560                                    else {
1561                                            if (orderByComparator.isAscending() ^ previous) {
1562                                                    query.append(ORDER_BY_ASC);
1563                                            }
1564                                            else {
1565                                                    query.append(ORDER_BY_DESC);
1566                                            }
1567                                    }
1568                            }
1569                    }
1570    
1571                    String sql = query.toString();
1572    
1573                    Query q = session.createQuery(sql);
1574    
1575                    q.setFirstResult(0);
1576                    q.setMaxResults(2);
1577    
1578                    QueryPos qPos = QueryPos.getInstance(q);
1579    
1580                    qPos.add(companyId);
1581    
1582                    if (orderByComparator != null) {
1583                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetPrototype);
1584    
1585                            for (Object value : values) {
1586                                    qPos.add(value);
1587                            }
1588                    }
1589    
1590                    List<LayoutSetPrototype> list = q.list();
1591    
1592                    if (list.size() == 2) {
1593                            return list.get(1);
1594                    }
1595                    else {
1596                            return null;
1597                    }
1598            }
1599    
1600            /**
1601             * Returns all the layout set prototypes that the user has permission to view where companyId = &#63;.
1602             *
1603             * @param companyId the company ID
1604             * @return the matching layout set prototypes that the user has permission to view
1605             * @throws SystemException if a system exception occurred
1606             */
1607            public List<LayoutSetPrototype> filterFindByCompanyId(long companyId)
1608                    throws SystemException {
1609                    return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
1610                            QueryUtil.ALL_POS, null);
1611            }
1612    
1613            /**
1614             * Returns a range of all the layout set prototypes that the user has permission to view where companyId = &#63;.
1615             *
1616             * <p>
1617             * 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.
1618             * </p>
1619             *
1620             * @param companyId the company ID
1621             * @param start the lower bound of the range of layout set prototypes
1622             * @param end the upper bound of the range of layout set prototypes (not inclusive)
1623             * @return the range of matching layout set prototypes that the user has permission to view
1624             * @throws SystemException if a system exception occurred
1625             */
1626            public List<LayoutSetPrototype> filterFindByCompanyId(long companyId,
1627                    int start, int end) throws SystemException {
1628                    return filterFindByCompanyId(companyId, start, end, null);
1629            }
1630    
1631            /**
1632             * Returns an ordered range of all the layout set prototypes that the user has permissions to view where companyId = &#63;.
1633             *
1634             * <p>
1635             * 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.
1636             * </p>
1637             *
1638             * @param companyId the company ID
1639             * @param start the lower bound of the range of layout set prototypes
1640             * @param end the upper bound of the range of layout set prototypes (not inclusive)
1641             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1642             * @return the ordered range of matching layout set prototypes that the user has permission to view
1643             * @throws SystemException if a system exception occurred
1644             */
1645            public List<LayoutSetPrototype> filterFindByCompanyId(long companyId,
1646                    int start, int end, OrderByComparator orderByComparator)
1647                    throws SystemException {
1648                    if (!InlineSQLHelperUtil.isEnabled()) {
1649                            return findByCompanyId(companyId, start, end, orderByComparator);
1650                    }
1651    
1652                    StringBundler query = null;
1653    
1654                    if (orderByComparator != null) {
1655                            query = new StringBundler(3 +
1656                                            (orderByComparator.getOrderByFields().length * 3));
1657                    }
1658                    else {
1659                            query = new StringBundler(2);
1660                    }
1661    
1662                    if (getDB().isSupportsInlineDistinct()) {
1663                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
1664                    }
1665                    else {
1666                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
1667                    }
1668    
1669                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1670    
1671                    if (!getDB().isSupportsInlineDistinct()) {
1672                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
1673                    }
1674    
1675                    if (orderByComparator != null) {
1676                            if (getDB().isSupportsInlineDistinct()) {
1677                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1678                                            orderByComparator);
1679                            }
1680                            else {
1681                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1682                                            orderByComparator);
1683                            }
1684                    }
1685    
1686                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1687                                    LayoutSetPrototype.class.getName(),
1688                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1689    
1690                    Session session = null;
1691    
1692                    try {
1693                            session = openSession();
1694    
1695                            SQLQuery q = session.createSQLQuery(sql);
1696    
1697                            if (getDB().isSupportsInlineDistinct()) {
1698                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetPrototypeImpl.class);
1699                            }
1700                            else {
1701                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetPrototypeImpl.class);
1702                            }
1703    
1704                            QueryPos qPos = QueryPos.getInstance(q);
1705    
1706                            qPos.add(companyId);
1707    
1708                            return (List<LayoutSetPrototype>)QueryUtil.list(q, getDialect(),
1709                                    start, end);
1710                    }
1711                    catch (Exception e) {
1712                            throw processException(e);
1713                    }
1714                    finally {
1715                            closeSession(session);
1716                    }
1717            }
1718    
1719            /**
1720             * Returns the layout set prototypes before and after the current layout set prototype in the ordered set of layout set prototypes that the user has permission to view where companyId = &#63;.
1721             *
1722             * @param layoutSetPrototypeId the primary key of the current layout set prototype
1723             * @param companyId the company ID
1724             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1725             * @return the previous, current, and next layout set prototype
1726             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
1727             * @throws SystemException if a system exception occurred
1728             */
1729            public LayoutSetPrototype[] filterFindByCompanyId_PrevAndNext(
1730                    long layoutSetPrototypeId, long companyId,
1731                    OrderByComparator orderByComparator)
1732                    throws NoSuchLayoutSetPrototypeException, SystemException {
1733                    if (!InlineSQLHelperUtil.isEnabled()) {
1734                            return findByCompanyId_PrevAndNext(layoutSetPrototypeId, companyId,
1735                                    orderByComparator);
1736                    }
1737    
1738                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
1739    
1740                    Session session = null;
1741    
1742                    try {
1743                            session = openSession();
1744    
1745                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
1746    
1747                            array[0] = filterGetByCompanyId_PrevAndNext(session,
1748                                            layoutSetPrototype, companyId, orderByComparator, true);
1749    
1750                            array[1] = layoutSetPrototype;
1751    
1752                            array[2] = filterGetByCompanyId_PrevAndNext(session,
1753                                            layoutSetPrototype, companyId, orderByComparator, false);
1754    
1755                            return array;
1756                    }
1757                    catch (Exception e) {
1758                            throw processException(e);
1759                    }
1760                    finally {
1761                            closeSession(session);
1762                    }
1763            }
1764    
1765            protected LayoutSetPrototype filterGetByCompanyId_PrevAndNext(
1766                    Session session, LayoutSetPrototype layoutSetPrototype, long companyId,
1767                    OrderByComparator orderByComparator, boolean previous) {
1768                    StringBundler query = null;
1769    
1770                    if (orderByComparator != null) {
1771                            query = new StringBundler(6 +
1772                                            (orderByComparator.getOrderByFields().length * 6));
1773                    }
1774                    else {
1775                            query = new StringBundler(3);
1776                    }
1777    
1778                    if (getDB().isSupportsInlineDistinct()) {
1779                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
1780                    }
1781                    else {
1782                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
1783                    }
1784    
1785                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1786    
1787                    if (!getDB().isSupportsInlineDistinct()) {
1788                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
1789                    }
1790    
1791                    if (orderByComparator != null) {
1792                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1793    
1794                            if (orderByConditionFields.length > 0) {
1795                                    query.append(WHERE_AND);
1796                            }
1797    
1798                            for (int i = 0; i < orderByConditionFields.length; i++) {
1799                                    if (getDB().isSupportsInlineDistinct()) {
1800                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1801                                    }
1802                                    else {
1803                                            query.append(_ORDER_BY_ENTITY_TABLE);
1804                                    }
1805    
1806                                    query.append(orderByConditionFields[i]);
1807    
1808                                    if ((i + 1) < orderByConditionFields.length) {
1809                                            if (orderByComparator.isAscending() ^ previous) {
1810                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1811                                            }
1812                                            else {
1813                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1814                                            }
1815                                    }
1816                                    else {
1817                                            if (orderByComparator.isAscending() ^ previous) {
1818                                                    query.append(WHERE_GREATER_THAN);
1819                                            }
1820                                            else {
1821                                                    query.append(WHERE_LESSER_THAN);
1822                                            }
1823                                    }
1824                            }
1825    
1826                            query.append(ORDER_BY_CLAUSE);
1827    
1828                            String[] orderByFields = orderByComparator.getOrderByFields();
1829    
1830                            for (int i = 0; i < orderByFields.length; i++) {
1831                                    if (getDB().isSupportsInlineDistinct()) {
1832                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1833                                    }
1834                                    else {
1835                                            query.append(_ORDER_BY_ENTITY_TABLE);
1836                                    }
1837    
1838                                    query.append(orderByFields[i]);
1839    
1840                                    if ((i + 1) < orderByFields.length) {
1841                                            if (orderByComparator.isAscending() ^ previous) {
1842                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1843                                            }
1844                                            else {
1845                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1846                                            }
1847                                    }
1848                                    else {
1849                                            if (orderByComparator.isAscending() ^ previous) {
1850                                                    query.append(ORDER_BY_ASC);
1851                                            }
1852                                            else {
1853                                                    query.append(ORDER_BY_DESC);
1854                                            }
1855                                    }
1856                            }
1857                    }
1858    
1859                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1860                                    LayoutSetPrototype.class.getName(),
1861                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1862    
1863                    SQLQuery q = session.createSQLQuery(sql);
1864    
1865                    q.setFirstResult(0);
1866                    q.setMaxResults(2);
1867    
1868                    if (getDB().isSupportsInlineDistinct()) {
1869                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetPrototypeImpl.class);
1870                    }
1871                    else {
1872                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetPrototypeImpl.class);
1873                    }
1874    
1875                    QueryPos qPos = QueryPos.getInstance(q);
1876    
1877                    qPos.add(companyId);
1878    
1879                    if (orderByComparator != null) {
1880                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetPrototype);
1881    
1882                            for (Object value : values) {
1883                                    qPos.add(value);
1884                            }
1885                    }
1886    
1887                    List<LayoutSetPrototype> list = q.list();
1888    
1889                    if (list.size() == 2) {
1890                            return list.get(1);
1891                    }
1892                    else {
1893                            return null;
1894                    }
1895            }
1896    
1897            /**
1898             * Returns all the layout set prototypes where companyId = &#63; and active = &#63;.
1899             *
1900             * @param companyId the company ID
1901             * @param active the active
1902             * @return the matching layout set prototypes
1903             * @throws SystemException if a system exception occurred
1904             */
1905            public List<LayoutSetPrototype> findByC_A(long companyId, boolean active)
1906                    throws SystemException {
1907                    return findByC_A(companyId, active, QueryUtil.ALL_POS,
1908                            QueryUtil.ALL_POS, null);
1909            }
1910    
1911            /**
1912             * Returns a range of all the layout set prototypes where companyId = &#63; and active = &#63;.
1913             *
1914             * <p>
1915             * 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.
1916             * </p>
1917             *
1918             * @param companyId the company ID
1919             * @param active the active
1920             * @param start the lower bound of the range of layout set prototypes
1921             * @param end the upper bound of the range of layout set prototypes (not inclusive)
1922             * @return the range of matching layout set prototypes
1923             * @throws SystemException if a system exception occurred
1924             */
1925            public List<LayoutSetPrototype> findByC_A(long companyId, boolean active,
1926                    int start, int end) throws SystemException {
1927                    return findByC_A(companyId, active, start, end, null);
1928            }
1929    
1930            /**
1931             * Returns an ordered range of all the layout set prototypes where companyId = &#63; and active = &#63;.
1932             *
1933             * <p>
1934             * 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.
1935             * </p>
1936             *
1937             * @param companyId the company ID
1938             * @param active the active
1939             * @param start the lower bound of the range of layout set prototypes
1940             * @param end the upper bound of the range of layout set prototypes (not inclusive)
1941             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1942             * @return the ordered range of matching layout set prototypes
1943             * @throws SystemException if a system exception occurred
1944             */
1945            public List<LayoutSetPrototype> findByC_A(long companyId, boolean active,
1946                    int start, int end, OrderByComparator orderByComparator)
1947                    throws SystemException {
1948                    FinderPath finderPath = null;
1949                    Object[] finderArgs = null;
1950    
1951                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1952                                    (orderByComparator == null)) {
1953                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A;
1954                            finderArgs = new Object[] { companyId, active };
1955                    }
1956                    else {
1957                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_A;
1958                            finderArgs = new Object[] {
1959                                            companyId, active,
1960                                            
1961                                            start, end, orderByComparator
1962                                    };
1963                    }
1964    
1965                    List<LayoutSetPrototype> list = (List<LayoutSetPrototype>)FinderCacheUtil.getResult(finderPath,
1966                                    finderArgs, this);
1967    
1968                    if ((list != null) && !list.isEmpty()) {
1969                            for (LayoutSetPrototype layoutSetPrototype : list) {
1970                                    if ((companyId != layoutSetPrototype.getCompanyId()) ||
1971                                                    (active != layoutSetPrototype.getActive())) {
1972                                            list = null;
1973    
1974                                            break;
1975                                    }
1976                            }
1977                    }
1978    
1979                    if (list == null) {
1980                            StringBundler query = null;
1981    
1982                            if (orderByComparator != null) {
1983                                    query = new StringBundler(4 +
1984                                                    (orderByComparator.getOrderByFields().length * 3));
1985                            }
1986                            else {
1987                                    query = new StringBundler(3);
1988                            }
1989    
1990                            query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
1991    
1992                            query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
1993    
1994                            query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
1995    
1996                            if (orderByComparator != null) {
1997                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1998                                            orderByComparator);
1999                            }
2000    
2001                            String sql = query.toString();
2002    
2003                            Session session = null;
2004    
2005                            try {
2006                                    session = openSession();
2007    
2008                                    Query q = session.createQuery(sql);
2009    
2010                                    QueryPos qPos = QueryPos.getInstance(q);
2011    
2012                                    qPos.add(companyId);
2013    
2014                                    qPos.add(active);
2015    
2016                                    list = (List<LayoutSetPrototype>)QueryUtil.list(q,
2017                                                    getDialect(), start, end);
2018                            }
2019                            catch (Exception e) {
2020                                    throw processException(e);
2021                            }
2022                            finally {
2023                                    if (list == null) {
2024                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2025                                    }
2026                                    else {
2027                                            cacheResult(list);
2028    
2029                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2030                                    }
2031    
2032                                    closeSession(session);
2033                            }
2034                    }
2035    
2036                    return list;
2037            }
2038    
2039            /**
2040             * Returns the first layout set prototype in the ordered set where companyId = &#63; and active = &#63;.
2041             *
2042             * <p>
2043             * 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.
2044             * </p>
2045             *
2046             * @param companyId the company ID
2047             * @param active the active
2048             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2049             * @return the first matching layout set prototype
2050             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
2051             * @throws SystemException if a system exception occurred
2052             */
2053            public LayoutSetPrototype findByC_A_First(long companyId, boolean active,
2054                    OrderByComparator orderByComparator)
2055                    throws NoSuchLayoutSetPrototypeException, SystemException {
2056                    List<LayoutSetPrototype> list = findByC_A(companyId, active, 0, 1,
2057                                    orderByComparator);
2058    
2059                    if (list.isEmpty()) {
2060                            StringBundler msg = new StringBundler(6);
2061    
2062                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2063    
2064                            msg.append("companyId=");
2065                            msg.append(companyId);
2066    
2067                            msg.append(", active=");
2068                            msg.append(active);
2069    
2070                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2071    
2072                            throw new NoSuchLayoutSetPrototypeException(msg.toString());
2073                    }
2074                    else {
2075                            return list.get(0);
2076                    }
2077            }
2078    
2079            /**
2080             * Returns the last layout set prototype in the ordered set where companyId = &#63; and active = &#63;.
2081             *
2082             * <p>
2083             * 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.
2084             * </p>
2085             *
2086             * @param companyId the company ID
2087             * @param active the active
2088             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2089             * @return the last matching layout set prototype
2090             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
2091             * @throws SystemException if a system exception occurred
2092             */
2093            public LayoutSetPrototype findByC_A_Last(long companyId, boolean active,
2094                    OrderByComparator orderByComparator)
2095                    throws NoSuchLayoutSetPrototypeException, SystemException {
2096                    int count = countByC_A(companyId, active);
2097    
2098                    List<LayoutSetPrototype> list = findByC_A(companyId, active, count - 1,
2099                                    count, orderByComparator);
2100    
2101                    if (list.isEmpty()) {
2102                            StringBundler msg = new StringBundler(6);
2103    
2104                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2105    
2106                            msg.append("companyId=");
2107                            msg.append(companyId);
2108    
2109                            msg.append(", active=");
2110                            msg.append(active);
2111    
2112                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2113    
2114                            throw new NoSuchLayoutSetPrototypeException(msg.toString());
2115                    }
2116                    else {
2117                            return list.get(0);
2118                    }
2119            }
2120    
2121            /**
2122             * Returns the layout set prototypes before and after the current layout set prototype in the ordered set where companyId = &#63; and active = &#63;.
2123             *
2124             * <p>
2125             * 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.
2126             * </p>
2127             *
2128             * @param layoutSetPrototypeId the primary key of the current layout set prototype
2129             * @param companyId the company ID
2130             * @param active the active
2131             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2132             * @return the previous, current, and next layout set prototype
2133             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
2134             * @throws SystemException if a system exception occurred
2135             */
2136            public LayoutSetPrototype[] findByC_A_PrevAndNext(
2137                    long layoutSetPrototypeId, long companyId, boolean active,
2138                    OrderByComparator orderByComparator)
2139                    throws NoSuchLayoutSetPrototypeException, SystemException {
2140                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
2141    
2142                    Session session = null;
2143    
2144                    try {
2145                            session = openSession();
2146    
2147                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
2148    
2149                            array[0] = getByC_A_PrevAndNext(session, layoutSetPrototype,
2150                                            companyId, active, orderByComparator, true);
2151    
2152                            array[1] = layoutSetPrototype;
2153    
2154                            array[2] = getByC_A_PrevAndNext(session, layoutSetPrototype,
2155                                            companyId, active, orderByComparator, false);
2156    
2157                            return array;
2158                    }
2159                    catch (Exception e) {
2160                            throw processException(e);
2161                    }
2162                    finally {
2163                            closeSession(session);
2164                    }
2165            }
2166    
2167            protected LayoutSetPrototype getByC_A_PrevAndNext(Session session,
2168                    LayoutSetPrototype layoutSetPrototype, long companyId, boolean active,
2169                    OrderByComparator orderByComparator, boolean previous) {
2170                    StringBundler query = null;
2171    
2172                    if (orderByComparator != null) {
2173                            query = new StringBundler(6 +
2174                                            (orderByComparator.getOrderByFields().length * 6));
2175                    }
2176                    else {
2177                            query = new StringBundler(3);
2178                    }
2179    
2180                    query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
2181    
2182                    query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
2183    
2184                    query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
2185    
2186                    if (orderByComparator != null) {
2187                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2188    
2189                            if (orderByConditionFields.length > 0) {
2190                                    query.append(WHERE_AND);
2191                            }
2192    
2193                            for (int i = 0; i < orderByConditionFields.length; i++) {
2194                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2195                                    query.append(orderByConditionFields[i]);
2196    
2197                                    if ((i + 1) < orderByConditionFields.length) {
2198                                            if (orderByComparator.isAscending() ^ previous) {
2199                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2200                                            }
2201                                            else {
2202                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2203                                            }
2204                                    }
2205                                    else {
2206                                            if (orderByComparator.isAscending() ^ previous) {
2207                                                    query.append(WHERE_GREATER_THAN);
2208                                            }
2209                                            else {
2210                                                    query.append(WHERE_LESSER_THAN);
2211                                            }
2212                                    }
2213                            }
2214    
2215                            query.append(ORDER_BY_CLAUSE);
2216    
2217                            String[] orderByFields = orderByComparator.getOrderByFields();
2218    
2219                            for (int i = 0; i < orderByFields.length; i++) {
2220                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2221                                    query.append(orderByFields[i]);
2222    
2223                                    if ((i + 1) < orderByFields.length) {
2224                                            if (orderByComparator.isAscending() ^ previous) {
2225                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2226                                            }
2227                                            else {
2228                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2229                                            }
2230                                    }
2231                                    else {
2232                                            if (orderByComparator.isAscending() ^ previous) {
2233                                                    query.append(ORDER_BY_ASC);
2234                                            }
2235                                            else {
2236                                                    query.append(ORDER_BY_DESC);
2237                                            }
2238                                    }
2239                            }
2240                    }
2241    
2242                    String sql = query.toString();
2243    
2244                    Query q = session.createQuery(sql);
2245    
2246                    q.setFirstResult(0);
2247                    q.setMaxResults(2);
2248    
2249                    QueryPos qPos = QueryPos.getInstance(q);
2250    
2251                    qPos.add(companyId);
2252    
2253                    qPos.add(active);
2254    
2255                    if (orderByComparator != null) {
2256                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetPrototype);
2257    
2258                            for (Object value : values) {
2259                                    qPos.add(value);
2260                            }
2261                    }
2262    
2263                    List<LayoutSetPrototype> list = q.list();
2264    
2265                    if (list.size() == 2) {
2266                            return list.get(1);
2267                    }
2268                    else {
2269                            return null;
2270                    }
2271            }
2272    
2273            /**
2274             * Returns all the layout set prototypes that the user has permission to view where companyId = &#63; and active = &#63;.
2275             *
2276             * @param companyId the company ID
2277             * @param active the active
2278             * @return the matching layout set prototypes that the user has permission to view
2279             * @throws SystemException if a system exception occurred
2280             */
2281            public List<LayoutSetPrototype> filterFindByC_A(long companyId,
2282                    boolean active) throws SystemException {
2283                    return filterFindByC_A(companyId, active, QueryUtil.ALL_POS,
2284                            QueryUtil.ALL_POS, null);
2285            }
2286    
2287            /**
2288             * Returns a range of all the layout set prototypes that the user has permission to view where companyId = &#63; and active = &#63;.
2289             *
2290             * <p>
2291             * 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.
2292             * </p>
2293             *
2294             * @param companyId the company ID
2295             * @param active the active
2296             * @param start the lower bound of the range of layout set prototypes
2297             * @param end the upper bound of the range of layout set prototypes (not inclusive)
2298             * @return the range of matching layout set prototypes that the user has permission to view
2299             * @throws SystemException if a system exception occurred
2300             */
2301            public List<LayoutSetPrototype> filterFindByC_A(long companyId,
2302                    boolean active, int start, int end) throws SystemException {
2303                    return filterFindByC_A(companyId, active, start, end, null);
2304            }
2305    
2306            /**
2307             * Returns an ordered range of all the layout set prototypes that the user has permissions to view where companyId = &#63; and active = &#63;.
2308             *
2309             * <p>
2310             * 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.
2311             * </p>
2312             *
2313             * @param companyId the company ID
2314             * @param active the active
2315             * @param start the lower bound of the range of layout set prototypes
2316             * @param end the upper bound of the range of layout set prototypes (not inclusive)
2317             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2318             * @return the ordered range of matching layout set prototypes that the user has permission to view
2319             * @throws SystemException if a system exception occurred
2320             */
2321            public List<LayoutSetPrototype> filterFindByC_A(long companyId,
2322                    boolean active, int start, int end, OrderByComparator orderByComparator)
2323                    throws SystemException {
2324                    if (!InlineSQLHelperUtil.isEnabled()) {
2325                            return findByC_A(companyId, active, start, end, orderByComparator);
2326                    }
2327    
2328                    StringBundler query = null;
2329    
2330                    if (orderByComparator != null) {
2331                            query = new StringBundler(4 +
2332                                            (orderByComparator.getOrderByFields().length * 3));
2333                    }
2334                    else {
2335                            query = new StringBundler(3);
2336                    }
2337    
2338                    if (getDB().isSupportsInlineDistinct()) {
2339                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
2340                    }
2341                    else {
2342                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
2343                    }
2344    
2345                    query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
2346    
2347                    query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
2348    
2349                    if (!getDB().isSupportsInlineDistinct()) {
2350                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
2351                    }
2352    
2353                    if (orderByComparator != null) {
2354                            if (getDB().isSupportsInlineDistinct()) {
2355                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2356                                            orderByComparator);
2357                            }
2358                            else {
2359                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2360                                            orderByComparator);
2361                            }
2362                    }
2363    
2364                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2365                                    LayoutSetPrototype.class.getName(),
2366                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2367    
2368                    Session session = null;
2369    
2370                    try {
2371                            session = openSession();
2372    
2373                            SQLQuery q = session.createSQLQuery(sql);
2374    
2375                            if (getDB().isSupportsInlineDistinct()) {
2376                                    q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetPrototypeImpl.class);
2377                            }
2378                            else {
2379                                    q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetPrototypeImpl.class);
2380                            }
2381    
2382                            QueryPos qPos = QueryPos.getInstance(q);
2383    
2384                            qPos.add(companyId);
2385    
2386                            qPos.add(active);
2387    
2388                            return (List<LayoutSetPrototype>)QueryUtil.list(q, getDialect(),
2389                                    start, end);
2390                    }
2391                    catch (Exception e) {
2392                            throw processException(e);
2393                    }
2394                    finally {
2395                            closeSession(session);
2396                    }
2397            }
2398    
2399            /**
2400             * Returns the layout set prototypes before and after the current layout set prototype in the ordered set of layout set prototypes that the user has permission to view where companyId = &#63; and active = &#63;.
2401             *
2402             * @param layoutSetPrototypeId the primary key of the current layout set prototype
2403             * @param companyId the company ID
2404             * @param active the active
2405             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2406             * @return the previous, current, and next layout set prototype
2407             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
2408             * @throws SystemException if a system exception occurred
2409             */
2410            public LayoutSetPrototype[] filterFindByC_A_PrevAndNext(
2411                    long layoutSetPrototypeId, long companyId, boolean active,
2412                    OrderByComparator orderByComparator)
2413                    throws NoSuchLayoutSetPrototypeException, SystemException {
2414                    if (!InlineSQLHelperUtil.isEnabled()) {
2415                            return findByC_A_PrevAndNext(layoutSetPrototypeId, companyId,
2416                                    active, orderByComparator);
2417                    }
2418    
2419                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
2420    
2421                    Session session = null;
2422    
2423                    try {
2424                            session = openSession();
2425    
2426                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
2427    
2428                            array[0] = filterGetByC_A_PrevAndNext(session, layoutSetPrototype,
2429                                            companyId, active, orderByComparator, true);
2430    
2431                            array[1] = layoutSetPrototype;
2432    
2433                            array[2] = filterGetByC_A_PrevAndNext(session, layoutSetPrototype,
2434                                            companyId, active, orderByComparator, false);
2435    
2436                            return array;
2437                    }
2438                    catch (Exception e) {
2439                            throw processException(e);
2440                    }
2441                    finally {
2442                            closeSession(session);
2443                    }
2444            }
2445    
2446            protected LayoutSetPrototype filterGetByC_A_PrevAndNext(Session session,
2447                    LayoutSetPrototype layoutSetPrototype, long companyId, boolean active,
2448                    OrderByComparator orderByComparator, boolean previous) {
2449                    StringBundler query = null;
2450    
2451                    if (orderByComparator != null) {
2452                            query = new StringBundler(6 +
2453                                            (orderByComparator.getOrderByFields().length * 6));
2454                    }
2455                    else {
2456                            query = new StringBundler(3);
2457                    }
2458    
2459                    if (getDB().isSupportsInlineDistinct()) {
2460                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
2461                    }
2462                    else {
2463                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1);
2464                    }
2465    
2466                    query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
2467    
2468                    query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
2469    
2470                    if (!getDB().isSupportsInlineDistinct()) {
2471                            query.append(_FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2);
2472                    }
2473    
2474                    if (orderByComparator != null) {
2475                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2476    
2477                            if (orderByConditionFields.length > 0) {
2478                                    query.append(WHERE_AND);
2479                            }
2480    
2481                            for (int i = 0; i < orderByConditionFields.length; i++) {
2482                                    if (getDB().isSupportsInlineDistinct()) {
2483                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2484                                    }
2485                                    else {
2486                                            query.append(_ORDER_BY_ENTITY_TABLE);
2487                                    }
2488    
2489                                    query.append(orderByConditionFields[i]);
2490    
2491                                    if ((i + 1) < orderByConditionFields.length) {
2492                                            if (orderByComparator.isAscending() ^ previous) {
2493                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2494                                            }
2495                                            else {
2496                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2497                                            }
2498                                    }
2499                                    else {
2500                                            if (orderByComparator.isAscending() ^ previous) {
2501                                                    query.append(WHERE_GREATER_THAN);
2502                                            }
2503                                            else {
2504                                                    query.append(WHERE_LESSER_THAN);
2505                                            }
2506                                    }
2507                            }
2508    
2509                            query.append(ORDER_BY_CLAUSE);
2510    
2511                            String[] orderByFields = orderByComparator.getOrderByFields();
2512    
2513                            for (int i = 0; i < orderByFields.length; i++) {
2514                                    if (getDB().isSupportsInlineDistinct()) {
2515                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2516                                    }
2517                                    else {
2518                                            query.append(_ORDER_BY_ENTITY_TABLE);
2519                                    }
2520    
2521                                    query.append(orderByFields[i]);
2522    
2523                                    if ((i + 1) < orderByFields.length) {
2524                                            if (orderByComparator.isAscending() ^ previous) {
2525                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2526                                            }
2527                                            else {
2528                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2529                                            }
2530                                    }
2531                                    else {
2532                                            if (orderByComparator.isAscending() ^ previous) {
2533                                                    query.append(ORDER_BY_ASC);
2534                                            }
2535                                            else {
2536                                                    query.append(ORDER_BY_DESC);
2537                                            }
2538                                    }
2539                            }
2540                    }
2541    
2542                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2543                                    LayoutSetPrototype.class.getName(),
2544                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2545    
2546                    SQLQuery q = session.createSQLQuery(sql);
2547    
2548                    q.setFirstResult(0);
2549                    q.setMaxResults(2);
2550    
2551                    if (getDB().isSupportsInlineDistinct()) {
2552                            q.addEntity(_FILTER_ENTITY_ALIAS, LayoutSetPrototypeImpl.class);
2553                    }
2554                    else {
2555                            q.addEntity(_FILTER_ENTITY_TABLE, LayoutSetPrototypeImpl.class);
2556                    }
2557    
2558                    QueryPos qPos = QueryPos.getInstance(q);
2559    
2560                    qPos.add(companyId);
2561    
2562                    qPos.add(active);
2563    
2564                    if (orderByComparator != null) {
2565                            Object[] values = orderByComparator.getOrderByConditionValues(layoutSetPrototype);
2566    
2567                            for (Object value : values) {
2568                                    qPos.add(value);
2569                            }
2570                    }
2571    
2572                    List<LayoutSetPrototype> list = q.list();
2573    
2574                    if (list.size() == 2) {
2575                            return list.get(1);
2576                    }
2577                    else {
2578                            return null;
2579                    }
2580            }
2581    
2582            /**
2583             * Returns all the layout set prototypes.
2584             *
2585             * @return the layout set prototypes
2586             * @throws SystemException if a system exception occurred
2587             */
2588            public List<LayoutSetPrototype> findAll() throws SystemException {
2589                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2590            }
2591    
2592            /**
2593             * Returns a range of all the layout set prototypes.
2594             *
2595             * <p>
2596             * 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.
2597             * </p>
2598             *
2599             * @param start the lower bound of the range of layout set prototypes
2600             * @param end the upper bound of the range of layout set prototypes (not inclusive)
2601             * @return the range of layout set prototypes
2602             * @throws SystemException if a system exception occurred
2603             */
2604            public List<LayoutSetPrototype> findAll(int start, int end)
2605                    throws SystemException {
2606                    return findAll(start, end, null);
2607            }
2608    
2609            /**
2610             * Returns an ordered range of all the layout set prototypes.
2611             *
2612             * <p>
2613             * 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.
2614             * </p>
2615             *
2616             * @param start the lower bound of the range of layout set prototypes
2617             * @param end the upper bound of the range of layout set prototypes (not inclusive)
2618             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2619             * @return the ordered range of layout set prototypes
2620             * @throws SystemException if a system exception occurred
2621             */
2622            public List<LayoutSetPrototype> findAll(int start, int end,
2623                    OrderByComparator orderByComparator) throws SystemException {
2624                    FinderPath finderPath = null;
2625                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
2626    
2627                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2628                                    (orderByComparator == null)) {
2629                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2630                            finderArgs = FINDER_ARGS_EMPTY;
2631                    }
2632                    else {
2633                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2634                            finderArgs = new Object[] { start, end, orderByComparator };
2635                    }
2636    
2637                    List<LayoutSetPrototype> list = (List<LayoutSetPrototype>)FinderCacheUtil.getResult(finderPath,
2638                                    finderArgs, this);
2639    
2640                    if (list == null) {
2641                            StringBundler query = null;
2642                            String sql = null;
2643    
2644                            if (orderByComparator != null) {
2645                                    query = new StringBundler(2 +
2646                                                    (orderByComparator.getOrderByFields().length * 3));
2647    
2648                                    query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE);
2649    
2650                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2651                                            orderByComparator);
2652    
2653                                    sql = query.toString();
2654                            }
2655                            else {
2656                                    sql = _SQL_SELECT_LAYOUTSETPROTOTYPE;
2657                            }
2658    
2659                            Session session = null;
2660    
2661                            try {
2662                                    session = openSession();
2663    
2664                                    Query q = session.createQuery(sql);
2665    
2666                                    if (orderByComparator == null) {
2667                                            list = (List<LayoutSetPrototype>)QueryUtil.list(q,
2668                                                            getDialect(), start, end, false);
2669    
2670                                            Collections.sort(list);
2671                                    }
2672                                    else {
2673                                            list = (List<LayoutSetPrototype>)QueryUtil.list(q,
2674                                                            getDialect(), start, end);
2675                                    }
2676                            }
2677                            catch (Exception e) {
2678                                    throw processException(e);
2679                            }
2680                            finally {
2681                                    if (list == null) {
2682                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2683                                    }
2684                                    else {
2685                                            cacheResult(list);
2686    
2687                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2688                                    }
2689    
2690                                    closeSession(session);
2691                            }
2692                    }
2693    
2694                    return list;
2695            }
2696    
2697            /**
2698             * Removes all the layout set prototypes where uuid = &#63; from the database.
2699             *
2700             * @param uuid the uuid
2701             * @throws SystemException if a system exception occurred
2702             */
2703            public void removeByUuid(String uuid) throws SystemException {
2704                    for (LayoutSetPrototype layoutSetPrototype : findByUuid(uuid)) {
2705                            remove(layoutSetPrototype);
2706                    }
2707            }
2708    
2709            /**
2710             * Removes all the layout set prototypes where companyId = &#63; from the database.
2711             *
2712             * @param companyId the company ID
2713             * @throws SystemException if a system exception occurred
2714             */
2715            public void removeByCompanyId(long companyId) throws SystemException {
2716                    for (LayoutSetPrototype layoutSetPrototype : findByCompanyId(companyId)) {
2717                            remove(layoutSetPrototype);
2718                    }
2719            }
2720    
2721            /**
2722             * Removes all the layout set prototypes where companyId = &#63; and active = &#63; from the database.
2723             *
2724             * @param companyId the company ID
2725             * @param active the active
2726             * @throws SystemException if a system exception occurred
2727             */
2728            public void removeByC_A(long companyId, boolean active)
2729                    throws SystemException {
2730                    for (LayoutSetPrototype layoutSetPrototype : findByC_A(companyId, active)) {
2731                            remove(layoutSetPrototype);
2732                    }
2733            }
2734    
2735            /**
2736             * Removes all the layout set prototypes from the database.
2737             *
2738             * @throws SystemException if a system exception occurred
2739             */
2740            public void removeAll() throws SystemException {
2741                    for (LayoutSetPrototype layoutSetPrototype : findAll()) {
2742                            remove(layoutSetPrototype);
2743                    }
2744            }
2745    
2746            /**
2747             * Returns the number of layout set prototypes where uuid = &#63;.
2748             *
2749             * @param uuid the uuid
2750             * @return the number of matching layout set prototypes
2751             * @throws SystemException if a system exception occurred
2752             */
2753            public int countByUuid(String uuid) throws SystemException {
2754                    Object[] finderArgs = new Object[] { uuid };
2755    
2756                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2757                                    finderArgs, this);
2758    
2759                    if (count == null) {
2760                            StringBundler query = new StringBundler(2);
2761    
2762                            query.append(_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
2763    
2764                            if (uuid == null) {
2765                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
2766                            }
2767                            else {
2768                                    if (uuid.equals(StringPool.BLANK)) {
2769                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
2770                                    }
2771                                    else {
2772                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
2773                                    }
2774                            }
2775    
2776                            String sql = query.toString();
2777    
2778                            Session session = null;
2779    
2780                            try {
2781                                    session = openSession();
2782    
2783                                    Query q = session.createQuery(sql);
2784    
2785                                    QueryPos qPos = QueryPos.getInstance(q);
2786    
2787                                    if (uuid != null) {
2788                                            qPos.add(uuid);
2789                                    }
2790    
2791                                    count = (Long)q.uniqueResult();
2792                            }
2793                            catch (Exception e) {
2794                                    throw processException(e);
2795                            }
2796                            finally {
2797                                    if (count == null) {
2798                                            count = Long.valueOf(0);
2799                                    }
2800    
2801                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2802                                            finderArgs, count);
2803    
2804                                    closeSession(session);
2805                            }
2806                    }
2807    
2808                    return count.intValue();
2809            }
2810    
2811            /**
2812             * Returns the number of layout set prototypes that the user has permission to view where uuid = &#63;.
2813             *
2814             * @param uuid the uuid
2815             * @return the number of matching layout set prototypes that the user has permission to view
2816             * @throws SystemException if a system exception occurred
2817             */
2818            public int filterCountByUuid(String uuid) throws SystemException {
2819                    if (!InlineSQLHelperUtil.isEnabled()) {
2820                            return countByUuid(uuid);
2821                    }
2822    
2823                    StringBundler query = new StringBundler(2);
2824    
2825                    query.append(_FILTER_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
2826    
2827                    if (uuid == null) {
2828                            query.append(_FINDER_COLUMN_UUID_UUID_1);
2829                    }
2830                    else {
2831                            if (uuid.equals(StringPool.BLANK)) {
2832                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
2833                            }
2834                            else {
2835                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
2836                            }
2837                    }
2838    
2839                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2840                                    LayoutSetPrototype.class.getName(),
2841                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2842    
2843                    Session session = null;
2844    
2845                    try {
2846                            session = openSession();
2847    
2848                            SQLQuery q = session.createSQLQuery(sql);
2849    
2850                            q.addScalar(COUNT_COLUMN_NAME,
2851                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2852    
2853                            QueryPos qPos = QueryPos.getInstance(q);
2854    
2855                            if (uuid != null) {
2856                                    qPos.add(uuid);
2857                            }
2858    
2859                            Long count = (Long)q.uniqueResult();
2860    
2861                            return count.intValue();
2862                    }
2863                    catch (Exception e) {
2864                            throw processException(e);
2865                    }
2866                    finally {
2867                            closeSession(session);
2868                    }
2869            }
2870    
2871            /**
2872             * Returns the number of layout set prototypes where companyId = &#63;.
2873             *
2874             * @param companyId the company ID
2875             * @return the number of matching layout set prototypes
2876             * @throws SystemException if a system exception occurred
2877             */
2878            public int countByCompanyId(long companyId) throws SystemException {
2879                    Object[] finderArgs = new Object[] { companyId };
2880    
2881                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2882                                    finderArgs, this);
2883    
2884                    if (count == null) {
2885                            StringBundler query = new StringBundler(2);
2886    
2887                            query.append(_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
2888    
2889                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2890    
2891                            String sql = query.toString();
2892    
2893                            Session session = null;
2894    
2895                            try {
2896                                    session = openSession();
2897    
2898                                    Query q = session.createQuery(sql);
2899    
2900                                    QueryPos qPos = QueryPos.getInstance(q);
2901    
2902                                    qPos.add(companyId);
2903    
2904                                    count = (Long)q.uniqueResult();
2905                            }
2906                            catch (Exception e) {
2907                                    throw processException(e);
2908                            }
2909                            finally {
2910                                    if (count == null) {
2911                                            count = Long.valueOf(0);
2912                                    }
2913    
2914                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2915                                            finderArgs, count);
2916    
2917                                    closeSession(session);
2918                            }
2919                    }
2920    
2921                    return count.intValue();
2922            }
2923    
2924            /**
2925             * Returns the number of layout set prototypes that the user has permission to view where companyId = &#63;.
2926             *
2927             * @param companyId the company ID
2928             * @return the number of matching layout set prototypes that the user has permission to view
2929             * @throws SystemException if a system exception occurred
2930             */
2931            public int filterCountByCompanyId(long companyId) throws SystemException {
2932                    if (!InlineSQLHelperUtil.isEnabled()) {
2933                            return countByCompanyId(companyId);
2934                    }
2935    
2936                    StringBundler query = new StringBundler(2);
2937    
2938                    query.append(_FILTER_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
2939    
2940                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2941    
2942                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2943                                    LayoutSetPrototype.class.getName(),
2944                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2945    
2946                    Session session = null;
2947    
2948                    try {
2949                            session = openSession();
2950    
2951                            SQLQuery q = session.createSQLQuery(sql);
2952    
2953                            q.addScalar(COUNT_COLUMN_NAME,
2954                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2955    
2956                            QueryPos qPos = QueryPos.getInstance(q);
2957    
2958                            qPos.add(companyId);
2959    
2960                            Long count = (Long)q.uniqueResult();
2961    
2962                            return count.intValue();
2963                    }
2964                    catch (Exception e) {
2965                            throw processException(e);
2966                    }
2967                    finally {
2968                            closeSession(session);
2969                    }
2970            }
2971    
2972            /**
2973             * Returns the number of layout set prototypes where companyId = &#63; and active = &#63;.
2974             *
2975             * @param companyId the company ID
2976             * @param active the active
2977             * @return the number of matching layout set prototypes
2978             * @throws SystemException if a system exception occurred
2979             */
2980            public int countByC_A(long companyId, boolean active)
2981                    throws SystemException {
2982                    Object[] finderArgs = new Object[] { companyId, active };
2983    
2984                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_A,
2985                                    finderArgs, this);
2986    
2987                    if (count == null) {
2988                            StringBundler query = new StringBundler(3);
2989    
2990                            query.append(_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
2991    
2992                            query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
2993    
2994                            query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
2995    
2996                            String sql = query.toString();
2997    
2998                            Session session = null;
2999    
3000                            try {
3001                                    session = openSession();
3002    
3003                                    Query q = session.createQuery(sql);
3004    
3005                                    QueryPos qPos = QueryPos.getInstance(q);
3006    
3007                                    qPos.add(companyId);
3008    
3009                                    qPos.add(active);
3010    
3011                                    count = (Long)q.uniqueResult();
3012                            }
3013                            catch (Exception e) {
3014                                    throw processException(e);
3015                            }
3016                            finally {
3017                                    if (count == null) {
3018                                            count = Long.valueOf(0);
3019                                    }
3020    
3021                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_A, finderArgs,
3022                                            count);
3023    
3024                                    closeSession(session);
3025                            }
3026                    }
3027    
3028                    return count.intValue();
3029            }
3030    
3031            /**
3032             * Returns the number of layout set prototypes that the user has permission to view where companyId = &#63; and active = &#63;.
3033             *
3034             * @param companyId the company ID
3035             * @param active the active
3036             * @return the number of matching layout set prototypes that the user has permission to view
3037             * @throws SystemException if a system exception occurred
3038             */
3039            public int filterCountByC_A(long companyId, boolean active)
3040                    throws SystemException {
3041                    if (!InlineSQLHelperUtil.isEnabled()) {
3042                            return countByC_A(companyId, active);
3043                    }
3044    
3045                    StringBundler query = new StringBundler(3);
3046    
3047                    query.append(_FILTER_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
3048    
3049                    query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
3050    
3051                    query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
3052    
3053                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3054                                    LayoutSetPrototype.class.getName(),
3055                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3056    
3057                    Session session = null;
3058    
3059                    try {
3060                            session = openSession();
3061    
3062                            SQLQuery q = session.createSQLQuery(sql);
3063    
3064                            q.addScalar(COUNT_COLUMN_NAME,
3065                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3066    
3067                            QueryPos qPos = QueryPos.getInstance(q);
3068    
3069                            qPos.add(companyId);
3070    
3071                            qPos.add(active);
3072    
3073                            Long count = (Long)q.uniqueResult();
3074    
3075                            return count.intValue();
3076                    }
3077                    catch (Exception e) {
3078                            throw processException(e);
3079                    }
3080                    finally {
3081                            closeSession(session);
3082                    }
3083            }
3084    
3085            /**
3086             * Returns the number of layout set prototypes.
3087             *
3088             * @return the number of layout set prototypes
3089             * @throws SystemException if a system exception occurred
3090             */
3091            public int countAll() throws SystemException {
3092                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3093                                    FINDER_ARGS_EMPTY, this);
3094    
3095                    if (count == null) {
3096                            Session session = null;
3097    
3098                            try {
3099                                    session = openSession();
3100    
3101                                    Query q = session.createQuery(_SQL_COUNT_LAYOUTSETPROTOTYPE);
3102    
3103                                    count = (Long)q.uniqueResult();
3104                            }
3105                            catch (Exception e) {
3106                                    throw processException(e);
3107                            }
3108                            finally {
3109                                    if (count == null) {
3110                                            count = Long.valueOf(0);
3111                                    }
3112    
3113                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3114                                            FINDER_ARGS_EMPTY, count);
3115    
3116                                    closeSession(session);
3117                            }
3118                    }
3119    
3120                    return count.intValue();
3121            }
3122    
3123            /**
3124             * Initializes the layout set prototype persistence.
3125             */
3126            public void afterPropertiesSet() {
3127                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3128                                            com.liferay.portal.util.PropsUtil.get(
3129                                                    "value.object.listener.com.liferay.portal.model.LayoutSetPrototype")));
3130    
3131                    if (listenerClassNames.length > 0) {
3132                            try {
3133                                    List<ModelListener<LayoutSetPrototype>> listenersList = new ArrayList<ModelListener<LayoutSetPrototype>>();
3134    
3135                                    for (String listenerClassName : listenerClassNames) {
3136                                            listenersList.add((ModelListener<LayoutSetPrototype>)InstanceFactory.newInstance(
3137                                                            listenerClassName));
3138                                    }
3139    
3140                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3141                            }
3142                            catch (Exception e) {
3143                                    _log.error(e);
3144                            }
3145                    }
3146            }
3147    
3148            public void destroy() {
3149                    EntityCacheUtil.removeCache(LayoutSetPrototypeImpl.class.getName());
3150                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3151                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3152            }
3153    
3154            @BeanReference(type = AccountPersistence.class)
3155            protected AccountPersistence accountPersistence;
3156            @BeanReference(type = AddressPersistence.class)
3157            protected AddressPersistence addressPersistence;
3158            @BeanReference(type = BrowserTrackerPersistence.class)
3159            protected BrowserTrackerPersistence browserTrackerPersistence;
3160            @BeanReference(type = ClassNamePersistence.class)
3161            protected ClassNamePersistence classNamePersistence;
3162            @BeanReference(type = ClusterGroupPersistence.class)
3163            protected ClusterGroupPersistence clusterGroupPersistence;
3164            @BeanReference(type = CompanyPersistence.class)
3165            protected CompanyPersistence companyPersistence;
3166            @BeanReference(type = ContactPersistence.class)
3167            protected ContactPersistence contactPersistence;
3168            @BeanReference(type = CountryPersistence.class)
3169            protected CountryPersistence countryPersistence;
3170            @BeanReference(type = EmailAddressPersistence.class)
3171            protected EmailAddressPersistence emailAddressPersistence;
3172            @BeanReference(type = GroupPersistence.class)
3173            protected GroupPersistence groupPersistence;
3174            @BeanReference(type = ImagePersistence.class)
3175            protected ImagePersistence imagePersistence;
3176            @BeanReference(type = LayoutPersistence.class)
3177            protected LayoutPersistence layoutPersistence;
3178            @BeanReference(type = LayoutBranchPersistence.class)
3179            protected LayoutBranchPersistence layoutBranchPersistence;
3180            @BeanReference(type = LayoutPrototypePersistence.class)
3181            protected LayoutPrototypePersistence layoutPrototypePersistence;
3182            @BeanReference(type = LayoutRevisionPersistence.class)
3183            protected LayoutRevisionPersistence layoutRevisionPersistence;
3184            @BeanReference(type = LayoutSetPersistence.class)
3185            protected LayoutSetPersistence layoutSetPersistence;
3186            @BeanReference(type = LayoutSetBranchPersistence.class)
3187            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
3188            @BeanReference(type = LayoutSetPrototypePersistence.class)
3189            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
3190            @BeanReference(type = ListTypePersistence.class)
3191            protected ListTypePersistence listTypePersistence;
3192            @BeanReference(type = LockPersistence.class)
3193            protected LockPersistence lockPersistence;
3194            @BeanReference(type = MembershipRequestPersistence.class)
3195            protected MembershipRequestPersistence membershipRequestPersistence;
3196            @BeanReference(type = OrganizationPersistence.class)
3197            protected OrganizationPersistence organizationPersistence;
3198            @BeanReference(type = OrgGroupPermissionPersistence.class)
3199            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
3200            @BeanReference(type = OrgGroupRolePersistence.class)
3201            protected OrgGroupRolePersistence orgGroupRolePersistence;
3202            @BeanReference(type = OrgLaborPersistence.class)
3203            protected OrgLaborPersistence orgLaborPersistence;
3204            @BeanReference(type = PasswordPolicyPersistence.class)
3205            protected PasswordPolicyPersistence passwordPolicyPersistence;
3206            @BeanReference(type = PasswordPolicyRelPersistence.class)
3207            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
3208            @BeanReference(type = PasswordTrackerPersistence.class)
3209            protected PasswordTrackerPersistence passwordTrackerPersistence;
3210            @BeanReference(type = PermissionPersistence.class)
3211            protected PermissionPersistence permissionPersistence;
3212            @BeanReference(type = PhonePersistence.class)
3213            protected PhonePersistence phonePersistence;
3214            @BeanReference(type = PluginSettingPersistence.class)
3215            protected PluginSettingPersistence pluginSettingPersistence;
3216            @BeanReference(type = PortalPreferencesPersistence.class)
3217            protected PortalPreferencesPersistence portalPreferencesPersistence;
3218            @BeanReference(type = PortletPersistence.class)
3219            protected PortletPersistence portletPersistence;
3220            @BeanReference(type = PortletItemPersistence.class)
3221            protected PortletItemPersistence portletItemPersistence;
3222            @BeanReference(type = PortletPreferencesPersistence.class)
3223            protected PortletPreferencesPersistence portletPreferencesPersistence;
3224            @BeanReference(type = RegionPersistence.class)
3225            protected RegionPersistence regionPersistence;
3226            @BeanReference(type = ReleasePersistence.class)
3227            protected ReleasePersistence releasePersistence;
3228            @BeanReference(type = RepositoryPersistence.class)
3229            protected RepositoryPersistence repositoryPersistence;
3230            @BeanReference(type = RepositoryEntryPersistence.class)
3231            protected RepositoryEntryPersistence repositoryEntryPersistence;
3232            @BeanReference(type = ResourcePersistence.class)
3233            protected ResourcePersistence resourcePersistence;
3234            @BeanReference(type = ResourceActionPersistence.class)
3235            protected ResourceActionPersistence resourceActionPersistence;
3236            @BeanReference(type = ResourceBlockPersistence.class)
3237            protected ResourceBlockPersistence resourceBlockPersistence;
3238            @BeanReference(type = ResourceBlockPermissionPersistence.class)
3239            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
3240            @BeanReference(type = ResourceCodePersistence.class)
3241            protected ResourceCodePersistence resourceCodePersistence;
3242            @BeanReference(type = ResourcePermissionPersistence.class)
3243            protected ResourcePermissionPersistence resourcePermissionPersistence;
3244            @BeanReference(type = ResourceTypePermissionPersistence.class)
3245            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
3246            @BeanReference(type = RolePersistence.class)
3247            protected RolePersistence rolePersistence;
3248            @BeanReference(type = ServiceComponentPersistence.class)
3249            protected ServiceComponentPersistence serviceComponentPersistence;
3250            @BeanReference(type = ShardPersistence.class)
3251            protected ShardPersistence shardPersistence;
3252            @BeanReference(type = SubscriptionPersistence.class)
3253            protected SubscriptionPersistence subscriptionPersistence;
3254            @BeanReference(type = TeamPersistence.class)
3255            protected TeamPersistence teamPersistence;
3256            @BeanReference(type = TicketPersistence.class)
3257            protected TicketPersistence ticketPersistence;
3258            @BeanReference(type = UserPersistence.class)
3259            protected UserPersistence userPersistence;
3260            @BeanReference(type = UserGroupPersistence.class)
3261            protected UserGroupPersistence userGroupPersistence;
3262            @BeanReference(type = UserGroupGroupRolePersistence.class)
3263            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
3264            @BeanReference(type = UserGroupRolePersistence.class)
3265            protected UserGroupRolePersistence userGroupRolePersistence;
3266            @BeanReference(type = UserIdMapperPersistence.class)
3267            protected UserIdMapperPersistence userIdMapperPersistence;
3268            @BeanReference(type = UserNotificationEventPersistence.class)
3269            protected UserNotificationEventPersistence userNotificationEventPersistence;
3270            @BeanReference(type = UserTrackerPersistence.class)
3271            protected UserTrackerPersistence userTrackerPersistence;
3272            @BeanReference(type = UserTrackerPathPersistence.class)
3273            protected UserTrackerPathPersistence userTrackerPathPersistence;
3274            @BeanReference(type = VirtualHostPersistence.class)
3275            protected VirtualHostPersistence virtualHostPersistence;
3276            @BeanReference(type = WebDAVPropsPersistence.class)
3277            protected WebDAVPropsPersistence webDAVPropsPersistence;
3278            @BeanReference(type = WebsitePersistence.class)
3279            protected WebsitePersistence websitePersistence;
3280            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
3281            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
3282            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
3283            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
3284            private static final String _SQL_SELECT_LAYOUTSETPROTOTYPE = "SELECT layoutSetPrototype FROM LayoutSetPrototype layoutSetPrototype";
3285            private static final String _SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE = "SELECT layoutSetPrototype FROM LayoutSetPrototype layoutSetPrototype WHERE ";
3286            private static final String _SQL_COUNT_LAYOUTSETPROTOTYPE = "SELECT COUNT(layoutSetPrototype) FROM LayoutSetPrototype layoutSetPrototype";
3287            private static final String _SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE = "SELECT COUNT(layoutSetPrototype) FROM LayoutSetPrototype layoutSetPrototype WHERE ";
3288            private static final String _FINDER_COLUMN_UUID_UUID_1 = "layoutSetPrototype.uuid IS NULL";
3289            private static final String _FINDER_COLUMN_UUID_UUID_2 = "layoutSetPrototype.uuid = ?";
3290            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(layoutSetPrototype.uuid IS NULL OR layoutSetPrototype.uuid = ?)";
3291            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "layoutSetPrototype.companyId = ?";
3292            private static final String _FINDER_COLUMN_C_A_COMPANYID_2 = "layoutSetPrototype.companyId = ? AND ";
3293            private static final String _FINDER_COLUMN_C_A_ACTIVE_2 = "layoutSetPrototype.active = ?";
3294            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "layoutSetPrototype.layoutSetPrototypeId";
3295            private static final String _FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE = "SELECT DISTINCT {layoutSetPrototype.*} FROM LayoutSetPrototype layoutSetPrototype WHERE ";
3296            private static final String _FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_1 =
3297                    "SELECT {LayoutSetPrototype.*} FROM (SELECT DISTINCT layoutSetPrototype.layoutSetPrototypeId FROM LayoutSetPrototype layoutSetPrototype WHERE ";
3298            private static final String _FILTER_SQL_SELECT_LAYOUTSETPROTOTYPE_NO_INLINE_DISTINCT_WHERE_2 =
3299                    ") TEMP_TABLE INNER JOIN LayoutSetPrototype ON TEMP_TABLE.layoutSetPrototypeId = LayoutSetPrototype.layoutSetPrototypeId";
3300            private static final String _FILTER_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE = "SELECT COUNT(DISTINCT layoutSetPrototype.layoutSetPrototypeId) AS COUNT_VALUE FROM LayoutSetPrototype layoutSetPrototype WHERE ";
3301            private static final String _FILTER_ENTITY_ALIAS = "layoutSetPrototype";
3302            private static final String _FILTER_ENTITY_TABLE = "LayoutSetPrototype";
3303            private static final String _ORDER_BY_ENTITY_ALIAS = "layoutSetPrototype.";
3304            private static final String _ORDER_BY_ENTITY_TABLE = "LayoutSetPrototype.";
3305            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutSetPrototype exists with the primary key ";
3306            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutSetPrototype exists with the key {";
3307            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3308            private static Log _log = LogFactoryUtil.getLog(LayoutSetPrototypePersistenceImpl.class);
3309            private static LayoutSetPrototype _nullLayoutSetPrototype = new LayoutSetPrototypeImpl() {
3310                            @Override
3311                            public Object clone() {
3312                                    return this;
3313                            }
3314    
3315                            @Override
3316                            public CacheModel<LayoutSetPrototype> toCacheModel() {
3317                                    return _nullLayoutSetPrototypeCacheModel;
3318                            }
3319                    };
3320    
3321            private static CacheModel<LayoutSetPrototype> _nullLayoutSetPrototypeCacheModel =
3322                    new CacheModel<LayoutSetPrototype>() {
3323                            public LayoutSetPrototype toEntityModel() {
3324                                    return _nullLayoutSetPrototype;
3325                            }
3326                    };
3327    }