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