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