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