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