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