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