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