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