001    /**
002     * Copyright (c) 2000-2010 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.NoSuchLayoutSetPrototypeException;
018    import com.liferay.portal.NoSuchModelException;
019    import com.liferay.portal.kernel.annotation.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.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.LayoutSetPrototype;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.impl.LayoutSetPrototypeImpl;
040    import com.liferay.portal.model.impl.LayoutSetPrototypeModelImpl;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import java.io.Serializable;
044    
045    import java.util.ArrayList;
046    import java.util.Collections;
047    import java.util.List;
048    
049    /**
050     * The persistence implementation for the layout set prototype service.
051     *
052     * <p>
053     * Never modify or reference this class directly. Always use {@link LayoutSetPrototypeUtil} to access the layout set prototype persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
054     * </p>
055     *
056     * <p>
057     * Caching information and settings can be found in <code>portal.properties</code>
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see LayoutSetPrototypePersistence
062     * @see LayoutSetPrototypeUtil
063     * @generated
064     */
065    public class LayoutSetPrototypePersistenceImpl extends BasePersistenceImpl<LayoutSetPrototype>
066            implements LayoutSetPrototypePersistence {
067            public static final String FINDER_CLASS_NAME_ENTITY = LayoutSetPrototypeImpl.class.getName();
068            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
069                    ".List";
070            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
071                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
072                            FINDER_CLASS_NAME_LIST, "findByCompanyId",
073                            new String[] {
074                                    Long.class.getName(),
075                                    
076                            "java.lang.Integer", "java.lang.Integer",
077                                    "com.liferay.portal.kernel.util.OrderByComparator"
078                            });
079            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
080                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
081                            FINDER_CLASS_NAME_LIST, "countByCompanyId",
082                            new String[] { Long.class.getName() });
083            public static final FinderPath FINDER_PATH_FIND_BY_C_A = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
084                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
085                            FINDER_CLASS_NAME_LIST, "findByC_A",
086                            new String[] {
087                                    Long.class.getName(), Boolean.class.getName(),
088                                    
089                            "java.lang.Integer", "java.lang.Integer",
090                                    "com.liferay.portal.kernel.util.OrderByComparator"
091                            });
092            public static final FinderPath FINDER_PATH_COUNT_BY_C_A = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
093                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
094                            FINDER_CLASS_NAME_LIST, "countByC_A",
095                            new String[] { Long.class.getName(), Boolean.class.getName() });
096            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
097                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
098                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
099            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
100                            LayoutSetPrototypeModelImpl.FINDER_CACHE_ENABLED,
101                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
102    
103            /**
104             * Caches the layout set prototype in the entity cache if it is enabled.
105             *
106             * @param layoutSetPrototype the layout set prototype to cache
107             */
108            public void cacheResult(LayoutSetPrototype layoutSetPrototype) {
109                    EntityCacheUtil.putResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
110                            LayoutSetPrototypeImpl.class, layoutSetPrototype.getPrimaryKey(),
111                            layoutSetPrototype);
112            }
113    
114            /**
115             * Caches the layout set prototypes in the entity cache if it is enabled.
116             *
117             * @param layoutSetPrototypes the layout set prototypes to cache
118             */
119            public void cacheResult(List<LayoutSetPrototype> layoutSetPrototypes) {
120                    for (LayoutSetPrototype layoutSetPrototype : layoutSetPrototypes) {
121                            if (EntityCacheUtil.getResult(
122                                                    LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
123                                                    LayoutSetPrototypeImpl.class,
124                                                    layoutSetPrototype.getPrimaryKey(), this) == null) {
125                                    cacheResult(layoutSetPrototype);
126                            }
127                    }
128            }
129    
130            /**
131             * Clears the cache for all layout set prototypes.
132             *
133             * <p>
134             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
135             * </p>
136             */
137            public void clearCache() {
138                    CacheRegistryUtil.clear(LayoutSetPrototypeImpl.class.getName());
139                    EntityCacheUtil.clearCache(LayoutSetPrototypeImpl.class.getName());
140                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
141                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
142            }
143    
144            /**
145             * Clears the cache for the layout set prototype.
146             *
147             * <p>
148             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
149             * </p>
150             */
151            public void clearCache(LayoutSetPrototype layoutSetPrototype) {
152                    EntityCacheUtil.removeResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
153                            LayoutSetPrototypeImpl.class, layoutSetPrototype.getPrimaryKey());
154            }
155    
156            /**
157             * Creates a new layout set prototype with the primary key. Does not add the layout set prototype to the database.
158             *
159             * @param layoutSetPrototypeId the primary key for the new layout set prototype
160             * @return the new layout set prototype
161             */
162            public LayoutSetPrototype create(long layoutSetPrototypeId) {
163                    LayoutSetPrototype layoutSetPrototype = new LayoutSetPrototypeImpl();
164    
165                    layoutSetPrototype.setNew(true);
166                    layoutSetPrototype.setPrimaryKey(layoutSetPrototypeId);
167    
168                    return layoutSetPrototype;
169            }
170    
171            /**
172             * Removes the layout set prototype with the primary key from the database. Also notifies the appropriate model listeners.
173             *
174             * @param primaryKey the primary key of the layout set prototype to remove
175             * @return the layout set prototype that was removed
176             * @throws com.liferay.portal.NoSuchModelException if a layout set prototype with the primary key could not be found
177             * @throws SystemException if a system exception occurred
178             */
179            public LayoutSetPrototype remove(Serializable primaryKey)
180                    throws NoSuchModelException, SystemException {
181                    return remove(((Long)primaryKey).longValue());
182            }
183    
184            /**
185             * Removes the layout set prototype with the primary key from the database. Also notifies the appropriate model listeners.
186             *
187             * @param layoutSetPrototypeId the primary key of the layout set prototype to remove
188             * @return the layout set prototype that was removed
189             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
190             * @throws SystemException if a system exception occurred
191             */
192            public LayoutSetPrototype remove(long layoutSetPrototypeId)
193                    throws NoSuchLayoutSetPrototypeException, SystemException {
194                    Session session = null;
195    
196                    try {
197                            session = openSession();
198    
199                            LayoutSetPrototype layoutSetPrototype = (LayoutSetPrototype)session.get(LayoutSetPrototypeImpl.class,
200                                            new Long(layoutSetPrototypeId));
201    
202                            if (layoutSetPrototype == null) {
203                                    if (_log.isWarnEnabled()) {
204                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
205                                                    layoutSetPrototypeId);
206                                    }
207    
208                                    throw new NoSuchLayoutSetPrototypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
209                                            layoutSetPrototypeId);
210                            }
211    
212                            return remove(layoutSetPrototype);
213                    }
214                    catch (NoSuchLayoutSetPrototypeException nsee) {
215                            throw nsee;
216                    }
217                    catch (Exception e) {
218                            throw processException(e);
219                    }
220                    finally {
221                            closeSession(session);
222                    }
223            }
224    
225            protected LayoutSetPrototype removeImpl(
226                    LayoutSetPrototype layoutSetPrototype) throws SystemException {
227                    layoutSetPrototype = toUnwrappedModel(layoutSetPrototype);
228    
229                    Session session = null;
230    
231                    try {
232                            session = openSession();
233    
234                            BatchSessionUtil.delete(session, layoutSetPrototype);
235                    }
236                    catch (Exception e) {
237                            throw processException(e);
238                    }
239                    finally {
240                            closeSession(session);
241                    }
242    
243                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
244    
245                    EntityCacheUtil.removeResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
246                            LayoutSetPrototypeImpl.class, layoutSetPrototype.getPrimaryKey());
247    
248                    return layoutSetPrototype;
249            }
250    
251            public LayoutSetPrototype updateImpl(
252                    com.liferay.portal.model.LayoutSetPrototype layoutSetPrototype,
253                    boolean merge) throws SystemException {
254                    layoutSetPrototype = toUnwrappedModel(layoutSetPrototype);
255    
256                    Session session = null;
257    
258                    try {
259                            session = openSession();
260    
261                            BatchSessionUtil.update(session, layoutSetPrototype, merge);
262    
263                            layoutSetPrototype.setNew(false);
264                    }
265                    catch (Exception e) {
266                            throw processException(e);
267                    }
268                    finally {
269                            closeSession(session);
270                    }
271    
272                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
273    
274                    EntityCacheUtil.putResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
275                            LayoutSetPrototypeImpl.class, layoutSetPrototype.getPrimaryKey(),
276                            layoutSetPrototype);
277    
278                    return layoutSetPrototype;
279            }
280    
281            protected LayoutSetPrototype toUnwrappedModel(
282                    LayoutSetPrototype layoutSetPrototype) {
283                    if (layoutSetPrototype instanceof LayoutSetPrototypeImpl) {
284                            return layoutSetPrototype;
285                    }
286    
287                    LayoutSetPrototypeImpl layoutSetPrototypeImpl = new LayoutSetPrototypeImpl();
288    
289                    layoutSetPrototypeImpl.setNew(layoutSetPrototype.isNew());
290                    layoutSetPrototypeImpl.setPrimaryKey(layoutSetPrototype.getPrimaryKey());
291    
292                    layoutSetPrototypeImpl.setLayoutSetPrototypeId(layoutSetPrototype.getLayoutSetPrototypeId());
293                    layoutSetPrototypeImpl.setCompanyId(layoutSetPrototype.getCompanyId());
294                    layoutSetPrototypeImpl.setName(layoutSetPrototype.getName());
295                    layoutSetPrototypeImpl.setDescription(layoutSetPrototype.getDescription());
296                    layoutSetPrototypeImpl.setSettings(layoutSetPrototype.getSettings());
297                    layoutSetPrototypeImpl.setActive(layoutSetPrototype.isActive());
298    
299                    return layoutSetPrototypeImpl;
300            }
301    
302            /**
303             * Finds the layout set prototype with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
304             *
305             * @param primaryKey the primary key of the layout set prototype to find
306             * @return the layout set prototype
307             * @throws com.liferay.portal.NoSuchModelException if a layout set prototype with the primary key could not be found
308             * @throws SystemException if a system exception occurred
309             */
310            public LayoutSetPrototype findByPrimaryKey(Serializable primaryKey)
311                    throws NoSuchModelException, SystemException {
312                    return findByPrimaryKey(((Long)primaryKey).longValue());
313            }
314    
315            /**
316             * Finds the layout set prototype with the primary key or throws a {@link com.liferay.portal.NoSuchLayoutSetPrototypeException} if it could not be found.
317             *
318             * @param layoutSetPrototypeId the primary key of the layout set prototype to find
319             * @return the layout set prototype
320             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
321             * @throws SystemException if a system exception occurred
322             */
323            public LayoutSetPrototype findByPrimaryKey(long layoutSetPrototypeId)
324                    throws NoSuchLayoutSetPrototypeException, SystemException {
325                    LayoutSetPrototype layoutSetPrototype = fetchByPrimaryKey(layoutSetPrototypeId);
326    
327                    if (layoutSetPrototype == null) {
328                            if (_log.isWarnEnabled()) {
329                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
330                                            layoutSetPrototypeId);
331                            }
332    
333                            throw new NoSuchLayoutSetPrototypeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
334                                    layoutSetPrototypeId);
335                    }
336    
337                    return layoutSetPrototype;
338            }
339    
340            /**
341             * Finds the layout set prototype with the primary key or returns <code>null</code> if it could not be found.
342             *
343             * @param primaryKey the primary key of the layout set prototype to find
344             * @return the layout set prototype, or <code>null</code> if a layout set prototype with the primary key could not be found
345             * @throws SystemException if a system exception occurred
346             */
347            public LayoutSetPrototype fetchByPrimaryKey(Serializable primaryKey)
348                    throws SystemException {
349                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
350            }
351    
352            /**
353             * Finds the layout set prototype with the primary key or returns <code>null</code> if it could not be found.
354             *
355             * @param layoutSetPrototypeId the primary key of the layout set prototype to find
356             * @return the layout set prototype, or <code>null</code> if a layout set prototype with the primary key could not be found
357             * @throws SystemException if a system exception occurred
358             */
359            public LayoutSetPrototype fetchByPrimaryKey(long layoutSetPrototypeId)
360                    throws SystemException {
361                    LayoutSetPrototype layoutSetPrototype = (LayoutSetPrototype)EntityCacheUtil.getResult(LayoutSetPrototypeModelImpl.ENTITY_CACHE_ENABLED,
362                                    LayoutSetPrototypeImpl.class, layoutSetPrototypeId, this);
363    
364                    if (layoutSetPrototype == null) {
365                            Session session = null;
366    
367                            try {
368                                    session = openSession();
369    
370                                    layoutSetPrototype = (LayoutSetPrototype)session.get(LayoutSetPrototypeImpl.class,
371                                                    new Long(layoutSetPrototypeId));
372                            }
373                            catch (Exception e) {
374                                    throw processException(e);
375                            }
376                            finally {
377                                    if (layoutSetPrototype != null) {
378                                            cacheResult(layoutSetPrototype);
379                                    }
380    
381                                    closeSession(session);
382                            }
383                    }
384    
385                    return layoutSetPrototype;
386            }
387    
388            /**
389             * Finds all the layout set prototypes where companyId = &#63;.
390             *
391             * @param companyId the company id to search with
392             * @return the matching layout set prototypes
393             * @throws SystemException if a system exception occurred
394             */
395            public List<LayoutSetPrototype> findByCompanyId(long companyId)
396                    throws SystemException {
397                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
398                            null);
399            }
400    
401            /**
402             * Finds a range of all the layout set prototypes where companyId = &#63;.
403             *
404             * <p>
405             * 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.
406             * </p>
407             *
408             * @param companyId the company id to search with
409             * @param start the lower bound of the range of layout set prototypes to return
410             * @param end the upper bound of the range of layout set prototypes to return (not inclusive)
411             * @return the range of matching layout set prototypes
412             * @throws SystemException if a system exception occurred
413             */
414            public List<LayoutSetPrototype> findByCompanyId(long companyId, int start,
415                    int end) throws SystemException {
416                    return findByCompanyId(companyId, start, end, null);
417            }
418    
419            /**
420             * Finds an ordered range of all the layout set prototypes where companyId = &#63;.
421             *
422             * <p>
423             * 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.
424             * </p>
425             *
426             * @param companyId the company id to search with
427             * @param start the lower bound of the range of layout set prototypes to return
428             * @param end the upper bound of the range of layout set prototypes to return (not inclusive)
429             * @param orderByComparator the comparator to order the results by
430             * @return the ordered range of matching layout set prototypes
431             * @throws SystemException if a system exception occurred
432             */
433            public List<LayoutSetPrototype> findByCompanyId(long companyId, int start,
434                    int end, OrderByComparator orderByComparator) throws SystemException {
435                    Object[] finderArgs = new Object[] {
436                                    companyId,
437                                    
438                                    String.valueOf(start), String.valueOf(end),
439                                    String.valueOf(orderByComparator)
440                            };
441    
442                    List<LayoutSetPrototype> list = (List<LayoutSetPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
443                                    finderArgs, this);
444    
445                    if (list == null) {
446                            Session session = null;
447    
448                            try {
449                                    session = openSession();
450    
451                                    StringBundler query = null;
452    
453                                    if (orderByComparator != null) {
454                                            query = new StringBundler(3 +
455                                                            (orderByComparator.getOrderByFields().length * 3));
456                                    }
457                                    else {
458                                            query = new StringBundler(2);
459                                    }
460    
461                                    query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
462    
463                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
464    
465                                    if (orderByComparator != null) {
466                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
467                                                    orderByComparator);
468                                    }
469    
470                                    String sql = query.toString();
471    
472                                    Query q = session.createQuery(sql);
473    
474                                    QueryPos qPos = QueryPos.getInstance(q);
475    
476                                    qPos.add(companyId);
477    
478                                    list = (List<LayoutSetPrototype>)QueryUtil.list(q,
479                                                    getDialect(), start, end);
480                            }
481                            catch (Exception e) {
482                                    throw processException(e);
483                            }
484                            finally {
485                                    if (list == null) {
486                                            list = new ArrayList<LayoutSetPrototype>();
487                                    }
488    
489                                    cacheResult(list);
490    
491                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
492                                            finderArgs, list);
493    
494                                    closeSession(session);
495                            }
496                    }
497    
498                    return list;
499            }
500    
501            /**
502             * Finds the first layout set prototype in the ordered set where companyId = &#63;.
503             *
504             * <p>
505             * 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.
506             * </p>
507             *
508             * @param companyId the company id to search with
509             * @param orderByComparator the comparator to order the set by
510             * @return the first matching layout set prototype
511             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
512             * @throws SystemException if a system exception occurred
513             */
514            public LayoutSetPrototype findByCompanyId_First(long companyId,
515                    OrderByComparator orderByComparator)
516                    throws NoSuchLayoutSetPrototypeException, SystemException {
517                    List<LayoutSetPrototype> list = findByCompanyId(companyId, 0, 1,
518                                    orderByComparator);
519    
520                    if (list.isEmpty()) {
521                            StringBundler msg = new StringBundler(4);
522    
523                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
524    
525                            msg.append("companyId=");
526                            msg.append(companyId);
527    
528                            msg.append(StringPool.CLOSE_CURLY_BRACE);
529    
530                            throw new NoSuchLayoutSetPrototypeException(msg.toString());
531                    }
532                    else {
533                            return list.get(0);
534                    }
535            }
536    
537            /**
538             * Finds the last layout set prototype in the ordered set where companyId = &#63;.
539             *
540             * <p>
541             * 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.
542             * </p>
543             *
544             * @param companyId the company id to search with
545             * @param orderByComparator the comparator to order the set by
546             * @return the last matching layout set prototype
547             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
548             * @throws SystemException if a system exception occurred
549             */
550            public LayoutSetPrototype findByCompanyId_Last(long companyId,
551                    OrderByComparator orderByComparator)
552                    throws NoSuchLayoutSetPrototypeException, SystemException {
553                    int count = countByCompanyId(companyId);
554    
555                    List<LayoutSetPrototype> list = findByCompanyId(companyId, count - 1,
556                                    count, orderByComparator);
557    
558                    if (list.isEmpty()) {
559                            StringBundler msg = new StringBundler(4);
560    
561                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
562    
563                            msg.append("companyId=");
564                            msg.append(companyId);
565    
566                            msg.append(StringPool.CLOSE_CURLY_BRACE);
567    
568                            throw new NoSuchLayoutSetPrototypeException(msg.toString());
569                    }
570                    else {
571                            return list.get(0);
572                    }
573            }
574    
575            /**
576             * Finds the layout set prototypes before and after the current layout set prototype in the ordered set where companyId = &#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 layoutSetPrototypeId the primary key of the current layout set prototype
583             * @param companyId the company id to search with
584             * @param orderByComparator the comparator to order the set by
585             * @return the previous, current, and next layout set prototype
586             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
587             * @throws SystemException if a system exception occurred
588             */
589            public LayoutSetPrototype[] findByCompanyId_PrevAndNext(
590                    long layoutSetPrototypeId, long companyId,
591                    OrderByComparator orderByComparator)
592                    throws NoSuchLayoutSetPrototypeException, SystemException {
593                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
594    
595                    Session session = null;
596    
597                    try {
598                            session = openSession();
599    
600                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
601    
602                            array[0] = getByCompanyId_PrevAndNext(session, layoutSetPrototype,
603                                            companyId, orderByComparator, true);
604    
605                            array[1] = layoutSetPrototype;
606    
607                            array[2] = getByCompanyId_PrevAndNext(session, layoutSetPrototype,
608                                            companyId, orderByComparator, false);
609    
610                            return array;
611                    }
612                    catch (Exception e) {
613                            throw processException(e);
614                    }
615                    finally {
616                            closeSession(session);
617                    }
618            }
619    
620            protected LayoutSetPrototype getByCompanyId_PrevAndNext(Session session,
621                    LayoutSetPrototype layoutSetPrototype, long companyId,
622                    OrderByComparator orderByComparator, boolean previous) {
623                    StringBundler query = null;
624    
625                    if (orderByComparator != null) {
626                            query = new StringBundler(6 +
627                                            (orderByComparator.getOrderByFields().length * 6));
628                    }
629                    else {
630                            query = new StringBundler(3);
631                    }
632    
633                    query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
634    
635                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
636    
637                    if (orderByComparator != null) {
638                            String[] orderByFields = orderByComparator.getOrderByFields();
639    
640                            if (orderByFields.length > 0) {
641                                    query.append(WHERE_AND);
642                            }
643    
644                            for (int i = 0; i < orderByFields.length; i++) {
645                                    query.append(_ORDER_BY_ENTITY_ALIAS);
646                                    query.append(orderByFields[i]);
647    
648                                    if ((i + 1) < orderByFields.length) {
649                                            if (orderByComparator.isAscending() ^ previous) {
650                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
651                                            }
652                                            else {
653                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
654                                            }
655                                    }
656                                    else {
657                                            if (orderByComparator.isAscending() ^ previous) {
658                                                    query.append(WHERE_GREATER_THAN);
659                                            }
660                                            else {
661                                                    query.append(WHERE_LESSER_THAN);
662                                            }
663                                    }
664                            }
665    
666                            query.append(ORDER_BY_CLAUSE);
667    
668                            for (int i = 0; i < orderByFields.length; i++) {
669                                    query.append(_ORDER_BY_ENTITY_ALIAS);
670                                    query.append(orderByFields[i]);
671    
672                                    if ((i + 1) < orderByFields.length) {
673                                            if (orderByComparator.isAscending() ^ previous) {
674                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
675                                            }
676                                            else {
677                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
678                                            }
679                                    }
680                                    else {
681                                            if (orderByComparator.isAscending() ^ previous) {
682                                                    query.append(ORDER_BY_ASC);
683                                            }
684                                            else {
685                                                    query.append(ORDER_BY_DESC);
686                                            }
687                                    }
688                            }
689                    }
690    
691                    String sql = query.toString();
692    
693                    Query q = session.createQuery(sql);
694    
695                    q.setFirstResult(0);
696                    q.setMaxResults(2);
697    
698                    QueryPos qPos = QueryPos.getInstance(q);
699    
700                    qPos.add(companyId);
701    
702                    if (orderByComparator != null) {
703                            Object[] values = orderByComparator.getOrderByValues(layoutSetPrototype);
704    
705                            for (Object value : values) {
706                                    qPos.add(value);
707                            }
708                    }
709    
710                    List<LayoutSetPrototype> list = q.list();
711    
712                    if (list.size() == 2) {
713                            return list.get(1);
714                    }
715                    else {
716                            return null;
717                    }
718            }
719    
720            /**
721             * Finds all the layout set prototypes where companyId = &#63; and active = &#63;.
722             *
723             * @param companyId the company id to search with
724             * @param active the active to search with
725             * @return the matching layout set prototypes
726             * @throws SystemException if a system exception occurred
727             */
728            public List<LayoutSetPrototype> findByC_A(long companyId, boolean active)
729                    throws SystemException {
730                    return findByC_A(companyId, active, QueryUtil.ALL_POS,
731                            QueryUtil.ALL_POS, null);
732            }
733    
734            /**
735             * Finds a range of all the layout set prototypes where companyId = &#63; and active = &#63;.
736             *
737             * <p>
738             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
739             * </p>
740             *
741             * @param companyId the company id to search with
742             * @param active the active to search with
743             * @param start the lower bound of the range of layout set prototypes to return
744             * @param end the upper bound of the range of layout set prototypes to return (not inclusive)
745             * @return the range of matching layout set prototypes
746             * @throws SystemException if a system exception occurred
747             */
748            public List<LayoutSetPrototype> findByC_A(long companyId, boolean active,
749                    int start, int end) throws SystemException {
750                    return findByC_A(companyId, active, start, end, null);
751            }
752    
753            /**
754             * Finds an ordered range of all the layout set prototypes where companyId = &#63; and active = &#63;.
755             *
756             * <p>
757             * 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.
758             * </p>
759             *
760             * @param companyId the company id to search with
761             * @param active the active to search with
762             * @param start the lower bound of the range of layout set prototypes to return
763             * @param end the upper bound of the range of layout set prototypes to return (not inclusive)
764             * @param orderByComparator the comparator to order the results by
765             * @return the ordered range of matching layout set prototypes
766             * @throws SystemException if a system exception occurred
767             */
768            public List<LayoutSetPrototype> findByC_A(long companyId, boolean active,
769                    int start, int end, OrderByComparator orderByComparator)
770                    throws SystemException {
771                    Object[] finderArgs = new Object[] {
772                                    companyId, active,
773                                    
774                                    String.valueOf(start), String.valueOf(end),
775                                    String.valueOf(orderByComparator)
776                            };
777    
778                    List<LayoutSetPrototype> list = (List<LayoutSetPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_A,
779                                    finderArgs, this);
780    
781                    if (list == null) {
782                            Session session = null;
783    
784                            try {
785                                    session = openSession();
786    
787                                    StringBundler query = null;
788    
789                                    if (orderByComparator != null) {
790                                            query = new StringBundler(4 +
791                                                            (orderByComparator.getOrderByFields().length * 3));
792                                    }
793                                    else {
794                                            query = new StringBundler(3);
795                                    }
796    
797                                    query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
798    
799                                    query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
800    
801                                    query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
802    
803                                    if (orderByComparator != null) {
804                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
805                                                    orderByComparator);
806                                    }
807    
808                                    String sql = query.toString();
809    
810                                    Query q = session.createQuery(sql);
811    
812                                    QueryPos qPos = QueryPos.getInstance(q);
813    
814                                    qPos.add(companyId);
815    
816                                    qPos.add(active);
817    
818                                    list = (List<LayoutSetPrototype>)QueryUtil.list(q,
819                                                    getDialect(), start, end);
820                            }
821                            catch (Exception e) {
822                                    throw processException(e);
823                            }
824                            finally {
825                                    if (list == null) {
826                                            list = new ArrayList<LayoutSetPrototype>();
827                                    }
828    
829                                    cacheResult(list);
830    
831                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_A, finderArgs,
832                                            list);
833    
834                                    closeSession(session);
835                            }
836                    }
837    
838                    return list;
839            }
840    
841            /**
842             * Finds the first layout set prototype in the ordered set where companyId = &#63; and active = &#63;.
843             *
844             * <p>
845             * 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.
846             * </p>
847             *
848             * @param companyId the company id to search with
849             * @param active the active to search with
850             * @param orderByComparator the comparator to order the set by
851             * @return the first matching layout set prototype
852             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
853             * @throws SystemException if a system exception occurred
854             */
855            public LayoutSetPrototype findByC_A_First(long companyId, boolean active,
856                    OrderByComparator orderByComparator)
857                    throws NoSuchLayoutSetPrototypeException, SystemException {
858                    List<LayoutSetPrototype> list = findByC_A(companyId, active, 0, 1,
859                                    orderByComparator);
860    
861                    if (list.isEmpty()) {
862                            StringBundler msg = new StringBundler(6);
863    
864                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
865    
866                            msg.append("companyId=");
867                            msg.append(companyId);
868    
869                            msg.append(", active=");
870                            msg.append(active);
871    
872                            msg.append(StringPool.CLOSE_CURLY_BRACE);
873    
874                            throw new NoSuchLayoutSetPrototypeException(msg.toString());
875                    }
876                    else {
877                            return list.get(0);
878                    }
879            }
880    
881            /**
882             * Finds the last layout set prototype in the ordered set where companyId = &#63; and active = &#63;.
883             *
884             * <p>
885             * 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.
886             * </p>
887             *
888             * @param companyId the company id to search with
889             * @param active the active to search with
890             * @param orderByComparator the comparator to order the set by
891             * @return the last matching layout set prototype
892             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a matching layout set prototype could not be found
893             * @throws SystemException if a system exception occurred
894             */
895            public LayoutSetPrototype findByC_A_Last(long companyId, boolean active,
896                    OrderByComparator orderByComparator)
897                    throws NoSuchLayoutSetPrototypeException, SystemException {
898                    int count = countByC_A(companyId, active);
899    
900                    List<LayoutSetPrototype> list = findByC_A(companyId, active, count - 1,
901                                    count, orderByComparator);
902    
903                    if (list.isEmpty()) {
904                            StringBundler msg = new StringBundler(6);
905    
906                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
907    
908                            msg.append("companyId=");
909                            msg.append(companyId);
910    
911                            msg.append(", active=");
912                            msg.append(active);
913    
914                            msg.append(StringPool.CLOSE_CURLY_BRACE);
915    
916                            throw new NoSuchLayoutSetPrototypeException(msg.toString());
917                    }
918                    else {
919                            return list.get(0);
920                    }
921            }
922    
923            /**
924             * Finds the layout set prototypes before and after the current layout set prototype in the ordered set where companyId = &#63; and active = &#63;.
925             *
926             * <p>
927             * 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.
928             * </p>
929             *
930             * @param layoutSetPrototypeId the primary key of the current layout set prototype
931             * @param companyId the company id to search with
932             * @param active the active to search with
933             * @param orderByComparator the comparator to order the set by
934             * @return the previous, current, and next layout set prototype
935             * @throws com.liferay.portal.NoSuchLayoutSetPrototypeException if a layout set prototype with the primary key could not be found
936             * @throws SystemException if a system exception occurred
937             */
938            public LayoutSetPrototype[] findByC_A_PrevAndNext(
939                    long layoutSetPrototypeId, long companyId, boolean active,
940                    OrderByComparator orderByComparator)
941                    throws NoSuchLayoutSetPrototypeException, SystemException {
942                    LayoutSetPrototype layoutSetPrototype = findByPrimaryKey(layoutSetPrototypeId);
943    
944                    Session session = null;
945    
946                    try {
947                            session = openSession();
948    
949                            LayoutSetPrototype[] array = new LayoutSetPrototypeImpl[3];
950    
951                            array[0] = getByC_A_PrevAndNext(session, layoutSetPrototype,
952                                            companyId, active, orderByComparator, true);
953    
954                            array[1] = layoutSetPrototype;
955    
956                            array[2] = getByC_A_PrevAndNext(session, layoutSetPrototype,
957                                            companyId, active, orderByComparator, false);
958    
959                            return array;
960                    }
961                    catch (Exception e) {
962                            throw processException(e);
963                    }
964                    finally {
965                            closeSession(session);
966                    }
967            }
968    
969            protected LayoutSetPrototype getByC_A_PrevAndNext(Session session,
970                    LayoutSetPrototype layoutSetPrototype, long companyId, boolean active,
971                    OrderByComparator orderByComparator, boolean previous) {
972                    StringBundler query = null;
973    
974                    if (orderByComparator != null) {
975                            query = new StringBundler(6 +
976                                            (orderByComparator.getOrderByFields().length * 6));
977                    }
978                    else {
979                            query = new StringBundler(3);
980                    }
981    
982                    query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE);
983    
984                    query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
985    
986                    query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
987    
988                    if (orderByComparator != null) {
989                            String[] orderByFields = orderByComparator.getOrderByFields();
990    
991                            if (orderByFields.length > 0) {
992                                    query.append(WHERE_AND);
993                            }
994    
995                            for (int i = 0; i < orderByFields.length; i++) {
996                                    query.append(_ORDER_BY_ENTITY_ALIAS);
997                                    query.append(orderByFields[i]);
998    
999                                    if ((i + 1) < orderByFields.length) {
1000                                            if (orderByComparator.isAscending() ^ previous) {
1001                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1002                                            }
1003                                            else {
1004                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1005                                            }
1006                                    }
1007                                    else {
1008                                            if (orderByComparator.isAscending() ^ previous) {
1009                                                    query.append(WHERE_GREATER_THAN);
1010                                            }
1011                                            else {
1012                                                    query.append(WHERE_LESSER_THAN);
1013                                            }
1014                                    }
1015                            }
1016    
1017                            query.append(ORDER_BY_CLAUSE);
1018    
1019                            for (int i = 0; i < orderByFields.length; i++) {
1020                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1021                                    query.append(orderByFields[i]);
1022    
1023                                    if ((i + 1) < orderByFields.length) {
1024                                            if (orderByComparator.isAscending() ^ previous) {
1025                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1026                                            }
1027                                            else {
1028                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1029                                            }
1030                                    }
1031                                    else {
1032                                            if (orderByComparator.isAscending() ^ previous) {
1033                                                    query.append(ORDER_BY_ASC);
1034                                            }
1035                                            else {
1036                                                    query.append(ORDER_BY_DESC);
1037                                            }
1038                                    }
1039                            }
1040                    }
1041    
1042                    String sql = query.toString();
1043    
1044                    Query q = session.createQuery(sql);
1045    
1046                    q.setFirstResult(0);
1047                    q.setMaxResults(2);
1048    
1049                    QueryPos qPos = QueryPos.getInstance(q);
1050    
1051                    qPos.add(companyId);
1052    
1053                    qPos.add(active);
1054    
1055                    if (orderByComparator != null) {
1056                            Object[] values = orderByComparator.getOrderByValues(layoutSetPrototype);
1057    
1058                            for (Object value : values) {
1059                                    qPos.add(value);
1060                            }
1061                    }
1062    
1063                    List<LayoutSetPrototype> list = q.list();
1064    
1065                    if (list.size() == 2) {
1066                            return list.get(1);
1067                    }
1068                    else {
1069                            return null;
1070                    }
1071            }
1072    
1073            /**
1074             * Finds all the layout set prototypes.
1075             *
1076             * @return the layout set prototypes
1077             * @throws SystemException if a system exception occurred
1078             */
1079            public List<LayoutSetPrototype> findAll() throws SystemException {
1080                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1081            }
1082    
1083            /**
1084             * Finds a range of all the layout set prototypes.
1085             *
1086             * <p>
1087             * 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.
1088             * </p>
1089             *
1090             * @param start the lower bound of the range of layout set prototypes to return
1091             * @param end the upper bound of the range of layout set prototypes to return (not inclusive)
1092             * @return the range of layout set prototypes
1093             * @throws SystemException if a system exception occurred
1094             */
1095            public List<LayoutSetPrototype> findAll(int start, int end)
1096                    throws SystemException {
1097                    return findAll(start, end, null);
1098            }
1099    
1100            /**
1101             * Finds an ordered range of all the layout set prototypes.
1102             *
1103             * <p>
1104             * 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.
1105             * </p>
1106             *
1107             * @param start the lower bound of the range of layout set prototypes to return
1108             * @param end the upper bound of the range of layout set prototypes to return (not inclusive)
1109             * @param orderByComparator the comparator to order the results by
1110             * @return the ordered range of layout set prototypes
1111             * @throws SystemException if a system exception occurred
1112             */
1113            public List<LayoutSetPrototype> findAll(int start, int end,
1114                    OrderByComparator orderByComparator) throws SystemException {
1115                    Object[] finderArgs = new Object[] {
1116                                    String.valueOf(start), String.valueOf(end),
1117                                    String.valueOf(orderByComparator)
1118                            };
1119    
1120                    List<LayoutSetPrototype> list = (List<LayoutSetPrototype>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1121                                    finderArgs, this);
1122    
1123                    if (list == null) {
1124                            Session session = null;
1125    
1126                            try {
1127                                    session = openSession();
1128    
1129                                    StringBundler query = null;
1130                                    String sql = null;
1131    
1132                                    if (orderByComparator != null) {
1133                                            query = new StringBundler(2 +
1134                                                            (orderByComparator.getOrderByFields().length * 3));
1135    
1136                                            query.append(_SQL_SELECT_LAYOUTSETPROTOTYPE);
1137    
1138                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1139                                                    orderByComparator);
1140    
1141                                            sql = query.toString();
1142                                    }
1143                                    else {
1144                                            sql = _SQL_SELECT_LAYOUTSETPROTOTYPE;
1145                                    }
1146    
1147                                    Query q = session.createQuery(sql);
1148    
1149                                    if (orderByComparator == null) {
1150                                            list = (List<LayoutSetPrototype>)QueryUtil.list(q,
1151                                                            getDialect(), start, end, false);
1152    
1153                                            Collections.sort(list);
1154                                    }
1155                                    else {
1156                                            list = (List<LayoutSetPrototype>)QueryUtil.list(q,
1157                                                            getDialect(), start, end);
1158                                    }
1159                            }
1160                            catch (Exception e) {
1161                                    throw processException(e);
1162                            }
1163                            finally {
1164                                    if (list == null) {
1165                                            list = new ArrayList<LayoutSetPrototype>();
1166                                    }
1167    
1168                                    cacheResult(list);
1169    
1170                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1171    
1172                                    closeSession(session);
1173                            }
1174                    }
1175    
1176                    return list;
1177            }
1178    
1179            /**
1180             * Removes all the layout set prototypes where companyId = &#63; from the database.
1181             *
1182             * @param companyId the company id to search with
1183             * @throws SystemException if a system exception occurred
1184             */
1185            public void removeByCompanyId(long companyId) throws SystemException {
1186                    for (LayoutSetPrototype layoutSetPrototype : findByCompanyId(companyId)) {
1187                            remove(layoutSetPrototype);
1188                    }
1189            }
1190    
1191            /**
1192             * Removes all the layout set prototypes where companyId = &#63; and active = &#63; from the database.
1193             *
1194             * @param companyId the company id to search with
1195             * @param active the active to search with
1196             * @throws SystemException if a system exception occurred
1197             */
1198            public void removeByC_A(long companyId, boolean active)
1199                    throws SystemException {
1200                    for (LayoutSetPrototype layoutSetPrototype : findByC_A(companyId, active)) {
1201                            remove(layoutSetPrototype);
1202                    }
1203            }
1204    
1205            /**
1206             * Removes all the layout set prototypes from the database.
1207             *
1208             * @throws SystemException if a system exception occurred
1209             */
1210            public void removeAll() throws SystemException {
1211                    for (LayoutSetPrototype layoutSetPrototype : findAll()) {
1212                            remove(layoutSetPrototype);
1213                    }
1214            }
1215    
1216            /**
1217             * Counts all the layout set prototypes where companyId = &#63;.
1218             *
1219             * @param companyId the company id to search with
1220             * @return the number of matching layout set prototypes
1221             * @throws SystemException if a system exception occurred
1222             */
1223            public int countByCompanyId(long companyId) throws SystemException {
1224                    Object[] finderArgs = new Object[] { companyId };
1225    
1226                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1227                                    finderArgs, this);
1228    
1229                    if (count == null) {
1230                            Session session = null;
1231    
1232                            try {
1233                                    session = openSession();
1234    
1235                                    StringBundler query = new StringBundler(2);
1236    
1237                                    query.append(_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
1238    
1239                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1240    
1241                                    String sql = query.toString();
1242    
1243                                    Query q = session.createQuery(sql);
1244    
1245                                    QueryPos qPos = QueryPos.getInstance(q);
1246    
1247                                    qPos.add(companyId);
1248    
1249                                    count = (Long)q.uniqueResult();
1250                            }
1251                            catch (Exception e) {
1252                                    throw processException(e);
1253                            }
1254                            finally {
1255                                    if (count == null) {
1256                                            count = Long.valueOf(0);
1257                                    }
1258    
1259                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1260                                            finderArgs, count);
1261    
1262                                    closeSession(session);
1263                            }
1264                    }
1265    
1266                    return count.intValue();
1267            }
1268    
1269            /**
1270             * Counts all the layout set prototypes where companyId = &#63; and active = &#63;.
1271             *
1272             * @param companyId the company id to search with
1273             * @param active the active to search with
1274             * @return the number of matching layout set prototypes
1275             * @throws SystemException if a system exception occurred
1276             */
1277            public int countByC_A(long companyId, boolean active)
1278                    throws SystemException {
1279                    Object[] finderArgs = new Object[] { companyId, active };
1280    
1281                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_A,
1282                                    finderArgs, this);
1283    
1284                    if (count == null) {
1285                            Session session = null;
1286    
1287                            try {
1288                                    session = openSession();
1289    
1290                                    StringBundler query = new StringBundler(3);
1291    
1292                                    query.append(_SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE);
1293    
1294                                    query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
1295    
1296                                    query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
1297    
1298                                    String sql = query.toString();
1299    
1300                                    Query q = session.createQuery(sql);
1301    
1302                                    QueryPos qPos = QueryPos.getInstance(q);
1303    
1304                                    qPos.add(companyId);
1305    
1306                                    qPos.add(active);
1307    
1308                                    count = (Long)q.uniqueResult();
1309                            }
1310                            catch (Exception e) {
1311                                    throw processException(e);
1312                            }
1313                            finally {
1314                                    if (count == null) {
1315                                            count = Long.valueOf(0);
1316                                    }
1317    
1318                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_A, finderArgs,
1319                                            count);
1320    
1321                                    closeSession(session);
1322                            }
1323                    }
1324    
1325                    return count.intValue();
1326            }
1327    
1328            /**
1329             * Counts all the layout set prototypes.
1330             *
1331             * @return the number of layout set prototypes
1332             * @throws SystemException if a system exception occurred
1333             */
1334            public int countAll() throws SystemException {
1335                    Object[] finderArgs = new Object[0];
1336    
1337                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1338                                    finderArgs, this);
1339    
1340                    if (count == null) {
1341                            Session session = null;
1342    
1343                            try {
1344                                    session = openSession();
1345    
1346                                    Query q = session.createQuery(_SQL_COUNT_LAYOUTSETPROTOTYPE);
1347    
1348                                    count = (Long)q.uniqueResult();
1349                            }
1350                            catch (Exception e) {
1351                                    throw processException(e);
1352                            }
1353                            finally {
1354                                    if (count == null) {
1355                                            count = Long.valueOf(0);
1356                                    }
1357    
1358                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1359                                            count);
1360    
1361                                    closeSession(session);
1362                            }
1363                    }
1364    
1365                    return count.intValue();
1366            }
1367    
1368            /**
1369             * Initializes the layout set prototype persistence.
1370             */
1371            public void afterPropertiesSet() {
1372                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1373                                            com.liferay.portal.util.PropsUtil.get(
1374                                                    "value.object.listener.com.liferay.portal.model.LayoutSetPrototype")));
1375    
1376                    if (listenerClassNames.length > 0) {
1377                            try {
1378                                    List<ModelListener<LayoutSetPrototype>> listenersList = new ArrayList<ModelListener<LayoutSetPrototype>>();
1379    
1380                                    for (String listenerClassName : listenerClassNames) {
1381                                            listenersList.add((ModelListener<LayoutSetPrototype>)InstanceFactory.newInstance(
1382                                                            listenerClassName));
1383                                    }
1384    
1385                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1386                            }
1387                            catch (Exception e) {
1388                                    _log.error(e);
1389                            }
1390                    }
1391            }
1392    
1393            public void destroy() {
1394                    EntityCacheUtil.removeCache(LayoutSetPrototypeImpl.class.getName());
1395                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1396                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1397            }
1398    
1399            @BeanReference(type = AccountPersistence.class)
1400            protected AccountPersistence accountPersistence;
1401            @BeanReference(type = AddressPersistence.class)
1402            protected AddressPersistence addressPersistence;
1403            @BeanReference(type = BrowserTrackerPersistence.class)
1404            protected BrowserTrackerPersistence browserTrackerPersistence;
1405            @BeanReference(type = ClassNamePersistence.class)
1406            protected ClassNamePersistence classNamePersistence;
1407            @BeanReference(type = ClusterGroupPersistence.class)
1408            protected ClusterGroupPersistence clusterGroupPersistence;
1409            @BeanReference(type = CompanyPersistence.class)
1410            protected CompanyPersistence companyPersistence;
1411            @BeanReference(type = ContactPersistence.class)
1412            protected ContactPersistence contactPersistence;
1413            @BeanReference(type = CountryPersistence.class)
1414            protected CountryPersistence countryPersistence;
1415            @BeanReference(type = EmailAddressPersistence.class)
1416            protected EmailAddressPersistence emailAddressPersistence;
1417            @BeanReference(type = GroupPersistence.class)
1418            protected GroupPersistence groupPersistence;
1419            @BeanReference(type = ImagePersistence.class)
1420            protected ImagePersistence imagePersistence;
1421            @BeanReference(type = LayoutPersistence.class)
1422            protected LayoutPersistence layoutPersistence;
1423            @BeanReference(type = LayoutPrototypePersistence.class)
1424            protected LayoutPrototypePersistence layoutPrototypePersistence;
1425            @BeanReference(type = LayoutSetPersistence.class)
1426            protected LayoutSetPersistence layoutSetPersistence;
1427            @BeanReference(type = LayoutSetPrototypePersistence.class)
1428            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1429            @BeanReference(type = ListTypePersistence.class)
1430            protected ListTypePersistence listTypePersistence;
1431            @BeanReference(type = LockPersistence.class)
1432            protected LockPersistence lockPersistence;
1433            @BeanReference(type = MembershipRequestPersistence.class)
1434            protected MembershipRequestPersistence membershipRequestPersistence;
1435            @BeanReference(type = OrganizationPersistence.class)
1436            protected OrganizationPersistence organizationPersistence;
1437            @BeanReference(type = OrgGroupPermissionPersistence.class)
1438            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1439            @BeanReference(type = OrgGroupRolePersistence.class)
1440            protected OrgGroupRolePersistence orgGroupRolePersistence;
1441            @BeanReference(type = OrgLaborPersistence.class)
1442            protected OrgLaborPersistence orgLaborPersistence;
1443            @BeanReference(type = PasswordPolicyPersistence.class)
1444            protected PasswordPolicyPersistence passwordPolicyPersistence;
1445            @BeanReference(type = PasswordPolicyRelPersistence.class)
1446            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1447            @BeanReference(type = PasswordTrackerPersistence.class)
1448            protected PasswordTrackerPersistence passwordTrackerPersistence;
1449            @BeanReference(type = PermissionPersistence.class)
1450            protected PermissionPersistence permissionPersistence;
1451            @BeanReference(type = PhonePersistence.class)
1452            protected PhonePersistence phonePersistence;
1453            @BeanReference(type = PluginSettingPersistence.class)
1454            protected PluginSettingPersistence pluginSettingPersistence;
1455            @BeanReference(type = PortletPersistence.class)
1456            protected PortletPersistence portletPersistence;
1457            @BeanReference(type = PortletItemPersistence.class)
1458            protected PortletItemPersistence portletItemPersistence;
1459            @BeanReference(type = PortletPreferencesPersistence.class)
1460            protected PortletPreferencesPersistence portletPreferencesPersistence;
1461            @BeanReference(type = RegionPersistence.class)
1462            protected RegionPersistence regionPersistence;
1463            @BeanReference(type = ReleasePersistence.class)
1464            protected ReleasePersistence releasePersistence;
1465            @BeanReference(type = ResourcePersistence.class)
1466            protected ResourcePersistence resourcePersistence;
1467            @BeanReference(type = ResourceActionPersistence.class)
1468            protected ResourceActionPersistence resourceActionPersistence;
1469            @BeanReference(type = ResourceCodePersistence.class)
1470            protected ResourceCodePersistence resourceCodePersistence;
1471            @BeanReference(type = ResourcePermissionPersistence.class)
1472            protected ResourcePermissionPersistence resourcePermissionPersistence;
1473            @BeanReference(type = RolePersistence.class)
1474            protected RolePersistence rolePersistence;
1475            @BeanReference(type = ServiceComponentPersistence.class)
1476            protected ServiceComponentPersistence serviceComponentPersistence;
1477            @BeanReference(type = ShardPersistence.class)
1478            protected ShardPersistence shardPersistence;
1479            @BeanReference(type = SubscriptionPersistence.class)
1480            protected SubscriptionPersistence subscriptionPersistence;
1481            @BeanReference(type = TicketPersistence.class)
1482            protected TicketPersistence ticketPersistence;
1483            @BeanReference(type = TeamPersistence.class)
1484            protected TeamPersistence teamPersistence;
1485            @BeanReference(type = UserPersistence.class)
1486            protected UserPersistence userPersistence;
1487            @BeanReference(type = UserGroupPersistence.class)
1488            protected UserGroupPersistence userGroupPersistence;
1489            @BeanReference(type = UserGroupGroupRolePersistence.class)
1490            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1491            @BeanReference(type = UserGroupRolePersistence.class)
1492            protected UserGroupRolePersistence userGroupRolePersistence;
1493            @BeanReference(type = UserIdMapperPersistence.class)
1494            protected UserIdMapperPersistence userIdMapperPersistence;
1495            @BeanReference(type = UserTrackerPersistence.class)
1496            protected UserTrackerPersistence userTrackerPersistence;
1497            @BeanReference(type = UserTrackerPathPersistence.class)
1498            protected UserTrackerPathPersistence userTrackerPathPersistence;
1499            @BeanReference(type = WebDAVPropsPersistence.class)
1500            protected WebDAVPropsPersistence webDAVPropsPersistence;
1501            @BeanReference(type = WebsitePersistence.class)
1502            protected WebsitePersistence websitePersistence;
1503            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1504            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1505            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1506            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1507            private static final String _SQL_SELECT_LAYOUTSETPROTOTYPE = "SELECT layoutSetPrototype FROM LayoutSetPrototype layoutSetPrototype";
1508            private static final String _SQL_SELECT_LAYOUTSETPROTOTYPE_WHERE = "SELECT layoutSetPrototype FROM LayoutSetPrototype layoutSetPrototype WHERE ";
1509            private static final String _SQL_COUNT_LAYOUTSETPROTOTYPE = "SELECT COUNT(layoutSetPrototype) FROM LayoutSetPrototype layoutSetPrototype";
1510            private static final String _SQL_COUNT_LAYOUTSETPROTOTYPE_WHERE = "SELECT COUNT(layoutSetPrototype) FROM LayoutSetPrototype layoutSetPrototype WHERE ";
1511            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "layoutSetPrototype.companyId = ?";
1512            private static final String _FINDER_COLUMN_C_A_COMPANYID_2 = "layoutSetPrototype.companyId = ? AND ";
1513            private static final String _FINDER_COLUMN_C_A_ACTIVE_2 = "layoutSetPrototype.active = ?";
1514            private static final String _ORDER_BY_ENTITY_ALIAS = "layoutSetPrototype.";
1515            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No LayoutSetPrototype exists with the primary key ";
1516            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No LayoutSetPrototype exists with the key {";
1517            private static Log _log = LogFactoryUtil.getLog(LayoutSetPrototypePersistenceImpl.class);
1518    }