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