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