001    /**
002     * Copyright (c) 2000-present 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.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.exception.NoSuchPortletPreferencesException;
020    import com.liferay.portal.kernel.bean.BeanReference;
021    import com.liferay.portal.kernel.dao.orm.EntityCache;
022    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderCache;
024    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
025    import com.liferay.portal.kernel.dao.orm.FinderPath;
026    import com.liferay.portal.kernel.dao.orm.Query;
027    import com.liferay.portal.kernel.dao.orm.QueryPos;
028    import com.liferay.portal.kernel.dao.orm.QueryUtil;
029    import com.liferay.portal.kernel.dao.orm.Session;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.Validator;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.MVCCModel;
038    import com.liferay.portal.model.PortletPreferences;
039    import com.liferay.portal.model.impl.PortletPreferencesImpl;
040    import com.liferay.portal.model.impl.PortletPreferencesModelImpl;
041    import com.liferay.portal.service.persistence.CompanyProvider;
042    import com.liferay.portal.service.persistence.CompanyProviderWrapper;
043    import com.liferay.portal.service.persistence.PortletPreferencesPersistence;
044    
045    import java.io.Serializable;
046    
047    import java.util.Collections;
048    import java.util.HashMap;
049    import java.util.HashSet;
050    import java.util.Iterator;
051    import java.util.List;
052    import java.util.Map;
053    import java.util.Set;
054    
055    /**
056     * The persistence implementation for the portlet preferences service.
057     *
058     * <p>
059     * Caching information and settings can be found in <code>portal.properties</code>
060     * </p>
061     *
062     * @author Brian Wing Shun Chan
063     * @see PortletPreferencesPersistence
064     * @see com.liferay.portal.service.persistence.PortletPreferencesUtil
065     * @generated
066     */
067    @ProviderType
068    public class PortletPreferencesPersistenceImpl extends BasePersistenceImpl<PortletPreferences>
069            implements PortletPreferencesPersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * 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.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = PortletPreferencesImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
081                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
082                            PortletPreferencesImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
085                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
086                            PortletPreferencesImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
088            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
089                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PLID = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
092                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
093                            PortletPreferencesImpl.class,
094                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByPlid",
095                            new String[] {
096                                    Long.class.getName(),
097                                    
098                            Integer.class.getName(), Integer.class.getName(),
099                                    OrderByComparator.class.getName()
100                            });
101            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PLID = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
102                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
103                            PortletPreferencesImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByPlid",
105                            new String[] { Long.class.getName() },
106                            PortletPreferencesModelImpl.PLID_COLUMN_BITMASK);
107            public static final FinderPath FINDER_PATH_COUNT_BY_PLID = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
108                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByPlid",
110                            new String[] { Long.class.getName() });
111    
112            /**
113             * Returns all the portlet preferenceses where plid = &#63;.
114             *
115             * @param plid the plid
116             * @return the matching portlet preferenceses
117             */
118            @Override
119            public List<PortletPreferences> findByPlid(long plid) {
120                    return findByPlid(plid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
121            }
122    
123            /**
124             * Returns a range of all the portlet preferenceses where plid = &#63;.
125             *
126             * <p>
127             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
128             * </p>
129             *
130             * @param plid the plid
131             * @param start the lower bound of the range of portlet preferenceses
132             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
133             * @return the range of matching portlet preferenceses
134             */
135            @Override
136            public List<PortletPreferences> findByPlid(long plid, int start, int end) {
137                    return findByPlid(plid, start, end, null);
138            }
139    
140            /**
141             * Returns an ordered range of all the portlet preferenceses where plid = &#63;.
142             *
143             * <p>
144             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
145             * </p>
146             *
147             * @param plid the plid
148             * @param start the lower bound of the range of portlet preferenceses
149             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
150             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
151             * @return the ordered range of matching portlet preferenceses
152             */
153            @Override
154            public List<PortletPreferences> findByPlid(long plid, int start, int end,
155                    OrderByComparator<PortletPreferences> orderByComparator) {
156                    return findByPlid(plid, start, end, orderByComparator, true);
157            }
158    
159            /**
160             * Returns an ordered range of all the portlet preferenceses where plid = &#63;.
161             *
162             * <p>
163             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
164             * </p>
165             *
166             * @param plid the plid
167             * @param start the lower bound of the range of portlet preferenceses
168             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
169             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
170             * @param retrieveFromCache whether to retrieve from the finder cache
171             * @return the ordered range of matching portlet preferenceses
172             */
173            @Override
174            public List<PortletPreferences> findByPlid(long plid, int start, int end,
175                    OrderByComparator<PortletPreferences> orderByComparator,
176                    boolean retrieveFromCache) {
177                    boolean pagination = true;
178                    FinderPath finderPath = null;
179                    Object[] finderArgs = null;
180    
181                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
182                                    (orderByComparator == null)) {
183                            pagination = false;
184                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PLID;
185                            finderArgs = new Object[] { plid };
186                    }
187                    else {
188                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PLID;
189                            finderArgs = new Object[] { plid, start, end, orderByComparator };
190                    }
191    
192                    List<PortletPreferences> list = null;
193    
194                    if (retrieveFromCache) {
195                            list = (List<PortletPreferences>)finderCache.getResult(finderPath,
196                                            finderArgs, this);
197    
198                            if ((list != null) && !list.isEmpty()) {
199                                    for (PortletPreferences portletPreferences : list) {
200                                            if ((plid != portletPreferences.getPlid())) {
201                                                    list = null;
202    
203                                                    break;
204                                            }
205                                    }
206                            }
207                    }
208    
209                    if (list == null) {
210                            StringBundler query = null;
211    
212                            if (orderByComparator != null) {
213                                    query = new StringBundler(3 +
214                                                    (orderByComparator.getOrderByFields().length * 2));
215                            }
216                            else {
217                                    query = new StringBundler(3);
218                            }
219    
220                            query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
221    
222                            query.append(_FINDER_COLUMN_PLID_PLID_2);
223    
224                            if (orderByComparator != null) {
225                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
226                                            orderByComparator);
227                            }
228                            else
229                             if (pagination) {
230                                    query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
231                            }
232    
233                            String sql = query.toString();
234    
235                            Session session = null;
236    
237                            try {
238                                    session = openSession();
239    
240                                    Query q = session.createQuery(sql);
241    
242                                    QueryPos qPos = QueryPos.getInstance(q);
243    
244                                    qPos.add(plid);
245    
246                                    if (!pagination) {
247                                            list = (List<PortletPreferences>)QueryUtil.list(q,
248                                                            getDialect(), start, end, false);
249    
250                                            Collections.sort(list);
251    
252                                            list = Collections.unmodifiableList(list);
253                                    }
254                                    else {
255                                            list = (List<PortletPreferences>)QueryUtil.list(q,
256                                                            getDialect(), start, end);
257                                    }
258    
259                                    cacheResult(list);
260    
261                                    finderCache.putResult(finderPath, finderArgs, list);
262                            }
263                            catch (Exception e) {
264                                    finderCache.removeResult(finderPath, finderArgs);
265    
266                                    throw processException(e);
267                            }
268                            finally {
269                                    closeSession(session);
270                            }
271                    }
272    
273                    return list;
274            }
275    
276            /**
277             * Returns the first portlet preferences in the ordered set where plid = &#63;.
278             *
279             * @param plid the plid
280             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
281             * @return the first matching portlet preferences
282             * @throws NoSuchPortletPreferencesException if a matching portlet preferences could not be found
283             */
284            @Override
285            public PortletPreferences findByPlid_First(long plid,
286                    OrderByComparator<PortletPreferences> orderByComparator)
287                    throws NoSuchPortletPreferencesException {
288                    PortletPreferences portletPreferences = fetchByPlid_First(plid,
289                                    orderByComparator);
290    
291                    if (portletPreferences != null) {
292                            return portletPreferences;
293                    }
294    
295                    StringBundler msg = new StringBundler(4);
296    
297                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
298    
299                    msg.append("plid=");
300                    msg.append(plid);
301    
302                    msg.append(StringPool.CLOSE_CURLY_BRACE);
303    
304                    throw new NoSuchPortletPreferencesException(msg.toString());
305            }
306    
307            /**
308             * Returns the first portlet preferences in the ordered set where plid = &#63;.
309             *
310             * @param plid the plid
311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
312             * @return the first matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
313             */
314            @Override
315            public PortletPreferences fetchByPlid_First(long plid,
316                    OrderByComparator<PortletPreferences> orderByComparator) {
317                    List<PortletPreferences> list = findByPlid(plid, 0, 1, orderByComparator);
318    
319                    if (!list.isEmpty()) {
320                            return list.get(0);
321                    }
322    
323                    return null;
324            }
325    
326            /**
327             * Returns the last portlet preferences in the ordered set where plid = &#63;.
328             *
329             * @param plid the plid
330             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
331             * @return the last matching portlet preferences
332             * @throws NoSuchPortletPreferencesException if a matching portlet preferences could not be found
333             */
334            @Override
335            public PortletPreferences findByPlid_Last(long plid,
336                    OrderByComparator<PortletPreferences> orderByComparator)
337                    throws NoSuchPortletPreferencesException {
338                    PortletPreferences portletPreferences = fetchByPlid_Last(plid,
339                                    orderByComparator);
340    
341                    if (portletPreferences != null) {
342                            return portletPreferences;
343                    }
344    
345                    StringBundler msg = new StringBundler(4);
346    
347                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
348    
349                    msg.append("plid=");
350                    msg.append(plid);
351    
352                    msg.append(StringPool.CLOSE_CURLY_BRACE);
353    
354                    throw new NoSuchPortletPreferencesException(msg.toString());
355            }
356    
357            /**
358             * Returns the last portlet preferences in the ordered set where plid = &#63;.
359             *
360             * @param plid the plid
361             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
362             * @return the last matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
363             */
364            @Override
365            public PortletPreferences fetchByPlid_Last(long plid,
366                    OrderByComparator<PortletPreferences> orderByComparator) {
367                    int count = countByPlid(plid);
368    
369                    if (count == 0) {
370                            return null;
371                    }
372    
373                    List<PortletPreferences> list = findByPlid(plid, count - 1, count,
374                                    orderByComparator);
375    
376                    if (!list.isEmpty()) {
377                            return list.get(0);
378                    }
379    
380                    return null;
381            }
382    
383            /**
384             * Returns the portlet preferenceses before and after the current portlet preferences in the ordered set where plid = &#63;.
385             *
386             * @param portletPreferencesId the primary key of the current portlet preferences
387             * @param plid the plid
388             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
389             * @return the previous, current, and next portlet preferences
390             * @throws NoSuchPortletPreferencesException if a portlet preferences with the primary key could not be found
391             */
392            @Override
393            public PortletPreferences[] findByPlid_PrevAndNext(
394                    long portletPreferencesId, long plid,
395                    OrderByComparator<PortletPreferences> orderByComparator)
396                    throws NoSuchPortletPreferencesException {
397                    PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
398    
399                    Session session = null;
400    
401                    try {
402                            session = openSession();
403    
404                            PortletPreferences[] array = new PortletPreferencesImpl[3];
405    
406                            array[0] = getByPlid_PrevAndNext(session, portletPreferences, plid,
407                                            orderByComparator, true);
408    
409                            array[1] = portletPreferences;
410    
411                            array[2] = getByPlid_PrevAndNext(session, portletPreferences, plid,
412                                            orderByComparator, false);
413    
414                            return array;
415                    }
416                    catch (Exception e) {
417                            throw processException(e);
418                    }
419                    finally {
420                            closeSession(session);
421                    }
422            }
423    
424            protected PortletPreferences getByPlid_PrevAndNext(Session session,
425                    PortletPreferences portletPreferences, long plid,
426                    OrderByComparator<PortletPreferences> orderByComparator,
427                    boolean previous) {
428                    StringBundler query = null;
429    
430                    if (orderByComparator != null) {
431                            query = new StringBundler(4 +
432                                            (orderByComparator.getOrderByConditionFields().length * 3) +
433                                            (orderByComparator.getOrderByFields().length * 3));
434                    }
435                    else {
436                            query = new StringBundler(3);
437                    }
438    
439                    query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
440    
441                    query.append(_FINDER_COLUMN_PLID_PLID_2);
442    
443                    if (orderByComparator != null) {
444                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
445    
446                            if (orderByConditionFields.length > 0) {
447                                    query.append(WHERE_AND);
448                            }
449    
450                            for (int i = 0; i < orderByConditionFields.length; i++) {
451                                    query.append(_ORDER_BY_ENTITY_ALIAS);
452                                    query.append(orderByConditionFields[i]);
453    
454                                    if ((i + 1) < orderByConditionFields.length) {
455                                            if (orderByComparator.isAscending() ^ previous) {
456                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
457                                            }
458                                            else {
459                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
460                                            }
461                                    }
462                                    else {
463                                            if (orderByComparator.isAscending() ^ previous) {
464                                                    query.append(WHERE_GREATER_THAN);
465                                            }
466                                            else {
467                                                    query.append(WHERE_LESSER_THAN);
468                                            }
469                                    }
470                            }
471    
472                            query.append(ORDER_BY_CLAUSE);
473    
474                            String[] orderByFields = orderByComparator.getOrderByFields();
475    
476                            for (int i = 0; i < orderByFields.length; i++) {
477                                    query.append(_ORDER_BY_ENTITY_ALIAS);
478                                    query.append(orderByFields[i]);
479    
480                                    if ((i + 1) < orderByFields.length) {
481                                            if (orderByComparator.isAscending() ^ previous) {
482                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
483                                            }
484                                            else {
485                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
486                                            }
487                                    }
488                                    else {
489                                            if (orderByComparator.isAscending() ^ previous) {
490                                                    query.append(ORDER_BY_ASC);
491                                            }
492                                            else {
493                                                    query.append(ORDER_BY_DESC);
494                                            }
495                                    }
496                            }
497                    }
498                    else {
499                            query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
500                    }
501    
502                    String sql = query.toString();
503    
504                    Query q = session.createQuery(sql);
505    
506                    q.setFirstResult(0);
507                    q.setMaxResults(2);
508    
509                    QueryPos qPos = QueryPos.getInstance(q);
510    
511                    qPos.add(plid);
512    
513                    if (orderByComparator != null) {
514                            Object[] values = orderByComparator.getOrderByConditionValues(portletPreferences);
515    
516                            for (Object value : values) {
517                                    qPos.add(value);
518                            }
519                    }
520    
521                    List<PortletPreferences> list = q.list();
522    
523                    if (list.size() == 2) {
524                            return list.get(1);
525                    }
526                    else {
527                            return null;
528                    }
529            }
530    
531            /**
532             * Removes all the portlet preferenceses where plid = &#63; from the database.
533             *
534             * @param plid the plid
535             */
536            @Override
537            public void removeByPlid(long plid) {
538                    for (PortletPreferences portletPreferences : findByPlid(plid,
539                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
540                            remove(portletPreferences);
541                    }
542            }
543    
544            /**
545             * Returns the number of portlet preferenceses where plid = &#63;.
546             *
547             * @param plid the plid
548             * @return the number of matching portlet preferenceses
549             */
550            @Override
551            public int countByPlid(long plid) {
552                    FinderPath finderPath = FINDER_PATH_COUNT_BY_PLID;
553    
554                    Object[] finderArgs = new Object[] { plid };
555    
556                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
557    
558                    if (count == null) {
559                            StringBundler query = new StringBundler(2);
560    
561                            query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
562    
563                            query.append(_FINDER_COLUMN_PLID_PLID_2);
564    
565                            String sql = query.toString();
566    
567                            Session session = null;
568    
569                            try {
570                                    session = openSession();
571    
572                                    Query q = session.createQuery(sql);
573    
574                                    QueryPos qPos = QueryPos.getInstance(q);
575    
576                                    qPos.add(plid);
577    
578                                    count = (Long)q.uniqueResult();
579    
580                                    finderCache.putResult(finderPath, finderArgs, count);
581                            }
582                            catch (Exception e) {
583                                    finderCache.removeResult(finderPath, finderArgs);
584    
585                                    throw processException(e);
586                            }
587                            finally {
588                                    closeSession(session);
589                            }
590                    }
591    
592                    return count.intValue();
593            }
594    
595            private static final String _FINDER_COLUMN_PLID_PLID_2 = "portletPreferences.plid = ?";
596            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PORTLETID =
597                    new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
598                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
599                            PortletPreferencesImpl.class,
600                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByPortletId",
601                            new String[] {
602                                    String.class.getName(),
603                                    
604                            Integer.class.getName(), Integer.class.getName(),
605                                    OrderByComparator.class.getName()
606                            });
607            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORTLETID =
608                    new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
609                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
610                            PortletPreferencesImpl.class,
611                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByPortletId",
612                            new String[] { String.class.getName() },
613                            PortletPreferencesModelImpl.PORTLETID_COLUMN_BITMASK);
614            public static final FinderPath FINDER_PATH_COUNT_BY_PORTLETID = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
615                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
616                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByPortletId",
617                            new String[] { String.class.getName() });
618    
619            /**
620             * Returns all the portlet preferenceses where portletId = &#63;.
621             *
622             * @param portletId the portlet ID
623             * @return the matching portlet preferenceses
624             */
625            @Override
626            public List<PortletPreferences> findByPortletId(String portletId) {
627                    return findByPortletId(portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
628                            null);
629            }
630    
631            /**
632             * Returns a range of all the portlet preferenceses where portletId = &#63;.
633             *
634             * <p>
635             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
636             * </p>
637             *
638             * @param portletId the portlet ID
639             * @param start the lower bound of the range of portlet preferenceses
640             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
641             * @return the range of matching portlet preferenceses
642             */
643            @Override
644            public List<PortletPreferences> findByPortletId(String portletId,
645                    int start, int end) {
646                    return findByPortletId(portletId, start, end, null);
647            }
648    
649            /**
650             * Returns an ordered range of all the portlet preferenceses where portletId = &#63;.
651             *
652             * <p>
653             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
654             * </p>
655             *
656             * @param portletId the portlet ID
657             * @param start the lower bound of the range of portlet preferenceses
658             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
659             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
660             * @return the ordered range of matching portlet preferenceses
661             */
662            @Override
663            public List<PortletPreferences> findByPortletId(String portletId,
664                    int start, int end,
665                    OrderByComparator<PortletPreferences> orderByComparator) {
666                    return findByPortletId(portletId, start, end, orderByComparator, true);
667            }
668    
669            /**
670             * Returns an ordered range of all the portlet preferenceses where portletId = &#63;.
671             *
672             * <p>
673             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
674             * </p>
675             *
676             * @param portletId the portlet ID
677             * @param start the lower bound of the range of portlet preferenceses
678             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
679             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
680             * @param retrieveFromCache whether to retrieve from the finder cache
681             * @return the ordered range of matching portlet preferenceses
682             */
683            @Override
684            public List<PortletPreferences> findByPortletId(String portletId,
685                    int start, int end,
686                    OrderByComparator<PortletPreferences> orderByComparator,
687                    boolean retrieveFromCache) {
688                    boolean pagination = true;
689                    FinderPath finderPath = null;
690                    Object[] finderArgs = null;
691    
692                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
693                                    (orderByComparator == null)) {
694                            pagination = false;
695                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORTLETID;
696                            finderArgs = new Object[] { portletId };
697                    }
698                    else {
699                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PORTLETID;
700                            finderArgs = new Object[] { portletId, start, end, orderByComparator };
701                    }
702    
703                    List<PortletPreferences> list = null;
704    
705                    if (retrieveFromCache) {
706                            list = (List<PortletPreferences>)finderCache.getResult(finderPath,
707                                            finderArgs, this);
708    
709                            if ((list != null) && !list.isEmpty()) {
710                                    for (PortletPreferences portletPreferences : list) {
711                                            if (!Validator.equals(portletId,
712                                                                    portletPreferences.getPortletId())) {
713                                                    list = null;
714    
715                                                    break;
716                                            }
717                                    }
718                            }
719                    }
720    
721                    if (list == null) {
722                            StringBundler query = null;
723    
724                            if (orderByComparator != null) {
725                                    query = new StringBundler(3 +
726                                                    (orderByComparator.getOrderByFields().length * 2));
727                            }
728                            else {
729                                    query = new StringBundler(3);
730                            }
731    
732                            query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
733    
734                            boolean bindPortletId = false;
735    
736                            if (portletId == null) {
737                                    query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_1);
738                            }
739                            else if (portletId.equals(StringPool.BLANK)) {
740                                    query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_3);
741                            }
742                            else {
743                                    bindPortletId = true;
744    
745                                    query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_2);
746                            }
747    
748                            if (orderByComparator != null) {
749                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
750                                            orderByComparator);
751                            }
752                            else
753                             if (pagination) {
754                                    query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
755                            }
756    
757                            String sql = query.toString();
758    
759                            Session session = null;
760    
761                            try {
762                                    session = openSession();
763    
764                                    Query q = session.createQuery(sql);
765    
766                                    QueryPos qPos = QueryPos.getInstance(q);
767    
768                                    if (bindPortletId) {
769                                            qPos.add(portletId);
770                                    }
771    
772                                    if (!pagination) {
773                                            list = (List<PortletPreferences>)QueryUtil.list(q,
774                                                            getDialect(), start, end, false);
775    
776                                            Collections.sort(list);
777    
778                                            list = Collections.unmodifiableList(list);
779                                    }
780                                    else {
781                                            list = (List<PortletPreferences>)QueryUtil.list(q,
782                                                            getDialect(), start, end);
783                                    }
784    
785                                    cacheResult(list);
786    
787                                    finderCache.putResult(finderPath, finderArgs, list);
788                            }
789                            catch (Exception e) {
790                                    finderCache.removeResult(finderPath, finderArgs);
791    
792                                    throw processException(e);
793                            }
794                            finally {
795                                    closeSession(session);
796                            }
797                    }
798    
799                    return list;
800            }
801    
802            /**
803             * Returns the first portlet preferences in the ordered set where portletId = &#63;.
804             *
805             * @param portletId the portlet ID
806             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
807             * @return the first matching portlet preferences
808             * @throws NoSuchPortletPreferencesException if a matching portlet preferences could not be found
809             */
810            @Override
811            public PortletPreferences findByPortletId_First(String portletId,
812                    OrderByComparator<PortletPreferences> orderByComparator)
813                    throws NoSuchPortletPreferencesException {
814                    PortletPreferences portletPreferences = fetchByPortletId_First(portletId,
815                                    orderByComparator);
816    
817                    if (portletPreferences != null) {
818                            return portletPreferences;
819                    }
820    
821                    StringBundler msg = new StringBundler(4);
822    
823                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
824    
825                    msg.append("portletId=");
826                    msg.append(portletId);
827    
828                    msg.append(StringPool.CLOSE_CURLY_BRACE);
829    
830                    throw new NoSuchPortletPreferencesException(msg.toString());
831            }
832    
833            /**
834             * Returns the first portlet preferences in the ordered set where portletId = &#63;.
835             *
836             * @param portletId the portlet ID
837             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
838             * @return the first matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
839             */
840            @Override
841            public PortletPreferences fetchByPortletId_First(String portletId,
842                    OrderByComparator<PortletPreferences> orderByComparator) {
843                    List<PortletPreferences> list = findByPortletId(portletId, 0, 1,
844                                    orderByComparator);
845    
846                    if (!list.isEmpty()) {
847                            return list.get(0);
848                    }
849    
850                    return null;
851            }
852    
853            /**
854             * Returns the last portlet preferences in the ordered set where portletId = &#63;.
855             *
856             * @param portletId the portlet ID
857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
858             * @return the last matching portlet preferences
859             * @throws NoSuchPortletPreferencesException if a matching portlet preferences could not be found
860             */
861            @Override
862            public PortletPreferences findByPortletId_Last(String portletId,
863                    OrderByComparator<PortletPreferences> orderByComparator)
864                    throws NoSuchPortletPreferencesException {
865                    PortletPreferences portletPreferences = fetchByPortletId_Last(portletId,
866                                    orderByComparator);
867    
868                    if (portletPreferences != null) {
869                            return portletPreferences;
870                    }
871    
872                    StringBundler msg = new StringBundler(4);
873    
874                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
875    
876                    msg.append("portletId=");
877                    msg.append(portletId);
878    
879                    msg.append(StringPool.CLOSE_CURLY_BRACE);
880    
881                    throw new NoSuchPortletPreferencesException(msg.toString());
882            }
883    
884            /**
885             * Returns the last portlet preferences in the ordered set where portletId = &#63;.
886             *
887             * @param portletId the portlet ID
888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
889             * @return the last matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
890             */
891            @Override
892            public PortletPreferences fetchByPortletId_Last(String portletId,
893                    OrderByComparator<PortletPreferences> orderByComparator) {
894                    int count = countByPortletId(portletId);
895    
896                    if (count == 0) {
897                            return null;
898                    }
899    
900                    List<PortletPreferences> list = findByPortletId(portletId, count - 1,
901                                    count, orderByComparator);
902    
903                    if (!list.isEmpty()) {
904                            return list.get(0);
905                    }
906    
907                    return null;
908            }
909    
910            /**
911             * Returns the portlet preferenceses before and after the current portlet preferences in the ordered set where portletId = &#63;.
912             *
913             * @param portletPreferencesId the primary key of the current portlet preferences
914             * @param portletId the portlet ID
915             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
916             * @return the previous, current, and next portlet preferences
917             * @throws NoSuchPortletPreferencesException if a portlet preferences with the primary key could not be found
918             */
919            @Override
920            public PortletPreferences[] findByPortletId_PrevAndNext(
921                    long portletPreferencesId, String portletId,
922                    OrderByComparator<PortletPreferences> orderByComparator)
923                    throws NoSuchPortletPreferencesException {
924                    PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
925    
926                    Session session = null;
927    
928                    try {
929                            session = openSession();
930    
931                            PortletPreferences[] array = new PortletPreferencesImpl[3];
932    
933                            array[0] = getByPortletId_PrevAndNext(session, portletPreferences,
934                                            portletId, orderByComparator, true);
935    
936                            array[1] = portletPreferences;
937    
938                            array[2] = getByPortletId_PrevAndNext(session, portletPreferences,
939                                            portletId, orderByComparator, false);
940    
941                            return array;
942                    }
943                    catch (Exception e) {
944                            throw processException(e);
945                    }
946                    finally {
947                            closeSession(session);
948                    }
949            }
950    
951            protected PortletPreferences getByPortletId_PrevAndNext(Session session,
952                    PortletPreferences portletPreferences, String portletId,
953                    OrderByComparator<PortletPreferences> orderByComparator,
954                    boolean previous) {
955                    StringBundler query = null;
956    
957                    if (orderByComparator != null) {
958                            query = new StringBundler(4 +
959                                            (orderByComparator.getOrderByConditionFields().length * 3) +
960                                            (orderByComparator.getOrderByFields().length * 3));
961                    }
962                    else {
963                            query = new StringBundler(3);
964                    }
965    
966                    query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
967    
968                    boolean bindPortletId = false;
969    
970                    if (portletId == null) {
971                            query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_1);
972                    }
973                    else if (portletId.equals(StringPool.BLANK)) {
974                            query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_3);
975                    }
976                    else {
977                            bindPortletId = true;
978    
979                            query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_2);
980                    }
981    
982                    if (orderByComparator != null) {
983                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
984    
985                            if (orderByConditionFields.length > 0) {
986                                    query.append(WHERE_AND);
987                            }
988    
989                            for (int i = 0; i < orderByConditionFields.length; i++) {
990                                    query.append(_ORDER_BY_ENTITY_ALIAS);
991                                    query.append(orderByConditionFields[i]);
992    
993                                    if ((i + 1) < orderByConditionFields.length) {
994                                            if (orderByComparator.isAscending() ^ previous) {
995                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
996                                            }
997                                            else {
998                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
999                                            }
1000                                    }
1001                                    else {
1002                                            if (orderByComparator.isAscending() ^ previous) {
1003                                                    query.append(WHERE_GREATER_THAN);
1004                                            }
1005                                            else {
1006                                                    query.append(WHERE_LESSER_THAN);
1007                                            }
1008                                    }
1009                            }
1010    
1011                            query.append(ORDER_BY_CLAUSE);
1012    
1013                            String[] orderByFields = orderByComparator.getOrderByFields();
1014    
1015                            for (int i = 0; i < orderByFields.length; i++) {
1016                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1017                                    query.append(orderByFields[i]);
1018    
1019                                    if ((i + 1) < orderByFields.length) {
1020                                            if (orderByComparator.isAscending() ^ previous) {
1021                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1022                                            }
1023                                            else {
1024                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1025                                            }
1026                                    }
1027                                    else {
1028                                            if (orderByComparator.isAscending() ^ previous) {
1029                                                    query.append(ORDER_BY_ASC);
1030                                            }
1031                                            else {
1032                                                    query.append(ORDER_BY_DESC);
1033                                            }
1034                                    }
1035                            }
1036                    }
1037                    else {
1038                            query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
1039                    }
1040    
1041                    String sql = query.toString();
1042    
1043                    Query q = session.createQuery(sql);
1044    
1045                    q.setFirstResult(0);
1046                    q.setMaxResults(2);
1047    
1048                    QueryPos qPos = QueryPos.getInstance(q);
1049    
1050                    if (bindPortletId) {
1051                            qPos.add(portletId);
1052                    }
1053    
1054                    if (orderByComparator != null) {
1055                            Object[] values = orderByComparator.getOrderByConditionValues(portletPreferences);
1056    
1057                            for (Object value : values) {
1058                                    qPos.add(value);
1059                            }
1060                    }
1061    
1062                    List<PortletPreferences> list = q.list();
1063    
1064                    if (list.size() == 2) {
1065                            return list.get(1);
1066                    }
1067                    else {
1068                            return null;
1069                    }
1070            }
1071    
1072            /**
1073             * Removes all the portlet preferenceses where portletId = &#63; from the database.
1074             *
1075             * @param portletId the portlet ID
1076             */
1077            @Override
1078            public void removeByPortletId(String portletId) {
1079                    for (PortletPreferences portletPreferences : findByPortletId(
1080                                    portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1081                            remove(portletPreferences);
1082                    }
1083            }
1084    
1085            /**
1086             * Returns the number of portlet preferenceses where portletId = &#63;.
1087             *
1088             * @param portletId the portlet ID
1089             * @return the number of matching portlet preferenceses
1090             */
1091            @Override
1092            public int countByPortletId(String portletId) {
1093                    FinderPath finderPath = FINDER_PATH_COUNT_BY_PORTLETID;
1094    
1095                    Object[] finderArgs = new Object[] { portletId };
1096    
1097                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1098    
1099                    if (count == null) {
1100                            StringBundler query = new StringBundler(2);
1101    
1102                            query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
1103    
1104                            boolean bindPortletId = false;
1105    
1106                            if (portletId == null) {
1107                                    query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_1);
1108                            }
1109                            else if (portletId.equals(StringPool.BLANK)) {
1110                                    query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_3);
1111                            }
1112                            else {
1113                                    bindPortletId = true;
1114    
1115                                    query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_2);
1116                            }
1117    
1118                            String sql = query.toString();
1119    
1120                            Session session = null;
1121    
1122                            try {
1123                                    session = openSession();
1124    
1125                                    Query q = session.createQuery(sql);
1126    
1127                                    QueryPos qPos = QueryPos.getInstance(q);
1128    
1129                                    if (bindPortletId) {
1130                                            qPos.add(portletId);
1131                                    }
1132    
1133                                    count = (Long)q.uniqueResult();
1134    
1135                                    finderCache.putResult(finderPath, finderArgs, count);
1136                            }
1137                            catch (Exception e) {
1138                                    finderCache.removeResult(finderPath, finderArgs);
1139    
1140                                    throw processException(e);
1141                            }
1142                            finally {
1143                                    closeSession(session);
1144                            }
1145                    }
1146    
1147                    return count.intValue();
1148            }
1149    
1150            private static final String _FINDER_COLUMN_PORTLETID_PORTLETID_1 = "portletPreferences.portletId IS NULL";
1151            private static final String _FINDER_COLUMN_PORTLETID_PORTLETID_2 = "portletPreferences.portletId = ?";
1152            private static final String _FINDER_COLUMN_PORTLETID_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = '')";
1153            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
1154                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
1155                            PortletPreferencesImpl.class,
1156                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByO_P",
1157                            new String[] {
1158                                    Integer.class.getName(), String.class.getName(),
1159                                    
1160                            Integer.class.getName(), Integer.class.getName(),
1161                                    OrderByComparator.class.getName()
1162                            });
1163            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
1164                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
1165                            PortletPreferencesImpl.class,
1166                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByO_P",
1167                            new String[] { Integer.class.getName(), String.class.getName() },
1168                            PortletPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK |
1169                            PortletPreferencesModelImpl.PORTLETID_COLUMN_BITMASK);
1170            public static final FinderPath FINDER_PATH_COUNT_BY_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
1171                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
1172                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_P",
1173                            new String[] { Integer.class.getName(), String.class.getName() });
1174    
1175            /**
1176             * Returns all the portlet preferenceses where ownerType = &#63; and portletId = &#63;.
1177             *
1178             * @param ownerType the owner type
1179             * @param portletId the portlet ID
1180             * @return the matching portlet preferenceses
1181             */
1182            @Override
1183            public List<PortletPreferences> findByO_P(int ownerType, String portletId) {
1184                    return findByO_P(ownerType, portletId, QueryUtil.ALL_POS,
1185                            QueryUtil.ALL_POS, null);
1186            }
1187    
1188            /**
1189             * Returns a range of all the portlet preferenceses where ownerType = &#63; and portletId = &#63;.
1190             *
1191             * <p>
1192             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1193             * </p>
1194             *
1195             * @param ownerType the owner type
1196             * @param portletId the portlet ID
1197             * @param start the lower bound of the range of portlet preferenceses
1198             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
1199             * @return the range of matching portlet preferenceses
1200             */
1201            @Override
1202            public List<PortletPreferences> findByO_P(int ownerType, String portletId,
1203                    int start, int end) {
1204                    return findByO_P(ownerType, portletId, start, end, null);
1205            }
1206    
1207            /**
1208             * Returns an ordered range of all the portlet preferenceses where ownerType = &#63; and portletId = &#63;.
1209             *
1210             * <p>
1211             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1212             * </p>
1213             *
1214             * @param ownerType the owner type
1215             * @param portletId the portlet ID
1216             * @param start the lower bound of the range of portlet preferenceses
1217             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
1218             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1219             * @return the ordered range of matching portlet preferenceses
1220             */
1221            @Override
1222            public List<PortletPreferences> findByO_P(int ownerType, String portletId,
1223                    int start, int end,
1224                    OrderByComparator<PortletPreferences> orderByComparator) {
1225                    return findByO_P(ownerType, portletId, start, end, orderByComparator,
1226                            true);
1227            }
1228    
1229            /**
1230             * Returns an ordered range of all the portlet preferenceses where ownerType = &#63; and portletId = &#63;.
1231             *
1232             * <p>
1233             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1234             * </p>
1235             *
1236             * @param ownerType the owner type
1237             * @param portletId the portlet ID
1238             * @param start the lower bound of the range of portlet preferenceses
1239             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
1240             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1241             * @param retrieveFromCache whether to retrieve from the finder cache
1242             * @return the ordered range of matching portlet preferenceses
1243             */
1244            @Override
1245            public List<PortletPreferences> findByO_P(int ownerType, String portletId,
1246                    int start, int end,
1247                    OrderByComparator<PortletPreferences> orderByComparator,
1248                    boolean retrieveFromCache) {
1249                    boolean pagination = true;
1250                    FinderPath finderPath = null;
1251                    Object[] finderArgs = null;
1252    
1253                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1254                                    (orderByComparator == null)) {
1255                            pagination = false;
1256                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P;
1257                            finderArgs = new Object[] { ownerType, portletId };
1258                    }
1259                    else {
1260                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_O_P;
1261                            finderArgs = new Object[] {
1262                                            ownerType, portletId,
1263                                            
1264                                            start, end, orderByComparator
1265                                    };
1266                    }
1267    
1268                    List<PortletPreferences> list = null;
1269    
1270                    if (retrieveFromCache) {
1271                            list = (List<PortletPreferences>)finderCache.getResult(finderPath,
1272                                            finderArgs, this);
1273    
1274                            if ((list != null) && !list.isEmpty()) {
1275                                    for (PortletPreferences portletPreferences : list) {
1276                                            if ((ownerType != portletPreferences.getOwnerType()) ||
1277                                                            !Validator.equals(portletId,
1278                                                                    portletPreferences.getPortletId())) {
1279                                                    list = null;
1280    
1281                                                    break;
1282                                            }
1283                                    }
1284                            }
1285                    }
1286    
1287                    if (list == null) {
1288                            StringBundler query = null;
1289    
1290                            if (orderByComparator != null) {
1291                                    query = new StringBundler(4 +
1292                                                    (orderByComparator.getOrderByFields().length * 2));
1293                            }
1294                            else {
1295                                    query = new StringBundler(4);
1296                            }
1297    
1298                            query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1299    
1300                            query.append(_FINDER_COLUMN_O_P_OWNERTYPE_2);
1301    
1302                            boolean bindPortletId = false;
1303    
1304                            if (portletId == null) {
1305                                    query.append(_FINDER_COLUMN_O_P_PORTLETID_1);
1306                            }
1307                            else if (portletId.equals(StringPool.BLANK)) {
1308                                    query.append(_FINDER_COLUMN_O_P_PORTLETID_3);
1309                            }
1310                            else {
1311                                    bindPortletId = true;
1312    
1313                                    query.append(_FINDER_COLUMN_O_P_PORTLETID_2);
1314                            }
1315    
1316                            if (orderByComparator != null) {
1317                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1318                                            orderByComparator);
1319                            }
1320                            else
1321                             if (pagination) {
1322                                    query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
1323                            }
1324    
1325                            String sql = query.toString();
1326    
1327                            Session session = null;
1328    
1329                            try {
1330                                    session = openSession();
1331    
1332                                    Query q = session.createQuery(sql);
1333    
1334                                    QueryPos qPos = QueryPos.getInstance(q);
1335    
1336                                    qPos.add(ownerType);
1337    
1338                                    if (bindPortletId) {
1339                                            qPos.add(portletId);
1340                                    }
1341    
1342                                    if (!pagination) {
1343                                            list = (List<PortletPreferences>)QueryUtil.list(q,
1344                                                            getDialect(), start, end, false);
1345    
1346                                            Collections.sort(list);
1347    
1348                                            list = Collections.unmodifiableList(list);
1349                                    }
1350                                    else {
1351                                            list = (List<PortletPreferences>)QueryUtil.list(q,
1352                                                            getDialect(), start, end);
1353                                    }
1354    
1355                                    cacheResult(list);
1356    
1357                                    finderCache.putResult(finderPath, finderArgs, list);
1358                            }
1359                            catch (Exception e) {
1360                                    finderCache.removeResult(finderPath, finderArgs);
1361    
1362                                    throw processException(e);
1363                            }
1364                            finally {
1365                                    closeSession(session);
1366                            }
1367                    }
1368    
1369                    return list;
1370            }
1371    
1372            /**
1373             * Returns the first portlet preferences in the ordered set where ownerType = &#63; and portletId = &#63;.
1374             *
1375             * @param ownerType the owner type
1376             * @param portletId the portlet ID
1377             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1378             * @return the first matching portlet preferences
1379             * @throws NoSuchPortletPreferencesException if a matching portlet preferences could not be found
1380             */
1381            @Override
1382            public PortletPreferences findByO_P_First(int ownerType, String portletId,
1383                    OrderByComparator<PortletPreferences> orderByComparator)
1384                    throws NoSuchPortletPreferencesException {
1385                    PortletPreferences portletPreferences = fetchByO_P_First(ownerType,
1386                                    portletId, orderByComparator);
1387    
1388                    if (portletPreferences != null) {
1389                            return portletPreferences;
1390                    }
1391    
1392                    StringBundler msg = new StringBundler(6);
1393    
1394                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1395    
1396                    msg.append("ownerType=");
1397                    msg.append(ownerType);
1398    
1399                    msg.append(", portletId=");
1400                    msg.append(portletId);
1401    
1402                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1403    
1404                    throw new NoSuchPortletPreferencesException(msg.toString());
1405            }
1406    
1407            /**
1408             * Returns the first portlet preferences in the ordered set where ownerType = &#63; and portletId = &#63;.
1409             *
1410             * @param ownerType the owner type
1411             * @param portletId the portlet ID
1412             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1413             * @return the first matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
1414             */
1415            @Override
1416            public PortletPreferences fetchByO_P_First(int ownerType, String portletId,
1417                    OrderByComparator<PortletPreferences> orderByComparator) {
1418                    List<PortletPreferences> list = findByO_P(ownerType, portletId, 0, 1,
1419                                    orderByComparator);
1420    
1421                    if (!list.isEmpty()) {
1422                            return list.get(0);
1423                    }
1424    
1425                    return null;
1426            }
1427    
1428            /**
1429             * Returns the last portlet preferences in the ordered set where ownerType = &#63; and portletId = &#63;.
1430             *
1431             * @param ownerType the owner type
1432             * @param portletId the portlet ID
1433             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1434             * @return the last matching portlet preferences
1435             * @throws NoSuchPortletPreferencesException if a matching portlet preferences could not be found
1436             */
1437            @Override
1438            public PortletPreferences findByO_P_Last(int ownerType, String portletId,
1439                    OrderByComparator<PortletPreferences> orderByComparator)
1440                    throws NoSuchPortletPreferencesException {
1441                    PortletPreferences portletPreferences = fetchByO_P_Last(ownerType,
1442                                    portletId, orderByComparator);
1443    
1444                    if (portletPreferences != null) {
1445                            return portletPreferences;
1446                    }
1447    
1448                    StringBundler msg = new StringBundler(6);
1449    
1450                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1451    
1452                    msg.append("ownerType=");
1453                    msg.append(ownerType);
1454    
1455                    msg.append(", portletId=");
1456                    msg.append(portletId);
1457    
1458                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1459    
1460                    throw new NoSuchPortletPreferencesException(msg.toString());
1461            }
1462    
1463            /**
1464             * Returns the last portlet preferences in the ordered set where ownerType = &#63; and portletId = &#63;.
1465             *
1466             * @param ownerType the owner type
1467             * @param portletId the portlet ID
1468             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1469             * @return the last matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
1470             */
1471            @Override
1472            public PortletPreferences fetchByO_P_Last(int ownerType, String portletId,
1473                    OrderByComparator<PortletPreferences> orderByComparator) {
1474                    int count = countByO_P(ownerType, portletId);
1475    
1476                    if (count == 0) {
1477                            return null;
1478                    }
1479    
1480                    List<PortletPreferences> list = findByO_P(ownerType, portletId,
1481                                    count - 1, count, orderByComparator);
1482    
1483                    if (!list.isEmpty()) {
1484                            return list.get(0);
1485                    }
1486    
1487                    return null;
1488            }
1489    
1490            /**
1491             * Returns the portlet preferenceses before and after the current portlet preferences in the ordered set where ownerType = &#63; and portletId = &#63;.
1492             *
1493             * @param portletPreferencesId the primary key of the current portlet preferences
1494             * @param ownerType the owner type
1495             * @param portletId the portlet ID
1496             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1497             * @return the previous, current, and next portlet preferences
1498             * @throws NoSuchPortletPreferencesException if a portlet preferences with the primary key could not be found
1499             */
1500            @Override
1501            public PortletPreferences[] findByO_P_PrevAndNext(
1502                    long portletPreferencesId, int ownerType, String portletId,
1503                    OrderByComparator<PortletPreferences> orderByComparator)
1504                    throws NoSuchPortletPreferencesException {
1505                    PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
1506    
1507                    Session session = null;
1508    
1509                    try {
1510                            session = openSession();
1511    
1512                            PortletPreferences[] array = new PortletPreferencesImpl[3];
1513    
1514                            array[0] = getByO_P_PrevAndNext(session, portletPreferences,
1515                                            ownerType, portletId, orderByComparator, true);
1516    
1517                            array[1] = portletPreferences;
1518    
1519                            array[2] = getByO_P_PrevAndNext(session, portletPreferences,
1520                                            ownerType, portletId, orderByComparator, false);
1521    
1522                            return array;
1523                    }
1524                    catch (Exception e) {
1525                            throw processException(e);
1526                    }
1527                    finally {
1528                            closeSession(session);
1529                    }
1530            }
1531    
1532            protected PortletPreferences getByO_P_PrevAndNext(Session session,
1533                    PortletPreferences portletPreferences, int ownerType, String portletId,
1534                    OrderByComparator<PortletPreferences> orderByComparator,
1535                    boolean previous) {
1536                    StringBundler query = null;
1537    
1538                    if (orderByComparator != null) {
1539                            query = new StringBundler(5 +
1540                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1541                                            (orderByComparator.getOrderByFields().length * 3));
1542                    }
1543                    else {
1544                            query = new StringBundler(4);
1545                    }
1546    
1547                    query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1548    
1549                    query.append(_FINDER_COLUMN_O_P_OWNERTYPE_2);
1550    
1551                    boolean bindPortletId = false;
1552    
1553                    if (portletId == null) {
1554                            query.append(_FINDER_COLUMN_O_P_PORTLETID_1);
1555                    }
1556                    else if (portletId.equals(StringPool.BLANK)) {
1557                            query.append(_FINDER_COLUMN_O_P_PORTLETID_3);
1558                    }
1559                    else {
1560                            bindPortletId = true;
1561    
1562                            query.append(_FINDER_COLUMN_O_P_PORTLETID_2);
1563                    }
1564    
1565                    if (orderByComparator != null) {
1566                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1567    
1568                            if (orderByConditionFields.length > 0) {
1569                                    query.append(WHERE_AND);
1570                            }
1571    
1572                            for (int i = 0; i < orderByConditionFields.length; i++) {
1573                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1574                                    query.append(orderByConditionFields[i]);
1575    
1576                                    if ((i + 1) < orderByConditionFields.length) {
1577                                            if (orderByComparator.isAscending() ^ previous) {
1578                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1579                                            }
1580                                            else {
1581                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1582                                            }
1583                                    }
1584                                    else {
1585                                            if (orderByComparator.isAscending() ^ previous) {
1586                                                    query.append(WHERE_GREATER_THAN);
1587                                            }
1588                                            else {
1589                                                    query.append(WHERE_LESSER_THAN);
1590                                            }
1591                                    }
1592                            }
1593    
1594                            query.append(ORDER_BY_CLAUSE);
1595    
1596                            String[] orderByFields = orderByComparator.getOrderByFields();
1597    
1598                            for (int i = 0; i < orderByFields.length; i++) {
1599                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1600                                    query.append(orderByFields[i]);
1601    
1602                                    if ((i + 1) < orderByFields.length) {
1603                                            if (orderByComparator.isAscending() ^ previous) {
1604                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1605                                            }
1606                                            else {
1607                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1608                                            }
1609                                    }
1610                                    else {
1611                                            if (orderByComparator.isAscending() ^ previous) {
1612                                                    query.append(ORDER_BY_ASC);
1613                                            }
1614                                            else {
1615                                                    query.append(ORDER_BY_DESC);
1616                                            }
1617                                    }
1618                            }
1619                    }
1620                    else {
1621                            query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
1622                    }
1623    
1624                    String sql = query.toString();
1625    
1626                    Query q = session.createQuery(sql);
1627    
1628                    q.setFirstResult(0);
1629                    q.setMaxResults(2);
1630    
1631                    QueryPos qPos = QueryPos.getInstance(q);
1632    
1633                    qPos.add(ownerType);
1634    
1635                    if (bindPortletId) {
1636                            qPos.add(portletId);
1637                    }
1638    
1639                    if (orderByComparator != null) {
1640                            Object[] values = orderByComparator.getOrderByConditionValues(portletPreferences);
1641    
1642                            for (Object value : values) {
1643                                    qPos.add(value);
1644                            }
1645                    }
1646    
1647                    List<PortletPreferences> list = q.list();
1648    
1649                    if (list.size() == 2) {
1650                            return list.get(1);
1651                    }
1652                    else {
1653                            return null;
1654                    }
1655            }
1656    
1657            /**
1658             * Removes all the portlet preferenceses where ownerType = &#63; and portletId = &#63; from the database.
1659             *
1660             * @param ownerType the owner type
1661             * @param portletId the portlet ID
1662             */
1663            @Override
1664            public void removeByO_P(int ownerType, String portletId) {
1665                    for (PortletPreferences portletPreferences : findByO_P(ownerType,
1666                                    portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1667                            remove(portletPreferences);
1668                    }
1669            }
1670    
1671            /**
1672             * Returns the number of portlet preferenceses where ownerType = &#63; and portletId = &#63;.
1673             *
1674             * @param ownerType the owner type
1675             * @param portletId the portlet ID
1676             * @return the number of matching portlet preferenceses
1677             */
1678            @Override
1679            public int countByO_P(int ownerType, String portletId) {
1680                    FinderPath finderPath = FINDER_PATH_COUNT_BY_O_P;
1681    
1682                    Object[] finderArgs = new Object[] { ownerType, portletId };
1683    
1684                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1685    
1686                    if (count == null) {
1687                            StringBundler query = new StringBundler(3);
1688    
1689                            query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
1690    
1691                            query.append(_FINDER_COLUMN_O_P_OWNERTYPE_2);
1692    
1693                            boolean bindPortletId = false;
1694    
1695                            if (portletId == null) {
1696                                    query.append(_FINDER_COLUMN_O_P_PORTLETID_1);
1697                            }
1698                            else if (portletId.equals(StringPool.BLANK)) {
1699                                    query.append(_FINDER_COLUMN_O_P_PORTLETID_3);
1700                            }
1701                            else {
1702                                    bindPortletId = true;
1703    
1704                                    query.append(_FINDER_COLUMN_O_P_PORTLETID_2);
1705                            }
1706    
1707                            String sql = query.toString();
1708    
1709                            Session session = null;
1710    
1711                            try {
1712                                    session = openSession();
1713    
1714                                    Query q = session.createQuery(sql);
1715    
1716                                    QueryPos qPos = QueryPos.getInstance(q);
1717    
1718                                    qPos.add(ownerType);
1719    
1720                                    if (bindPortletId) {
1721                                            qPos.add(portletId);
1722                                    }
1723    
1724                                    count = (Long)q.uniqueResult();
1725    
1726                                    finderCache.putResult(finderPath, finderArgs, count);
1727                            }
1728                            catch (Exception e) {
1729                                    finderCache.removeResult(finderPath, finderArgs);
1730    
1731                                    throw processException(e);
1732                            }
1733                            finally {
1734                                    closeSession(session);
1735                            }
1736                    }
1737    
1738                    return count.intValue();
1739            }
1740    
1741            private static final String _FINDER_COLUMN_O_P_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
1742            private static final String _FINDER_COLUMN_O_P_PORTLETID_1 = "portletPreferences.portletId IS NULL";
1743            private static final String _FINDER_COLUMN_O_P_PORTLETID_2 = "portletPreferences.portletId = ?";
1744            private static final String _FINDER_COLUMN_O_P_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = '')";
1745            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
1746                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
1747                            PortletPreferencesImpl.class,
1748                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByP_P",
1749                            new String[] {
1750                                    Long.class.getName(), String.class.getName(),
1751                                    
1752                            Integer.class.getName(), Integer.class.getName(),
1753                                    OrderByComparator.class.getName()
1754                            });
1755            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
1756                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
1757                            PortletPreferencesImpl.class,
1758                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByP_P",
1759                            new String[] { Long.class.getName(), String.class.getName() },
1760                            PortletPreferencesModelImpl.PLID_COLUMN_BITMASK |
1761                            PortletPreferencesModelImpl.PORTLETID_COLUMN_BITMASK);
1762            public static final FinderPath FINDER_PATH_COUNT_BY_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
1763                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
1764                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_P",
1765                            new String[] { Long.class.getName(), String.class.getName() });
1766    
1767            /**
1768             * Returns all the portlet preferenceses where plid = &#63; and portletId = &#63;.
1769             *
1770             * @param plid the plid
1771             * @param portletId the portlet ID
1772             * @return the matching portlet preferenceses
1773             */
1774            @Override
1775            public List<PortletPreferences> findByP_P(long plid, String portletId) {
1776                    return findByP_P(plid, portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1777                            null);
1778            }
1779    
1780            /**
1781             * Returns a range of all the portlet preferenceses where plid = &#63; and portletId = &#63;.
1782             *
1783             * <p>
1784             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1785             * </p>
1786             *
1787             * @param plid the plid
1788             * @param portletId the portlet ID
1789             * @param start the lower bound of the range of portlet preferenceses
1790             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
1791             * @return the range of matching portlet preferenceses
1792             */
1793            @Override
1794            public List<PortletPreferences> findByP_P(long plid, String portletId,
1795                    int start, int end) {
1796                    return findByP_P(plid, portletId, start, end, null);
1797            }
1798    
1799            /**
1800             * Returns an ordered range of all the portlet preferenceses where plid = &#63; and portletId = &#63;.
1801             *
1802             * <p>
1803             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1804             * </p>
1805             *
1806             * @param plid the plid
1807             * @param portletId the portlet ID
1808             * @param start the lower bound of the range of portlet preferenceses
1809             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
1810             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1811             * @return the ordered range of matching portlet preferenceses
1812             */
1813            @Override
1814            public List<PortletPreferences> findByP_P(long plid, String portletId,
1815                    int start, int end,
1816                    OrderByComparator<PortletPreferences> orderByComparator) {
1817                    return findByP_P(plid, portletId, start, end, orderByComparator, true);
1818            }
1819    
1820            /**
1821             * Returns an ordered range of all the portlet preferenceses where plid = &#63; and portletId = &#63;.
1822             *
1823             * <p>
1824             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1825             * </p>
1826             *
1827             * @param plid the plid
1828             * @param portletId the portlet ID
1829             * @param start the lower bound of the range of portlet preferenceses
1830             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
1831             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1832             * @param retrieveFromCache whether to retrieve from the finder cache
1833             * @return the ordered range of matching portlet preferenceses
1834             */
1835            @Override
1836            public List<PortletPreferences> findByP_P(long plid, String portletId,
1837                    int start, int end,
1838                    OrderByComparator<PortletPreferences> orderByComparator,
1839                    boolean retrieveFromCache) {
1840                    boolean pagination = true;
1841                    FinderPath finderPath = null;
1842                    Object[] finderArgs = null;
1843    
1844                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1845                                    (orderByComparator == null)) {
1846                            pagination = false;
1847                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_P;
1848                            finderArgs = new Object[] { plid, portletId };
1849                    }
1850                    else {
1851                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_P;
1852                            finderArgs = new Object[] {
1853                                            plid, portletId,
1854                                            
1855                                            start, end, orderByComparator
1856                                    };
1857                    }
1858    
1859                    List<PortletPreferences> list = null;
1860    
1861                    if (retrieveFromCache) {
1862                            list = (List<PortletPreferences>)finderCache.getResult(finderPath,
1863                                            finderArgs, this);
1864    
1865                            if ((list != null) && !list.isEmpty()) {
1866                                    for (PortletPreferences portletPreferences : list) {
1867                                            if ((plid != portletPreferences.getPlid()) ||
1868                                                            !Validator.equals(portletId,
1869                                                                    portletPreferences.getPortletId())) {
1870                                                    list = null;
1871    
1872                                                    break;
1873                                            }
1874                                    }
1875                            }
1876                    }
1877    
1878                    if (list == null) {
1879                            StringBundler query = null;
1880    
1881                            if (orderByComparator != null) {
1882                                    query = new StringBundler(4 +
1883                                                    (orderByComparator.getOrderByFields().length * 2));
1884                            }
1885                            else {
1886                                    query = new StringBundler(4);
1887                            }
1888    
1889                            query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1890    
1891                            query.append(_FINDER_COLUMN_P_P_PLID_2);
1892    
1893                            boolean bindPortletId = false;
1894    
1895                            if (portletId == null) {
1896                                    query.append(_FINDER_COLUMN_P_P_PORTLETID_1);
1897                            }
1898                            else if (portletId.equals(StringPool.BLANK)) {
1899                                    query.append(_FINDER_COLUMN_P_P_PORTLETID_3);
1900                            }
1901                            else {
1902                                    bindPortletId = true;
1903    
1904                                    query.append(_FINDER_COLUMN_P_P_PORTLETID_2);
1905                            }
1906    
1907                            if (orderByComparator != null) {
1908                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1909                                            orderByComparator);
1910                            }
1911                            else
1912                             if (pagination) {
1913                                    query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
1914                            }
1915    
1916                            String sql = query.toString();
1917    
1918                            Session session = null;
1919    
1920                            try {
1921                                    session = openSession();
1922    
1923                                    Query q = session.createQuery(sql);
1924    
1925                                    QueryPos qPos = QueryPos.getInstance(q);
1926    
1927                                    qPos.add(plid);
1928    
1929                                    if (bindPortletId) {
1930                                            qPos.add(portletId);
1931                                    }
1932    
1933                                    if (!pagination) {
1934                                            list = (List<PortletPreferences>)QueryUtil.list(q,
1935                                                            getDialect(), start, end, false);
1936    
1937                                            Collections.sort(list);
1938    
1939                                            list = Collections.unmodifiableList(list);
1940                                    }
1941                                    else {
1942                                            list = (List<PortletPreferences>)QueryUtil.list(q,
1943                                                            getDialect(), start, end);
1944                                    }
1945    
1946                                    cacheResult(list);
1947    
1948                                    finderCache.putResult(finderPath, finderArgs, list);
1949                            }
1950                            catch (Exception e) {
1951                                    finderCache.removeResult(finderPath, finderArgs);
1952    
1953                                    throw processException(e);
1954                            }
1955                            finally {
1956                                    closeSession(session);
1957                            }
1958                    }
1959    
1960                    return list;
1961            }
1962    
1963            /**
1964             * Returns the first portlet preferences in the ordered set where plid = &#63; and portletId = &#63;.
1965             *
1966             * @param plid the plid
1967             * @param portletId the portlet ID
1968             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1969             * @return the first matching portlet preferences
1970             * @throws NoSuchPortletPreferencesException if a matching portlet preferences could not be found
1971             */
1972            @Override
1973            public PortletPreferences findByP_P_First(long plid, String portletId,
1974                    OrderByComparator<PortletPreferences> orderByComparator)
1975                    throws NoSuchPortletPreferencesException {
1976                    PortletPreferences portletPreferences = fetchByP_P_First(plid,
1977                                    portletId, orderByComparator);
1978    
1979                    if (portletPreferences != null) {
1980                            return portletPreferences;
1981                    }
1982    
1983                    StringBundler msg = new StringBundler(6);
1984    
1985                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1986    
1987                    msg.append("plid=");
1988                    msg.append(plid);
1989    
1990                    msg.append(", portletId=");
1991                    msg.append(portletId);
1992    
1993                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1994    
1995                    throw new NoSuchPortletPreferencesException(msg.toString());
1996            }
1997    
1998            /**
1999             * Returns the first portlet preferences in the ordered set where plid = &#63; and portletId = &#63;.
2000             *
2001             * @param plid the plid
2002             * @param portletId the portlet ID
2003             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2004             * @return the first matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
2005             */
2006            @Override
2007            public PortletPreferences fetchByP_P_First(long plid, String portletId,
2008                    OrderByComparator<PortletPreferences> orderByComparator) {
2009                    List<PortletPreferences> list = findByP_P(plid, portletId, 0, 1,
2010                                    orderByComparator);
2011    
2012                    if (!list.isEmpty()) {
2013                            return list.get(0);
2014                    }
2015    
2016                    return null;
2017            }
2018    
2019            /**
2020             * Returns the last portlet preferences in the ordered set where plid = &#63; and portletId = &#63;.
2021             *
2022             * @param plid the plid
2023             * @param portletId the portlet ID
2024             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2025             * @return the last matching portlet preferences
2026             * @throws NoSuchPortletPreferencesException if a matching portlet preferences could not be found
2027             */
2028            @Override
2029            public PortletPreferences findByP_P_Last(long plid, String portletId,
2030                    OrderByComparator<PortletPreferences> orderByComparator)
2031                    throws NoSuchPortletPreferencesException {
2032                    PortletPreferences portletPreferences = fetchByP_P_Last(plid,
2033                                    portletId, orderByComparator);
2034    
2035                    if (portletPreferences != null) {
2036                            return portletPreferences;
2037                    }
2038    
2039                    StringBundler msg = new StringBundler(6);
2040    
2041                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2042    
2043                    msg.append("plid=");
2044                    msg.append(plid);
2045    
2046                    msg.append(", portletId=");
2047                    msg.append(portletId);
2048    
2049                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2050    
2051                    throw new NoSuchPortletPreferencesException(msg.toString());
2052            }
2053    
2054            /**
2055             * Returns the last portlet preferences in the ordered set where plid = &#63; and portletId = &#63;.
2056             *
2057             * @param plid the plid
2058             * @param portletId the portlet ID
2059             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2060             * @return the last matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
2061             */
2062            @Override
2063            public PortletPreferences fetchByP_P_Last(long plid, String portletId,
2064                    OrderByComparator<PortletPreferences> orderByComparator) {
2065                    int count = countByP_P(plid, portletId);
2066    
2067                    if (count == 0) {
2068                            return null;
2069                    }
2070    
2071                    List<PortletPreferences> list = findByP_P(plid, portletId, count - 1,
2072                                    count, orderByComparator);
2073    
2074                    if (!list.isEmpty()) {
2075                            return list.get(0);
2076                    }
2077    
2078                    return null;
2079            }
2080    
2081            /**
2082             * Returns the portlet preferenceses before and after the current portlet preferences in the ordered set where plid = &#63; and portletId = &#63;.
2083             *
2084             * @param portletPreferencesId the primary key of the current portlet preferences
2085             * @param plid the plid
2086             * @param portletId the portlet ID
2087             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2088             * @return the previous, current, and next portlet preferences
2089             * @throws NoSuchPortletPreferencesException if a portlet preferences with the primary key could not be found
2090             */
2091            @Override
2092            public PortletPreferences[] findByP_P_PrevAndNext(
2093                    long portletPreferencesId, long plid, String portletId,
2094                    OrderByComparator<PortletPreferences> orderByComparator)
2095                    throws NoSuchPortletPreferencesException {
2096                    PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
2097    
2098                    Session session = null;
2099    
2100                    try {
2101                            session = openSession();
2102    
2103                            PortletPreferences[] array = new PortletPreferencesImpl[3];
2104    
2105                            array[0] = getByP_P_PrevAndNext(session, portletPreferences, plid,
2106                                            portletId, orderByComparator, true);
2107    
2108                            array[1] = portletPreferences;
2109    
2110                            array[2] = getByP_P_PrevAndNext(session, portletPreferences, plid,
2111                                            portletId, orderByComparator, false);
2112    
2113                            return array;
2114                    }
2115                    catch (Exception e) {
2116                            throw processException(e);
2117                    }
2118                    finally {
2119                            closeSession(session);
2120                    }
2121            }
2122    
2123            protected PortletPreferences getByP_P_PrevAndNext(Session session,
2124                    PortletPreferences portletPreferences, long plid, String portletId,
2125                    OrderByComparator<PortletPreferences> orderByComparator,
2126                    boolean previous) {
2127                    StringBundler query = null;
2128    
2129                    if (orderByComparator != null) {
2130                            query = new StringBundler(5 +
2131                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2132                                            (orderByComparator.getOrderByFields().length * 3));
2133                    }
2134                    else {
2135                            query = new StringBundler(4);
2136                    }
2137    
2138                    query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
2139    
2140                    query.append(_FINDER_COLUMN_P_P_PLID_2);
2141    
2142                    boolean bindPortletId = false;
2143    
2144                    if (portletId == null) {
2145                            query.append(_FINDER_COLUMN_P_P_PORTLETID_1);
2146                    }
2147                    else if (portletId.equals(StringPool.BLANK)) {
2148                            query.append(_FINDER_COLUMN_P_P_PORTLETID_3);
2149                    }
2150                    else {
2151                            bindPortletId = true;
2152    
2153                            query.append(_FINDER_COLUMN_P_P_PORTLETID_2);
2154                    }
2155    
2156                    if (orderByComparator != null) {
2157                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2158    
2159                            if (orderByConditionFields.length > 0) {
2160                                    query.append(WHERE_AND);
2161                            }
2162    
2163                            for (int i = 0; i < orderByConditionFields.length; i++) {
2164                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2165                                    query.append(orderByConditionFields[i]);
2166    
2167                                    if ((i + 1) < orderByConditionFields.length) {
2168                                            if (orderByComparator.isAscending() ^ previous) {
2169                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2170                                            }
2171                                            else {
2172                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2173                                            }
2174                                    }
2175                                    else {
2176                                            if (orderByComparator.isAscending() ^ previous) {
2177                                                    query.append(WHERE_GREATER_THAN);
2178                                            }
2179                                            else {
2180                                                    query.append(WHERE_LESSER_THAN);
2181                                            }
2182                                    }
2183                            }
2184    
2185                            query.append(ORDER_BY_CLAUSE);
2186    
2187                            String[] orderByFields = orderByComparator.getOrderByFields();
2188    
2189                            for (int i = 0; i < orderByFields.length; i++) {
2190                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2191                                    query.append(orderByFields[i]);
2192    
2193                                    if ((i + 1) < orderByFields.length) {
2194                                            if (orderByComparator.isAscending() ^ previous) {
2195                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2196                                            }
2197                                            else {
2198                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2199                                            }
2200                                    }
2201                                    else {
2202                                            if (orderByComparator.isAscending() ^ previous) {
2203                                                    query.append(ORDER_BY_ASC);
2204                                            }
2205                                            else {
2206                                                    query.append(ORDER_BY_DESC);
2207                                            }
2208                                    }
2209                            }
2210                    }
2211                    else {
2212                            query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
2213                    }
2214    
2215                    String sql = query.toString();
2216    
2217                    Query q = session.createQuery(sql);
2218    
2219                    q.setFirstResult(0);
2220                    q.setMaxResults(2);
2221    
2222                    QueryPos qPos = QueryPos.getInstance(q);
2223    
2224                    qPos.add(plid);
2225    
2226                    if (bindPortletId) {
2227                            qPos.add(portletId);
2228                    }
2229    
2230                    if (orderByComparator != null) {
2231                            Object[] values = orderByComparator.getOrderByConditionValues(portletPreferences);
2232    
2233                            for (Object value : values) {
2234                                    qPos.add(value);
2235                            }
2236                    }
2237    
2238                    List<PortletPreferences> list = q.list();
2239    
2240                    if (list.size() == 2) {
2241                            return list.get(1);
2242                    }
2243                    else {
2244                            return null;
2245                    }
2246            }
2247    
2248            /**
2249             * Removes all the portlet preferenceses where plid = &#63; and portletId = &#63; from the database.
2250             *
2251             * @param plid the plid
2252             * @param portletId the portlet ID
2253             */
2254            @Override
2255            public void removeByP_P(long plid, String portletId) {
2256                    for (PortletPreferences portletPreferences : findByP_P(plid, portletId,
2257                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2258                            remove(portletPreferences);
2259                    }
2260            }
2261    
2262            /**
2263             * Returns the number of portlet preferenceses where plid = &#63; and portletId = &#63;.
2264             *
2265             * @param plid the plid
2266             * @param portletId the portlet ID
2267             * @return the number of matching portlet preferenceses
2268             */
2269            @Override
2270            public int countByP_P(long plid, String portletId) {
2271                    FinderPath finderPath = FINDER_PATH_COUNT_BY_P_P;
2272    
2273                    Object[] finderArgs = new Object[] { plid, portletId };
2274    
2275                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2276    
2277                    if (count == null) {
2278                            StringBundler query = new StringBundler(3);
2279    
2280                            query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
2281    
2282                            query.append(_FINDER_COLUMN_P_P_PLID_2);
2283    
2284                            boolean bindPortletId = false;
2285    
2286                            if (portletId == null) {
2287                                    query.append(_FINDER_COLUMN_P_P_PORTLETID_1);
2288                            }
2289                            else if (portletId.equals(StringPool.BLANK)) {
2290                                    query.append(_FINDER_COLUMN_P_P_PORTLETID_3);
2291                            }
2292                            else {
2293                                    bindPortletId = true;
2294    
2295                                    query.append(_FINDER_COLUMN_P_P_PORTLETID_2);
2296                            }
2297    
2298                            String sql = query.toString();
2299    
2300                            Session session = null;
2301    
2302                            try {
2303                                    session = openSession();
2304    
2305                                    Query q = session.createQuery(sql);
2306    
2307                                    QueryPos qPos = QueryPos.getInstance(q);
2308    
2309                                    qPos.add(plid);
2310    
2311                                    if (bindPortletId) {
2312                                            qPos.add(portletId);
2313                                    }
2314    
2315                                    count = (Long)q.uniqueResult();
2316    
2317                                    finderCache.putResult(finderPath, finderArgs, count);
2318                            }
2319                            catch (Exception e) {
2320                                    finderCache.removeResult(finderPath, finderArgs);
2321    
2322                                    throw processException(e);
2323                            }
2324                            finally {
2325                                    closeSession(session);
2326                            }
2327                    }
2328    
2329                    return count.intValue();
2330            }
2331    
2332            private static final String _FINDER_COLUMN_P_P_PLID_2 = "portletPreferences.plid = ? AND ";
2333            private static final String _FINDER_COLUMN_P_P_PORTLETID_1 = "portletPreferences.portletId IS NULL";
2334            private static final String _FINDER_COLUMN_P_P_PORTLETID_2 = "portletPreferences.portletId = ?";
2335            private static final String _FINDER_COLUMN_P_P_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = '')";
2336            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_O_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
2337                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
2338                            PortletPreferencesImpl.class,
2339                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByO_O_P",
2340                            new String[] {
2341                                    Long.class.getName(), Integer.class.getName(),
2342                                    Long.class.getName(),
2343                                    
2344                            Integer.class.getName(), Integer.class.getName(),
2345                                    OrderByComparator.class.getName()
2346                            });
2347            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
2348                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
2349                            PortletPreferencesImpl.class,
2350                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByO_O_P",
2351                            new String[] {
2352                                    Long.class.getName(), Integer.class.getName(),
2353                                    Long.class.getName()
2354                            },
2355                            PortletPreferencesModelImpl.OWNERID_COLUMN_BITMASK |
2356                            PortletPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK |
2357                            PortletPreferencesModelImpl.PLID_COLUMN_BITMASK);
2358            public static final FinderPath FINDER_PATH_COUNT_BY_O_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
2359                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
2360                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_O_P",
2361                            new String[] {
2362                                    Long.class.getName(), Integer.class.getName(),
2363                                    Long.class.getName()
2364                            });
2365    
2366            /**
2367             * Returns all the portlet preferenceses where ownerId = &#63; and ownerType = &#63; and plid = &#63;.
2368             *
2369             * @param ownerId the owner ID
2370             * @param ownerType the owner type
2371             * @param plid the plid
2372             * @return the matching portlet preferenceses
2373             */
2374            @Override
2375            public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
2376                    long plid) {
2377                    return findByO_O_P(ownerId, ownerType, plid, QueryUtil.ALL_POS,
2378                            QueryUtil.ALL_POS, null);
2379            }
2380    
2381            /**
2382             * Returns a range of all the portlet preferenceses where ownerId = &#63; and ownerType = &#63; and plid = &#63;.
2383             *
2384             * <p>
2385             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2386             * </p>
2387             *
2388             * @param ownerId the owner ID
2389             * @param ownerType the owner type
2390             * @param plid the plid
2391             * @param start the lower bound of the range of portlet preferenceses
2392             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
2393             * @return the range of matching portlet preferenceses
2394             */
2395            @Override
2396            public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
2397                    long plid, int start, int end) {
2398                    return findByO_O_P(ownerId, ownerType, plid, start, end, null);
2399            }
2400    
2401            /**
2402             * Returns an ordered range of all the portlet preferenceses where ownerId = &#63; and ownerType = &#63; and plid = &#63;.
2403             *
2404             * <p>
2405             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2406             * </p>
2407             *
2408             * @param ownerId the owner ID
2409             * @param ownerType the owner type
2410             * @param plid the plid
2411             * @param start the lower bound of the range of portlet preferenceses
2412             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
2413             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2414             * @return the ordered range of matching portlet preferenceses
2415             */
2416            @Override
2417            public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
2418                    long plid, int start, int end,
2419                    OrderByComparator<PortletPreferences> orderByComparator) {
2420                    return findByO_O_P(ownerId, ownerType, plid, start, end,
2421                            orderByComparator, true);
2422            }
2423    
2424            /**
2425             * Returns an ordered range of all the portlet preferenceses where ownerId = &#63; and ownerType = &#63; and plid = &#63;.
2426             *
2427             * <p>
2428             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2429             * </p>
2430             *
2431             * @param ownerId the owner ID
2432             * @param ownerType the owner type
2433             * @param plid the plid
2434             * @param start the lower bound of the range of portlet preferenceses
2435             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
2436             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2437             * @param retrieveFromCache whether to retrieve from the finder cache
2438             * @return the ordered range of matching portlet preferenceses
2439             */
2440            @Override
2441            public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
2442                    long plid, int start, int end,
2443                    OrderByComparator<PortletPreferences> orderByComparator,
2444                    boolean retrieveFromCache) {
2445                    boolean pagination = true;
2446                    FinderPath finderPath = null;
2447                    Object[] finderArgs = null;
2448    
2449                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2450                                    (orderByComparator == null)) {
2451                            pagination = false;
2452                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_P;
2453                            finderArgs = new Object[] { ownerId, ownerType, plid };
2454                    }
2455                    else {
2456                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_O_O_P;
2457                            finderArgs = new Object[] {
2458                                            ownerId, ownerType, plid,
2459                                            
2460                                            start, end, orderByComparator
2461                                    };
2462                    }
2463    
2464                    List<PortletPreferences> list = null;
2465    
2466                    if (retrieveFromCache) {
2467                            list = (List<PortletPreferences>)finderCache.getResult(finderPath,
2468                                            finderArgs, this);
2469    
2470                            if ((list != null) && !list.isEmpty()) {
2471                                    for (PortletPreferences portletPreferences : list) {
2472                                            if ((ownerId != portletPreferences.getOwnerId()) ||
2473                                                            (ownerType != portletPreferences.getOwnerType()) ||
2474                                                            (plid != portletPreferences.getPlid())) {
2475                                                    list = null;
2476    
2477                                                    break;
2478                                            }
2479                                    }
2480                            }
2481                    }
2482    
2483                    if (list == null) {
2484                            StringBundler query = null;
2485    
2486                            if (orderByComparator != null) {
2487                                    query = new StringBundler(5 +
2488                                                    (orderByComparator.getOrderByFields().length * 2));
2489                            }
2490                            else {
2491                                    query = new StringBundler(5);
2492                            }
2493    
2494                            query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
2495    
2496                            query.append(_FINDER_COLUMN_O_O_P_OWNERID_2);
2497    
2498                            query.append(_FINDER_COLUMN_O_O_P_OWNERTYPE_2);
2499    
2500                            query.append(_FINDER_COLUMN_O_O_P_PLID_2);
2501    
2502                            if (orderByComparator != null) {
2503                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2504                                            orderByComparator);
2505                            }
2506                            else
2507                             if (pagination) {
2508                                    query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
2509                            }
2510    
2511                            String sql = query.toString();
2512    
2513                            Session session = null;
2514    
2515                            try {
2516                                    session = openSession();
2517    
2518                                    Query q = session.createQuery(sql);
2519    
2520                                    QueryPos qPos = QueryPos.getInstance(q);
2521    
2522                                    qPos.add(ownerId);
2523    
2524                                    qPos.add(ownerType);
2525    
2526                                    qPos.add(plid);
2527    
2528                                    if (!pagination) {
2529                                            list = (List<PortletPreferences>)QueryUtil.list(q,
2530                                                            getDialect(), start, end, false);
2531    
2532                                            Collections.sort(list);
2533    
2534                                            list = Collections.unmodifiableList(list);
2535                                    }
2536                                    else {
2537                                            list = (List<PortletPreferences>)QueryUtil.list(q,
2538                                                            getDialect(), start, end);
2539                                    }
2540    
2541                                    cacheResult(list);
2542    
2543                                    finderCache.putResult(finderPath, finderArgs, list);
2544                            }
2545                            catch (Exception e) {
2546                                    finderCache.removeResult(finderPath, finderArgs);
2547    
2548                                    throw processException(e);
2549                            }
2550                            finally {
2551                                    closeSession(session);
2552                            }
2553                    }
2554    
2555                    return list;
2556            }
2557    
2558            /**
2559             * Returns the first portlet preferences in the ordered set where ownerId = &#63; and ownerType = &#63; and plid = &#63;.
2560             *
2561             * @param ownerId the owner ID
2562             * @param ownerType the owner type
2563             * @param plid the plid
2564             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2565             * @return the first matching portlet preferences
2566             * @throws NoSuchPortletPreferencesException if a matching portlet preferences could not be found
2567             */
2568            @Override
2569            public PortletPreferences findByO_O_P_First(long ownerId, int ownerType,
2570                    long plid, OrderByComparator<PortletPreferences> orderByComparator)
2571                    throws NoSuchPortletPreferencesException {
2572                    PortletPreferences portletPreferences = fetchByO_O_P_First(ownerId,
2573                                    ownerType, plid, orderByComparator);
2574    
2575                    if (portletPreferences != null) {
2576                            return portletPreferences;
2577                    }
2578    
2579                    StringBundler msg = new StringBundler(8);
2580    
2581                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2582    
2583                    msg.append("ownerId=");
2584                    msg.append(ownerId);
2585    
2586                    msg.append(", ownerType=");
2587                    msg.append(ownerType);
2588    
2589                    msg.append(", plid=");
2590                    msg.append(plid);
2591    
2592                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2593    
2594                    throw new NoSuchPortletPreferencesException(msg.toString());
2595            }
2596    
2597            /**
2598             * Returns the first portlet preferences in the ordered set where ownerId = &#63; and ownerType = &#63; and plid = &#63;.
2599             *
2600             * @param ownerId the owner ID
2601             * @param ownerType the owner type
2602             * @param plid the plid
2603             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2604             * @return the first matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
2605             */
2606            @Override
2607            public PortletPreferences fetchByO_O_P_First(long ownerId, int ownerType,
2608                    long plid, OrderByComparator<PortletPreferences> orderByComparator) {
2609                    List<PortletPreferences> list = findByO_O_P(ownerId, ownerType, plid,
2610                                    0, 1, orderByComparator);
2611    
2612                    if (!list.isEmpty()) {
2613                            return list.get(0);
2614                    }
2615    
2616                    return null;
2617            }
2618    
2619            /**
2620             * Returns the last portlet preferences in the ordered set where ownerId = &#63; and ownerType = &#63; and plid = &#63;.
2621             *
2622             * @param ownerId the owner ID
2623             * @param ownerType the owner type
2624             * @param plid the plid
2625             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2626             * @return the last matching portlet preferences
2627             * @throws NoSuchPortletPreferencesException if a matching portlet preferences could not be found
2628             */
2629            @Override
2630            public PortletPreferences findByO_O_P_Last(long ownerId, int ownerType,
2631                    long plid, OrderByComparator<PortletPreferences> orderByComparator)
2632                    throws NoSuchPortletPreferencesException {
2633                    PortletPreferences portletPreferences = fetchByO_O_P_Last(ownerId,
2634                                    ownerType, plid, orderByComparator);
2635    
2636                    if (portletPreferences != null) {
2637                            return portletPreferences;
2638                    }
2639    
2640                    StringBundler msg = new StringBundler(8);
2641    
2642                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2643    
2644                    msg.append("ownerId=");
2645                    msg.append(ownerId);
2646    
2647                    msg.append(", ownerType=");
2648                    msg.append(ownerType);
2649    
2650                    msg.append(", plid=");
2651                    msg.append(plid);
2652    
2653                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2654    
2655                    throw new NoSuchPortletPreferencesException(msg.toString());
2656            }
2657    
2658            /**
2659             * Returns the last portlet preferences in the ordered set where ownerId = &#63; and ownerType = &#63; and plid = &#63;.
2660             *
2661             * @param ownerId the owner ID
2662             * @param ownerType the owner type
2663             * @param plid the plid
2664             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2665             * @return the last matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
2666             */
2667            @Override
2668            public PortletPreferences fetchByO_O_P_Last(long ownerId, int ownerType,
2669                    long plid, OrderByComparator<PortletPreferences> orderByComparator) {
2670                    int count = countByO_O_P(ownerId, ownerType, plid);
2671    
2672                    if (count == 0) {
2673                            return null;
2674                    }
2675    
2676                    List<PortletPreferences> list = findByO_O_P(ownerId, ownerType, plid,
2677                                    count - 1, count, orderByComparator);
2678    
2679                    if (!list.isEmpty()) {
2680                            return list.get(0);
2681                    }
2682    
2683                    return null;
2684            }
2685    
2686            /**
2687             * Returns the portlet preferenceses before and after the current portlet preferences in the ordered set where ownerId = &#63; and ownerType = &#63; and plid = &#63;.
2688             *
2689             * @param portletPreferencesId the primary key of the current portlet preferences
2690             * @param ownerId the owner ID
2691             * @param ownerType the owner type
2692             * @param plid the plid
2693             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2694             * @return the previous, current, and next portlet preferences
2695             * @throws NoSuchPortletPreferencesException if a portlet preferences with the primary key could not be found
2696             */
2697            @Override
2698            public PortletPreferences[] findByO_O_P_PrevAndNext(
2699                    long portletPreferencesId, long ownerId, int ownerType, long plid,
2700                    OrderByComparator<PortletPreferences> orderByComparator)
2701                    throws NoSuchPortletPreferencesException {
2702                    PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
2703    
2704                    Session session = null;
2705    
2706                    try {
2707                            session = openSession();
2708    
2709                            PortletPreferences[] array = new PortletPreferencesImpl[3];
2710    
2711                            array[0] = getByO_O_P_PrevAndNext(session, portletPreferences,
2712                                            ownerId, ownerType, plid, orderByComparator, true);
2713    
2714                            array[1] = portletPreferences;
2715    
2716                            array[2] = getByO_O_P_PrevAndNext(session, portletPreferences,
2717                                            ownerId, ownerType, plid, orderByComparator, false);
2718    
2719                            return array;
2720                    }
2721                    catch (Exception e) {
2722                            throw processException(e);
2723                    }
2724                    finally {
2725                            closeSession(session);
2726                    }
2727            }
2728    
2729            protected PortletPreferences getByO_O_P_PrevAndNext(Session session,
2730                    PortletPreferences portletPreferences, long ownerId, int ownerType,
2731                    long plid, OrderByComparator<PortletPreferences> orderByComparator,
2732                    boolean previous) {
2733                    StringBundler query = null;
2734    
2735                    if (orderByComparator != null) {
2736                            query = new StringBundler(6 +
2737                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2738                                            (orderByComparator.getOrderByFields().length * 3));
2739                    }
2740                    else {
2741                            query = new StringBundler(5);
2742                    }
2743    
2744                    query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
2745    
2746                    query.append(_FINDER_COLUMN_O_O_P_OWNERID_2);
2747    
2748                    query.append(_FINDER_COLUMN_O_O_P_OWNERTYPE_2);
2749    
2750                    query.append(_FINDER_COLUMN_O_O_P_PLID_2);
2751    
2752                    if (orderByComparator != null) {
2753                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2754    
2755                            if (orderByConditionFields.length > 0) {
2756                                    query.append(WHERE_AND);
2757                            }
2758    
2759                            for (int i = 0; i < orderByConditionFields.length; i++) {
2760                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2761                                    query.append(orderByConditionFields[i]);
2762    
2763                                    if ((i + 1) < orderByConditionFields.length) {
2764                                            if (orderByComparator.isAscending() ^ previous) {
2765                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2766                                            }
2767                                            else {
2768                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2769                                            }
2770                                    }
2771                                    else {
2772                                            if (orderByComparator.isAscending() ^ previous) {
2773                                                    query.append(WHERE_GREATER_THAN);
2774                                            }
2775                                            else {
2776                                                    query.append(WHERE_LESSER_THAN);
2777                                            }
2778                                    }
2779                            }
2780    
2781                            query.append(ORDER_BY_CLAUSE);
2782    
2783                            String[] orderByFields = orderByComparator.getOrderByFields();
2784    
2785                            for (int i = 0; i < orderByFields.length; i++) {
2786                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2787                                    query.append(orderByFields[i]);
2788    
2789                                    if ((i + 1) < orderByFields.length) {
2790                                            if (orderByComparator.isAscending() ^ previous) {
2791                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2792                                            }
2793                                            else {
2794                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2795                                            }
2796                                    }
2797                                    else {
2798                                            if (orderByComparator.isAscending() ^ previous) {
2799                                                    query.append(ORDER_BY_ASC);
2800                                            }
2801                                            else {
2802                                                    query.append(ORDER_BY_DESC);
2803                                            }
2804                                    }
2805                            }
2806                    }
2807                    else {
2808                            query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
2809                    }
2810    
2811                    String sql = query.toString();
2812    
2813                    Query q = session.createQuery(sql);
2814    
2815                    q.setFirstResult(0);
2816                    q.setMaxResults(2);
2817    
2818                    QueryPos qPos = QueryPos.getInstance(q);
2819    
2820                    qPos.add(ownerId);
2821    
2822                    qPos.add(ownerType);
2823    
2824                    qPos.add(plid);
2825    
2826                    if (orderByComparator != null) {
2827                            Object[] values = orderByComparator.getOrderByConditionValues(portletPreferences);
2828    
2829                            for (Object value : values) {
2830                                    qPos.add(value);
2831                            }
2832                    }
2833    
2834                    List<PortletPreferences> list = q.list();
2835    
2836                    if (list.size() == 2) {
2837                            return list.get(1);
2838                    }
2839                    else {
2840                            return null;
2841                    }
2842            }
2843    
2844            /**
2845             * Removes all the portlet preferenceses where ownerId = &#63; and ownerType = &#63; and plid = &#63; from the database.
2846             *
2847             * @param ownerId the owner ID
2848             * @param ownerType the owner type
2849             * @param plid the plid
2850             */
2851            @Override
2852            public void removeByO_O_P(long ownerId, int ownerType, long plid) {
2853                    for (PortletPreferences portletPreferences : findByO_O_P(ownerId,
2854                                    ownerType, plid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2855                            remove(portletPreferences);
2856                    }
2857            }
2858    
2859            /**
2860             * Returns the number of portlet preferenceses where ownerId = &#63; and ownerType = &#63; and plid = &#63;.
2861             *
2862             * @param ownerId the owner ID
2863             * @param ownerType the owner type
2864             * @param plid the plid
2865             * @return the number of matching portlet preferenceses
2866             */
2867            @Override
2868            public int countByO_O_P(long ownerId, int ownerType, long plid) {
2869                    FinderPath finderPath = FINDER_PATH_COUNT_BY_O_O_P;
2870    
2871                    Object[] finderArgs = new Object[] { ownerId, ownerType, plid };
2872    
2873                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2874    
2875                    if (count == null) {
2876                            StringBundler query = new StringBundler(4);
2877    
2878                            query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
2879    
2880                            query.append(_FINDER_COLUMN_O_O_P_OWNERID_2);
2881    
2882                            query.append(_FINDER_COLUMN_O_O_P_OWNERTYPE_2);
2883    
2884                            query.append(_FINDER_COLUMN_O_O_P_PLID_2);
2885    
2886                            String sql = query.toString();
2887    
2888                            Session session = null;
2889    
2890                            try {
2891                                    session = openSession();
2892    
2893                                    Query q = session.createQuery(sql);
2894    
2895                                    QueryPos qPos = QueryPos.getInstance(q);
2896    
2897                                    qPos.add(ownerId);
2898    
2899                                    qPos.add(ownerType);
2900    
2901                                    qPos.add(plid);
2902    
2903                                    count = (Long)q.uniqueResult();
2904    
2905                                    finderCache.putResult(finderPath, finderArgs, count);
2906                            }
2907                            catch (Exception e) {
2908                                    finderCache.removeResult(finderPath, finderArgs);
2909    
2910                                    throw processException(e);
2911                            }
2912                            finally {
2913                                    closeSession(session);
2914                            }
2915                    }
2916    
2917                    return count.intValue();
2918            }
2919    
2920            private static final String _FINDER_COLUMN_O_O_P_OWNERID_2 = "portletPreferences.ownerId = ? AND ";
2921            private static final String _FINDER_COLUMN_O_O_P_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
2922            private static final String _FINDER_COLUMN_O_O_P_PLID_2 = "portletPreferences.plid = ?";
2923            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_O_O_PI = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
2924                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
2925                            PortletPreferencesImpl.class,
2926                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByO_O_PI",
2927                            new String[] {
2928                                    Long.class.getName(), Integer.class.getName(),
2929                                    String.class.getName(),
2930                                    
2931                            Integer.class.getName(), Integer.class.getName(),
2932                                    OrderByComparator.class.getName()
2933                            });
2934            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_PI =
2935                    new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
2936                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
2937                            PortletPreferencesImpl.class,
2938                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByO_O_PI",
2939                            new String[] {
2940                                    Long.class.getName(), Integer.class.getName(),
2941                                    String.class.getName()
2942                            },
2943                            PortletPreferencesModelImpl.OWNERID_COLUMN_BITMASK |
2944                            PortletPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK |
2945                            PortletPreferencesModelImpl.PORTLETID_COLUMN_BITMASK);
2946            public static final FinderPath FINDER_PATH_COUNT_BY_O_O_PI = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
2947                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
2948                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_O_PI",
2949                            new String[] {
2950                                    Long.class.getName(), Integer.class.getName(),
2951                                    String.class.getName()
2952                            });
2953    
2954            /**
2955             * Returns all the portlet preferenceses where ownerId = &#63; and ownerType = &#63; and portletId = &#63;.
2956             *
2957             * @param ownerId the owner ID
2958             * @param ownerType the owner type
2959             * @param portletId the portlet ID
2960             * @return the matching portlet preferenceses
2961             */
2962            @Override
2963            public List<PortletPreferences> findByO_O_PI(long ownerId, int ownerType,
2964                    String portletId) {
2965                    return findByO_O_PI(ownerId, ownerType, portletId, QueryUtil.ALL_POS,
2966                            QueryUtil.ALL_POS, null);
2967            }
2968    
2969            /**
2970             * Returns a range of all the portlet preferenceses where ownerId = &#63; and ownerType = &#63; and portletId = &#63;.
2971             *
2972             * <p>
2973             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2974             * </p>
2975             *
2976             * @param ownerId the owner ID
2977             * @param ownerType the owner type
2978             * @param portletId the portlet ID
2979             * @param start the lower bound of the range of portlet preferenceses
2980             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
2981             * @return the range of matching portlet preferenceses
2982             */
2983            @Override
2984            public List<PortletPreferences> findByO_O_PI(long ownerId, int ownerType,
2985                    String portletId, int start, int end) {
2986                    return findByO_O_PI(ownerId, ownerType, portletId, start, end, null);
2987            }
2988    
2989            /**
2990             * Returns an ordered range of all the portlet preferenceses where ownerId = &#63; and ownerType = &#63; and portletId = &#63;.
2991             *
2992             * <p>
2993             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2994             * </p>
2995             *
2996             * @param ownerId the owner ID
2997             * @param ownerType the owner type
2998             * @param portletId the portlet ID
2999             * @param start the lower bound of the range of portlet preferenceses
3000             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
3001             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3002             * @return the ordered range of matching portlet preferenceses
3003             */
3004            @Override
3005            public List<PortletPreferences> findByO_O_PI(long ownerId, int ownerType,
3006                    String portletId, int start, int end,
3007                    OrderByComparator<PortletPreferences> orderByComparator) {
3008                    return findByO_O_PI(ownerId, ownerType, portletId, start, end,
3009                            orderByComparator, true);
3010            }
3011    
3012            /**
3013             * Returns an ordered range of all the portlet preferenceses where ownerId = &#63; and ownerType = &#63; and portletId = &#63;.
3014             *
3015             * <p>
3016             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
3017             * </p>
3018             *
3019             * @param ownerId the owner ID
3020             * @param ownerType the owner type
3021             * @param portletId the portlet ID
3022             * @param start the lower bound of the range of portlet preferenceses
3023             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
3024             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3025             * @param retrieveFromCache whether to retrieve from the finder cache
3026             * @return the ordered range of matching portlet preferenceses
3027             */
3028            @Override
3029            public List<PortletPreferences> findByO_O_PI(long ownerId, int ownerType,
3030                    String portletId, int start, int end,
3031                    OrderByComparator<PortletPreferences> orderByComparator,
3032                    boolean retrieveFromCache) {
3033                    boolean pagination = true;
3034                    FinderPath finderPath = null;
3035                    Object[] finderArgs = null;
3036    
3037                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3038                                    (orderByComparator == null)) {
3039                            pagination = false;
3040                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_PI;
3041                            finderArgs = new Object[] { ownerId, ownerType, portletId };
3042                    }
3043                    else {
3044                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_O_O_PI;
3045                            finderArgs = new Object[] {
3046                                            ownerId, ownerType, portletId,
3047                                            
3048                                            start, end, orderByComparator
3049                                    };
3050                    }
3051    
3052                    List<PortletPreferences> list = null;
3053    
3054                    if (retrieveFromCache) {
3055                            list = (List<PortletPreferences>)finderCache.getResult(finderPath,
3056                                            finderArgs, this);
3057    
3058                            if ((list != null) && !list.isEmpty()) {
3059                                    for (PortletPreferences portletPreferences : list) {
3060                                            if ((ownerId != portletPreferences.getOwnerId()) ||
3061                                                            (ownerType != portletPreferences.getOwnerType()) ||
3062                                                            !Validator.equals(portletId,
3063                                                                    portletPreferences.getPortletId())) {
3064                                                    list = null;
3065    
3066                                                    break;
3067                                            }
3068                                    }
3069                            }
3070                    }
3071    
3072                    if (list == null) {
3073                            StringBundler query = null;
3074    
3075                            if (orderByComparator != null) {
3076                                    query = new StringBundler(5 +
3077                                                    (orderByComparator.getOrderByFields().length * 2));
3078                            }
3079                            else {
3080                                    query = new StringBundler(5);
3081                            }
3082    
3083                            query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
3084    
3085                            query.append(_FINDER_COLUMN_O_O_PI_OWNERID_2);
3086    
3087                            query.append(_FINDER_COLUMN_O_O_PI_OWNERTYPE_2);
3088    
3089                            boolean bindPortletId = false;
3090    
3091                            if (portletId == null) {
3092                                    query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_1);
3093                            }
3094                            else if (portletId.equals(StringPool.BLANK)) {
3095                                    query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_3);
3096                            }
3097                            else {
3098                                    bindPortletId = true;
3099    
3100                                    query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_2);
3101                            }
3102    
3103                            if (orderByComparator != null) {
3104                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3105                                            orderByComparator);
3106                            }
3107                            else
3108                             if (pagination) {
3109                                    query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
3110                            }
3111    
3112                            String sql = query.toString();
3113    
3114                            Session session = null;
3115    
3116                            try {
3117                                    session = openSession();
3118    
3119                                    Query q = session.createQuery(sql);
3120    
3121                                    QueryPos qPos = QueryPos.getInstance(q);
3122    
3123                                    qPos.add(ownerId);
3124    
3125                                    qPos.add(ownerType);
3126    
3127                                    if (bindPortletId) {
3128                                            qPos.add(portletId);
3129                                    }
3130    
3131                                    if (!pagination) {
3132                                            list = (List<PortletPreferences>)QueryUtil.list(q,
3133                                                            getDialect(), start, end, false);
3134    
3135                                            Collections.sort(list);
3136    
3137                                            list = Collections.unmodifiableList(list);
3138                                    }
3139                                    else {
3140                                            list = (List<PortletPreferences>)QueryUtil.list(q,
3141                                                            getDialect(), start, end);
3142                                    }
3143    
3144                                    cacheResult(list);
3145    
3146                                    finderCache.putResult(finderPath, finderArgs, list);
3147                            }
3148                            catch (Exception e) {
3149                                    finderCache.removeResult(finderPath, finderArgs);
3150    
3151                                    throw processException(e);
3152                            }
3153                            finally {
3154                                    closeSession(session);
3155                            }
3156                    }
3157    
3158                    return list;
3159            }
3160    
3161            /**
3162             * Returns the first portlet preferences in the ordered set where ownerId = &#63; and ownerType = &#63; and portletId = &#63;.
3163             *
3164             * @param ownerId the owner ID
3165             * @param ownerType the owner type
3166             * @param portletId the portlet ID
3167             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3168             * @return the first matching portlet preferences
3169             * @throws NoSuchPortletPreferencesException if a matching portlet preferences could not be found
3170             */
3171            @Override
3172            public PortletPreferences findByO_O_PI_First(long ownerId, int ownerType,
3173                    String portletId,
3174                    OrderByComparator<PortletPreferences> orderByComparator)
3175                    throws NoSuchPortletPreferencesException {
3176                    PortletPreferences portletPreferences = fetchByO_O_PI_First(ownerId,
3177                                    ownerType, portletId, orderByComparator);
3178    
3179                    if (portletPreferences != null) {
3180                            return portletPreferences;
3181                    }
3182    
3183                    StringBundler msg = new StringBundler(8);
3184    
3185                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3186    
3187                    msg.append("ownerId=");
3188                    msg.append(ownerId);
3189    
3190                    msg.append(", ownerType=");
3191                    msg.append(ownerType);
3192    
3193                    msg.append(", portletId=");
3194                    msg.append(portletId);
3195    
3196                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3197    
3198                    throw new NoSuchPortletPreferencesException(msg.toString());
3199            }
3200    
3201            /**
3202             * Returns the first portlet preferences in the ordered set where ownerId = &#63; and ownerType = &#63; and portletId = &#63;.
3203             *
3204             * @param ownerId the owner ID
3205             * @param ownerType the owner type
3206             * @param portletId the portlet ID
3207             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3208             * @return the first matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
3209             */
3210            @Override
3211            public PortletPreferences fetchByO_O_PI_First(long ownerId, int ownerType,
3212                    String portletId,
3213                    OrderByComparator<PortletPreferences> orderByComparator) {
3214                    List<PortletPreferences> list = findByO_O_PI(ownerId, ownerType,
3215                                    portletId, 0, 1, orderByComparator);
3216    
3217                    if (!list.isEmpty()) {
3218                            return list.get(0);
3219                    }
3220    
3221                    return null;
3222            }
3223    
3224            /**
3225             * Returns the last portlet preferences in the ordered set where ownerId = &#63; and ownerType = &#63; and portletId = &#63;.
3226             *
3227             * @param ownerId the owner ID
3228             * @param ownerType the owner type
3229             * @param portletId the portlet ID
3230             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3231             * @return the last matching portlet preferences
3232             * @throws NoSuchPortletPreferencesException if a matching portlet preferences could not be found
3233             */
3234            @Override
3235            public PortletPreferences findByO_O_PI_Last(long ownerId, int ownerType,
3236                    String portletId,
3237                    OrderByComparator<PortletPreferences> orderByComparator)
3238                    throws NoSuchPortletPreferencesException {
3239                    PortletPreferences portletPreferences = fetchByO_O_PI_Last(ownerId,
3240                                    ownerType, portletId, orderByComparator);
3241    
3242                    if (portletPreferences != null) {
3243                            return portletPreferences;
3244                    }
3245    
3246                    StringBundler msg = new StringBundler(8);
3247    
3248                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3249    
3250                    msg.append("ownerId=");
3251                    msg.append(ownerId);
3252    
3253                    msg.append(", ownerType=");
3254                    msg.append(ownerType);
3255    
3256                    msg.append(", portletId=");
3257                    msg.append(portletId);
3258    
3259                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3260    
3261                    throw new NoSuchPortletPreferencesException(msg.toString());
3262            }
3263    
3264            /**
3265             * Returns the last portlet preferences in the ordered set where ownerId = &#63; and ownerType = &#63; and portletId = &#63;.
3266             *
3267             * @param ownerId the owner ID
3268             * @param ownerType the owner type
3269             * @param portletId the portlet ID
3270             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3271             * @return the last matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
3272             */
3273            @Override
3274            public PortletPreferences fetchByO_O_PI_Last(long ownerId, int ownerType,
3275                    String portletId,
3276                    OrderByComparator<PortletPreferences> orderByComparator) {
3277                    int count = countByO_O_PI(ownerId, ownerType, portletId);
3278    
3279                    if (count == 0) {
3280                            return null;
3281                    }
3282    
3283                    List<PortletPreferences> list = findByO_O_PI(ownerId, ownerType,
3284                                    portletId, count - 1, count, orderByComparator);
3285    
3286                    if (!list.isEmpty()) {
3287                            return list.get(0);
3288                    }
3289    
3290                    return null;
3291            }
3292    
3293            /**
3294             * Returns the portlet preferenceses before and after the current portlet preferences in the ordered set where ownerId = &#63; and ownerType = &#63; and portletId = &#63;.
3295             *
3296             * @param portletPreferencesId the primary key of the current portlet preferences
3297             * @param ownerId the owner ID
3298             * @param ownerType the owner type
3299             * @param portletId the portlet ID
3300             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3301             * @return the previous, current, and next portlet preferences
3302             * @throws NoSuchPortletPreferencesException if a portlet preferences with the primary key could not be found
3303             */
3304            @Override
3305            public PortletPreferences[] findByO_O_PI_PrevAndNext(
3306                    long portletPreferencesId, long ownerId, int ownerType,
3307                    String portletId,
3308                    OrderByComparator<PortletPreferences> orderByComparator)
3309                    throws NoSuchPortletPreferencesException {
3310                    PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
3311    
3312                    Session session = null;
3313    
3314                    try {
3315                            session = openSession();
3316    
3317                            PortletPreferences[] array = new PortletPreferencesImpl[3];
3318    
3319                            array[0] = getByO_O_PI_PrevAndNext(session, portletPreferences,
3320                                            ownerId, ownerType, portletId, orderByComparator, true);
3321    
3322                            array[1] = portletPreferences;
3323    
3324                            array[2] = getByO_O_PI_PrevAndNext(session, portletPreferences,
3325                                            ownerId, ownerType, portletId, orderByComparator, false);
3326    
3327                            return array;
3328                    }
3329                    catch (Exception e) {
3330                            throw processException(e);
3331                    }
3332                    finally {
3333                            closeSession(session);
3334                    }
3335            }
3336    
3337            protected PortletPreferences getByO_O_PI_PrevAndNext(Session session,
3338                    PortletPreferences portletPreferences, long ownerId, int ownerType,
3339                    String portletId,
3340                    OrderByComparator<PortletPreferences> orderByComparator,
3341                    boolean previous) {
3342                    StringBundler query = null;
3343    
3344                    if (orderByComparator != null) {
3345                            query = new StringBundler(6 +
3346                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3347                                            (orderByComparator.getOrderByFields().length * 3));
3348                    }
3349                    else {
3350                            query = new StringBundler(5);
3351                    }
3352    
3353                    query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
3354    
3355                    query.append(_FINDER_COLUMN_O_O_PI_OWNERID_2);
3356    
3357                    query.append(_FINDER_COLUMN_O_O_PI_OWNERTYPE_2);
3358    
3359                    boolean bindPortletId = false;
3360    
3361                    if (portletId == null) {
3362                            query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_1);
3363                    }
3364                    else if (portletId.equals(StringPool.BLANK)) {
3365                            query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_3);
3366                    }
3367                    else {
3368                            bindPortletId = true;
3369    
3370                            query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_2);
3371                    }
3372    
3373                    if (orderByComparator != null) {
3374                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3375    
3376                            if (orderByConditionFields.length > 0) {
3377                                    query.append(WHERE_AND);
3378                            }
3379    
3380                            for (int i = 0; i < orderByConditionFields.length; i++) {
3381                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3382                                    query.append(orderByConditionFields[i]);
3383    
3384                                    if ((i + 1) < orderByConditionFields.length) {
3385                                            if (orderByComparator.isAscending() ^ previous) {
3386                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3387                                            }
3388                                            else {
3389                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3390                                            }
3391                                    }
3392                                    else {
3393                                            if (orderByComparator.isAscending() ^ previous) {
3394                                                    query.append(WHERE_GREATER_THAN);
3395                                            }
3396                                            else {
3397                                                    query.append(WHERE_LESSER_THAN);
3398                                            }
3399                                    }
3400                            }
3401    
3402                            query.append(ORDER_BY_CLAUSE);
3403    
3404                            String[] orderByFields = orderByComparator.getOrderByFields();
3405    
3406                            for (int i = 0; i < orderByFields.length; i++) {
3407                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3408                                    query.append(orderByFields[i]);
3409    
3410                                    if ((i + 1) < orderByFields.length) {
3411                                            if (orderByComparator.isAscending() ^ previous) {
3412                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3413                                            }
3414                                            else {
3415                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3416                                            }
3417                                    }
3418                                    else {
3419                                            if (orderByComparator.isAscending() ^ previous) {
3420                                                    query.append(ORDER_BY_ASC);
3421                                            }
3422                                            else {
3423                                                    query.append(ORDER_BY_DESC);
3424                                            }
3425                                    }
3426                            }
3427                    }
3428                    else {
3429                            query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
3430                    }
3431    
3432                    String sql = query.toString();
3433    
3434                    Query q = session.createQuery(sql);
3435    
3436                    q.setFirstResult(0);
3437                    q.setMaxResults(2);
3438    
3439                    QueryPos qPos = QueryPos.getInstance(q);
3440    
3441                    qPos.add(ownerId);
3442    
3443                    qPos.add(ownerType);
3444    
3445                    if (bindPortletId) {
3446                            qPos.add(portletId);
3447                    }
3448    
3449                    if (orderByComparator != null) {
3450                            Object[] values = orderByComparator.getOrderByConditionValues(portletPreferences);
3451    
3452                            for (Object value : values) {
3453                                    qPos.add(value);
3454                            }
3455                    }
3456    
3457                    List<PortletPreferences> list = q.list();
3458    
3459                    if (list.size() == 2) {
3460                            return list.get(1);
3461                    }
3462                    else {
3463                            return null;
3464                    }
3465            }
3466    
3467            /**
3468             * Removes all the portlet preferenceses where ownerId = &#63; and ownerType = &#63; and portletId = &#63; from the database.
3469             *
3470             * @param ownerId the owner ID
3471             * @param ownerType the owner type
3472             * @param portletId the portlet ID
3473             */
3474            @Override
3475            public void removeByO_O_PI(long ownerId, int ownerType, String portletId) {
3476                    for (PortletPreferences portletPreferences : findByO_O_PI(ownerId,
3477                                    ownerType, portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3478                            remove(portletPreferences);
3479                    }
3480            }
3481    
3482            /**
3483             * Returns the number of portlet preferenceses where ownerId = &#63; and ownerType = &#63; and portletId = &#63;.
3484             *
3485             * @param ownerId the owner ID
3486             * @param ownerType the owner type
3487             * @param portletId the portlet ID
3488             * @return the number of matching portlet preferenceses
3489             */
3490            @Override
3491            public int countByO_O_PI(long ownerId, int ownerType, String portletId) {
3492                    FinderPath finderPath = FINDER_PATH_COUNT_BY_O_O_PI;
3493    
3494                    Object[] finderArgs = new Object[] { ownerId, ownerType, portletId };
3495    
3496                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3497    
3498                    if (count == null) {
3499                            StringBundler query = new StringBundler(4);
3500    
3501                            query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
3502    
3503                            query.append(_FINDER_COLUMN_O_O_PI_OWNERID_2);
3504    
3505                            query.append(_FINDER_COLUMN_O_O_PI_OWNERTYPE_2);
3506    
3507                            boolean bindPortletId = false;
3508    
3509                            if (portletId == null) {
3510                                    query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_1);
3511                            }
3512                            else if (portletId.equals(StringPool.BLANK)) {
3513                                    query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_3);
3514                            }
3515                            else {
3516                                    bindPortletId = true;
3517    
3518                                    query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_2);
3519                            }
3520    
3521                            String sql = query.toString();
3522    
3523                            Session session = null;
3524    
3525                            try {
3526                                    session = openSession();
3527    
3528                                    Query q = session.createQuery(sql);
3529    
3530                                    QueryPos qPos = QueryPos.getInstance(q);
3531    
3532                                    qPos.add(ownerId);
3533    
3534                                    qPos.add(ownerType);
3535    
3536                                    if (bindPortletId) {
3537                                            qPos.add(portletId);
3538                                    }
3539    
3540                                    count = (Long)q.uniqueResult();
3541    
3542                                    finderCache.putResult(finderPath, finderArgs, count);
3543                            }
3544                            catch (Exception e) {
3545                                    finderCache.removeResult(finderPath, finderArgs);
3546    
3547                                    throw processException(e);
3548                            }
3549                            finally {
3550                                    closeSession(session);
3551                            }
3552                    }
3553    
3554                    return count.intValue();
3555            }
3556    
3557            private static final String _FINDER_COLUMN_O_O_PI_OWNERID_2 = "portletPreferences.ownerId = ? AND ";
3558            private static final String _FINDER_COLUMN_O_O_PI_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
3559            private static final String _FINDER_COLUMN_O_O_PI_PORTLETID_1 = "portletPreferences.portletId IS NULL";
3560            private static final String _FINDER_COLUMN_O_O_PI_PORTLETID_2 = "portletPreferences.portletId = ?";
3561            private static final String _FINDER_COLUMN_O_O_PI_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = '')";
3562            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_O_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
3563                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
3564                            PortletPreferencesImpl.class,
3565                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByO_P_P",
3566                            new String[] {
3567                                    Integer.class.getName(), Long.class.getName(),
3568                                    String.class.getName(),
3569                                    
3570                            Integer.class.getName(), Integer.class.getName(),
3571                                    OrderByComparator.class.getName()
3572                            });
3573            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
3574                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
3575                            PortletPreferencesImpl.class,
3576                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByO_P_P",
3577                            new String[] {
3578                                    Integer.class.getName(), Long.class.getName(),
3579                                    String.class.getName()
3580                            },
3581                            PortletPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK |
3582                            PortletPreferencesModelImpl.PLID_COLUMN_BITMASK |
3583                            PortletPreferencesModelImpl.PORTLETID_COLUMN_BITMASK);
3584            public static final FinderPath FINDER_PATH_COUNT_BY_O_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
3585                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
3586                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_P_P",
3587                            new String[] {
3588                                    Integer.class.getName(), Long.class.getName(),
3589                                    String.class.getName()
3590                            });
3591    
3592            /**
3593             * Returns all the portlet preferenceses where ownerType = &#63; and plid = &#63; and portletId = &#63;.
3594             *
3595             * @param ownerType the owner type
3596             * @param plid the plid
3597             * @param portletId the portlet ID
3598             * @return the matching portlet preferenceses
3599             */
3600            @Override
3601            public List<PortletPreferences> findByO_P_P(int ownerType, long plid,
3602                    String portletId) {
3603                    return findByO_P_P(ownerType, plid, portletId, QueryUtil.ALL_POS,
3604                            QueryUtil.ALL_POS, null);
3605            }
3606    
3607            /**
3608             * Returns a range of all the portlet preferenceses where ownerType = &#63; and plid = &#63; and portletId = &#63;.
3609             *
3610             * <p>
3611             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
3612             * </p>
3613             *
3614             * @param ownerType the owner type
3615             * @param plid the plid
3616             * @param portletId the portlet ID
3617             * @param start the lower bound of the range of portlet preferenceses
3618             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
3619             * @return the range of matching portlet preferenceses
3620             */
3621            @Override
3622            public List<PortletPreferences> findByO_P_P(int ownerType, long plid,
3623                    String portletId, int start, int end) {
3624                    return findByO_P_P(ownerType, plid, portletId, start, end, null);
3625            }
3626    
3627            /**
3628             * Returns an ordered range of all the portlet preferenceses where ownerType = &#63; and plid = &#63; and portletId = &#63;.
3629             *
3630             * <p>
3631             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
3632             * </p>
3633             *
3634             * @param ownerType the owner type
3635             * @param plid the plid
3636             * @param portletId the portlet ID
3637             * @param start the lower bound of the range of portlet preferenceses
3638             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
3639             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3640             * @return the ordered range of matching portlet preferenceses
3641             */
3642            @Override
3643            public List<PortletPreferences> findByO_P_P(int ownerType, long plid,
3644                    String portletId, int start, int end,
3645                    OrderByComparator<PortletPreferences> orderByComparator) {
3646                    return findByO_P_P(ownerType, plid, portletId, start, end,
3647                            orderByComparator, true);
3648            }
3649    
3650            /**
3651             * Returns an ordered range of all the portlet preferenceses where ownerType = &#63; and plid = &#63; and portletId = &#63;.
3652             *
3653             * <p>
3654             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
3655             * </p>
3656             *
3657             * @param ownerType the owner type
3658             * @param plid the plid
3659             * @param portletId the portlet ID
3660             * @param start the lower bound of the range of portlet preferenceses
3661             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
3662             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3663             * @param retrieveFromCache whether to retrieve from the finder cache
3664             * @return the ordered range of matching portlet preferenceses
3665             */
3666            @Override
3667            public List<PortletPreferences> findByO_P_P(int ownerType, long plid,
3668                    String portletId, int start, int end,
3669                    OrderByComparator<PortletPreferences> orderByComparator,
3670                    boolean retrieveFromCache) {
3671                    boolean pagination = true;
3672                    FinderPath finderPath = null;
3673                    Object[] finderArgs = null;
3674    
3675                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3676                                    (orderByComparator == null)) {
3677                            pagination = false;
3678                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P_P;
3679                            finderArgs = new Object[] { ownerType, plid, portletId };
3680                    }
3681                    else {
3682                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_O_P_P;
3683                            finderArgs = new Object[] {
3684                                            ownerType, plid, portletId,
3685                                            
3686                                            start, end, orderByComparator
3687                                    };
3688                    }
3689    
3690                    List<PortletPreferences> list = null;
3691    
3692                    if (retrieveFromCache) {
3693                            list = (List<PortletPreferences>)finderCache.getResult(finderPath,
3694                                            finderArgs, this);
3695    
3696                            if ((list != null) && !list.isEmpty()) {
3697                                    for (PortletPreferences portletPreferences : list) {
3698                                            if ((ownerType != portletPreferences.getOwnerType()) ||
3699                                                            (plid != portletPreferences.getPlid()) ||
3700                                                            !Validator.equals(portletId,
3701                                                                    portletPreferences.getPortletId())) {
3702                                                    list = null;
3703    
3704                                                    break;
3705                                            }
3706                                    }
3707                            }
3708                    }
3709    
3710                    if (list == null) {
3711                            StringBundler query = null;
3712    
3713                            if (orderByComparator != null) {
3714                                    query = new StringBundler(5 +
3715                                                    (orderByComparator.getOrderByFields().length * 2));
3716                            }
3717                            else {
3718                                    query = new StringBundler(5);
3719                            }
3720    
3721                            query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
3722    
3723                            query.append(_FINDER_COLUMN_O_P_P_OWNERTYPE_2);
3724    
3725                            query.append(_FINDER_COLUMN_O_P_P_PLID_2);
3726    
3727                            boolean bindPortletId = false;
3728    
3729                            if (portletId == null) {
3730                                    query.append(_FINDER_COLUMN_O_P_P_PORTLETID_1);
3731                            }
3732                            else if (portletId.equals(StringPool.BLANK)) {
3733                                    query.append(_FINDER_COLUMN_O_P_P_PORTLETID_3);
3734                            }
3735                            else {
3736                                    bindPortletId = true;
3737    
3738                                    query.append(_FINDER_COLUMN_O_P_P_PORTLETID_2);
3739                            }
3740    
3741                            if (orderByComparator != null) {
3742                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3743                                            orderByComparator);
3744                            }
3745                            else
3746                             if (pagination) {
3747                                    query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
3748                            }
3749    
3750                            String sql = query.toString();
3751    
3752                            Session session = null;
3753    
3754                            try {
3755                                    session = openSession();
3756    
3757                                    Query q = session.createQuery(sql);
3758    
3759                                    QueryPos qPos = QueryPos.getInstance(q);
3760    
3761                                    qPos.add(ownerType);
3762    
3763                                    qPos.add(plid);
3764    
3765                                    if (bindPortletId) {
3766                                            qPos.add(portletId);
3767                                    }
3768    
3769                                    if (!pagination) {
3770                                            list = (List<PortletPreferences>)QueryUtil.list(q,
3771                                                            getDialect(), start, end, false);
3772    
3773                                            Collections.sort(list);
3774    
3775                                            list = Collections.unmodifiableList(list);
3776                                    }
3777                                    else {
3778                                            list = (List<PortletPreferences>)QueryUtil.list(q,
3779                                                            getDialect(), start, end);
3780                                    }
3781    
3782                                    cacheResult(list);
3783    
3784                                    finderCache.putResult(finderPath, finderArgs, list);
3785                            }
3786                            catch (Exception e) {
3787                                    finderCache.removeResult(finderPath, finderArgs);
3788    
3789                                    throw processException(e);
3790                            }
3791                            finally {
3792                                    closeSession(session);
3793                            }
3794                    }
3795    
3796                    return list;
3797            }
3798    
3799            /**
3800             * Returns the first portlet preferences in the ordered set where ownerType = &#63; and plid = &#63; and portletId = &#63;.
3801             *
3802             * @param ownerType the owner type
3803             * @param plid the plid
3804             * @param portletId the portlet ID
3805             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3806             * @return the first matching portlet preferences
3807             * @throws NoSuchPortletPreferencesException if a matching portlet preferences could not be found
3808             */
3809            @Override
3810            public PortletPreferences findByO_P_P_First(int ownerType, long plid,
3811                    String portletId,
3812                    OrderByComparator<PortletPreferences> orderByComparator)
3813                    throws NoSuchPortletPreferencesException {
3814                    PortletPreferences portletPreferences = fetchByO_P_P_First(ownerType,
3815                                    plid, portletId, orderByComparator);
3816    
3817                    if (portletPreferences != null) {
3818                            return portletPreferences;
3819                    }
3820    
3821                    StringBundler msg = new StringBundler(8);
3822    
3823                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3824    
3825                    msg.append("ownerType=");
3826                    msg.append(ownerType);
3827    
3828                    msg.append(", plid=");
3829                    msg.append(plid);
3830    
3831                    msg.append(", portletId=");
3832                    msg.append(portletId);
3833    
3834                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3835    
3836                    throw new NoSuchPortletPreferencesException(msg.toString());
3837            }
3838    
3839            /**
3840             * Returns the first portlet preferences in the ordered set where ownerType = &#63; and plid = &#63; and portletId = &#63;.
3841             *
3842             * @param ownerType the owner type
3843             * @param plid the plid
3844             * @param portletId the portlet ID
3845             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3846             * @return the first matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
3847             */
3848            @Override
3849            public PortletPreferences fetchByO_P_P_First(int ownerType, long plid,
3850                    String portletId,
3851                    OrderByComparator<PortletPreferences> orderByComparator) {
3852                    List<PortletPreferences> list = findByO_P_P(ownerType, plid, portletId,
3853                                    0, 1, orderByComparator);
3854    
3855                    if (!list.isEmpty()) {
3856                            return list.get(0);
3857                    }
3858    
3859                    return null;
3860            }
3861    
3862            /**
3863             * Returns the last portlet preferences in the ordered set where ownerType = &#63; and plid = &#63; and portletId = &#63;.
3864             *
3865             * @param ownerType the owner type
3866             * @param plid the plid
3867             * @param portletId the portlet ID
3868             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3869             * @return the last matching portlet preferences
3870             * @throws NoSuchPortletPreferencesException if a matching portlet preferences could not be found
3871             */
3872            @Override
3873            public PortletPreferences findByO_P_P_Last(int ownerType, long plid,
3874                    String portletId,
3875                    OrderByComparator<PortletPreferences> orderByComparator)
3876                    throws NoSuchPortletPreferencesException {
3877                    PortletPreferences portletPreferences = fetchByO_P_P_Last(ownerType,
3878                                    plid, portletId, orderByComparator);
3879    
3880                    if (portletPreferences != null) {
3881                            return portletPreferences;
3882                    }
3883    
3884                    StringBundler msg = new StringBundler(8);
3885    
3886                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3887    
3888                    msg.append("ownerType=");
3889                    msg.append(ownerType);
3890    
3891                    msg.append(", plid=");
3892                    msg.append(plid);
3893    
3894                    msg.append(", portletId=");
3895                    msg.append(portletId);
3896    
3897                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3898    
3899                    throw new NoSuchPortletPreferencesException(msg.toString());
3900            }
3901    
3902            /**
3903             * Returns the last portlet preferences in the ordered set where ownerType = &#63; and plid = &#63; and portletId = &#63;.
3904             *
3905             * @param ownerType the owner type
3906             * @param plid the plid
3907             * @param portletId the portlet ID
3908             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3909             * @return the last matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
3910             */
3911            @Override
3912            public PortletPreferences fetchByO_P_P_Last(int ownerType, long plid,
3913                    String portletId,
3914                    OrderByComparator<PortletPreferences> orderByComparator) {
3915                    int count = countByO_P_P(ownerType, plid, portletId);
3916    
3917                    if (count == 0) {
3918                            return null;
3919                    }
3920    
3921                    List<PortletPreferences> list = findByO_P_P(ownerType, plid, portletId,
3922                                    count - 1, count, orderByComparator);
3923    
3924                    if (!list.isEmpty()) {
3925                            return list.get(0);
3926                    }
3927    
3928                    return null;
3929            }
3930    
3931            /**
3932             * Returns the portlet preferenceses before and after the current portlet preferences in the ordered set where ownerType = &#63; and plid = &#63; and portletId = &#63;.
3933             *
3934             * @param portletPreferencesId the primary key of the current portlet preferences
3935             * @param ownerType the owner type
3936             * @param plid the plid
3937             * @param portletId the portlet ID
3938             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3939             * @return the previous, current, and next portlet preferences
3940             * @throws NoSuchPortletPreferencesException if a portlet preferences with the primary key could not be found
3941             */
3942            @Override
3943            public PortletPreferences[] findByO_P_P_PrevAndNext(
3944                    long portletPreferencesId, int ownerType, long plid, String portletId,
3945                    OrderByComparator<PortletPreferences> orderByComparator)
3946                    throws NoSuchPortletPreferencesException {
3947                    PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
3948    
3949                    Session session = null;
3950    
3951                    try {
3952                            session = openSession();
3953    
3954                            PortletPreferences[] array = new PortletPreferencesImpl[3];
3955    
3956                            array[0] = getByO_P_P_PrevAndNext(session, portletPreferences,
3957                                            ownerType, plid, portletId, orderByComparator, true);
3958    
3959                            array[1] = portletPreferences;
3960    
3961                            array[2] = getByO_P_P_PrevAndNext(session, portletPreferences,
3962                                            ownerType, plid, portletId, orderByComparator, false);
3963    
3964                            return array;
3965                    }
3966                    catch (Exception e) {
3967                            throw processException(e);
3968                    }
3969                    finally {
3970                            closeSession(session);
3971                    }
3972            }
3973    
3974            protected PortletPreferences getByO_P_P_PrevAndNext(Session session,
3975                    PortletPreferences portletPreferences, int ownerType, long plid,
3976                    String portletId,
3977                    OrderByComparator<PortletPreferences> orderByComparator,
3978                    boolean previous) {
3979                    StringBundler query = null;
3980    
3981                    if (orderByComparator != null) {
3982                            query = new StringBundler(6 +
3983                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3984                                            (orderByComparator.getOrderByFields().length * 3));
3985                    }
3986                    else {
3987                            query = new StringBundler(5);
3988                    }
3989    
3990                    query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
3991    
3992                    query.append(_FINDER_COLUMN_O_P_P_OWNERTYPE_2);
3993    
3994                    query.append(_FINDER_COLUMN_O_P_P_PLID_2);
3995    
3996                    boolean bindPortletId = false;
3997    
3998                    if (portletId == null) {
3999                            query.append(_FINDER_COLUMN_O_P_P_PORTLETID_1);
4000                    }
4001                    else if (portletId.equals(StringPool.BLANK)) {
4002                            query.append(_FINDER_COLUMN_O_P_P_PORTLETID_3);
4003                    }
4004                    else {
4005                            bindPortletId = true;
4006    
4007                            query.append(_FINDER_COLUMN_O_P_P_PORTLETID_2);
4008                    }
4009    
4010                    if (orderByComparator != null) {
4011                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4012    
4013                            if (orderByConditionFields.length > 0) {
4014                                    query.append(WHERE_AND);
4015                            }
4016    
4017                            for (int i = 0; i < orderByConditionFields.length; i++) {
4018                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4019                                    query.append(orderByConditionFields[i]);
4020    
4021                                    if ((i + 1) < orderByConditionFields.length) {
4022                                            if (orderByComparator.isAscending() ^ previous) {
4023                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4024                                            }
4025                                            else {
4026                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4027                                            }
4028                                    }
4029                                    else {
4030                                            if (orderByComparator.isAscending() ^ previous) {
4031                                                    query.append(WHERE_GREATER_THAN);
4032                                            }
4033                                            else {
4034                                                    query.append(WHERE_LESSER_THAN);
4035                                            }
4036                                    }
4037                            }
4038    
4039                            query.append(ORDER_BY_CLAUSE);
4040    
4041                            String[] orderByFields = orderByComparator.getOrderByFields();
4042    
4043                            for (int i = 0; i < orderByFields.length; i++) {
4044                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4045                                    query.append(orderByFields[i]);
4046    
4047                                    if ((i + 1) < orderByFields.length) {
4048                                            if (orderByComparator.isAscending() ^ previous) {
4049                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4050                                            }
4051                                            else {
4052                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4053                                            }
4054                                    }
4055                                    else {
4056                                            if (orderByComparator.isAscending() ^ previous) {
4057                                                    query.append(ORDER_BY_ASC);
4058                                            }
4059                                            else {
4060                                                    query.append(ORDER_BY_DESC);
4061                                            }
4062                                    }
4063                            }
4064                    }
4065                    else {
4066                            query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
4067                    }
4068    
4069                    String sql = query.toString();
4070    
4071                    Query q = session.createQuery(sql);
4072    
4073                    q.setFirstResult(0);
4074                    q.setMaxResults(2);
4075    
4076                    QueryPos qPos = QueryPos.getInstance(q);
4077    
4078                    qPos.add(ownerType);
4079    
4080                    qPos.add(plid);
4081    
4082                    if (bindPortletId) {
4083                            qPos.add(portletId);
4084                    }
4085    
4086                    if (orderByComparator != null) {
4087                            Object[] values = orderByComparator.getOrderByConditionValues(portletPreferences);
4088    
4089                            for (Object value : values) {
4090                                    qPos.add(value);
4091                            }
4092                    }
4093    
4094                    List<PortletPreferences> list = q.list();
4095    
4096                    if (list.size() == 2) {
4097                            return list.get(1);
4098                    }
4099                    else {
4100                            return null;
4101                    }
4102            }
4103    
4104            /**
4105             * Removes all the portlet preferenceses where ownerType = &#63; and plid = &#63; and portletId = &#63; from the database.
4106             *
4107             * @param ownerType the owner type
4108             * @param plid the plid
4109             * @param portletId the portlet ID
4110             */
4111            @Override
4112            public void removeByO_P_P(int ownerType, long plid, String portletId) {
4113                    for (PortletPreferences portletPreferences : findByO_P_P(ownerType,
4114                                    plid, portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4115                            remove(portletPreferences);
4116                    }
4117            }
4118    
4119            /**
4120             * Returns the number of portlet preferenceses where ownerType = &#63; and plid = &#63; and portletId = &#63;.
4121             *
4122             * @param ownerType the owner type
4123             * @param plid the plid
4124             * @param portletId the portlet ID
4125             * @return the number of matching portlet preferenceses
4126             */
4127            @Override
4128            public int countByO_P_P(int ownerType, long plid, String portletId) {
4129                    FinderPath finderPath = FINDER_PATH_COUNT_BY_O_P_P;
4130    
4131                    Object[] finderArgs = new Object[] { ownerType, plid, portletId };
4132    
4133                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4134    
4135                    if (count == null) {
4136                            StringBundler query = new StringBundler(4);
4137    
4138                            query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
4139    
4140                            query.append(_FINDER_COLUMN_O_P_P_OWNERTYPE_2);
4141    
4142                            query.append(_FINDER_COLUMN_O_P_P_PLID_2);
4143    
4144                            boolean bindPortletId = false;
4145    
4146                            if (portletId == null) {
4147                                    query.append(_FINDER_COLUMN_O_P_P_PORTLETID_1);
4148                            }
4149                            else if (portletId.equals(StringPool.BLANK)) {
4150                                    query.append(_FINDER_COLUMN_O_P_P_PORTLETID_3);
4151                            }
4152                            else {
4153                                    bindPortletId = true;
4154    
4155                                    query.append(_FINDER_COLUMN_O_P_P_PORTLETID_2);
4156                            }
4157    
4158                            String sql = query.toString();
4159    
4160                            Session session = null;
4161    
4162                            try {
4163                                    session = openSession();
4164    
4165                                    Query q = session.createQuery(sql);
4166    
4167                                    QueryPos qPos = QueryPos.getInstance(q);
4168    
4169                                    qPos.add(ownerType);
4170    
4171                                    qPos.add(plid);
4172    
4173                                    if (bindPortletId) {
4174                                            qPos.add(portletId);
4175                                    }
4176    
4177                                    count = (Long)q.uniqueResult();
4178    
4179                                    finderCache.putResult(finderPath, finderArgs, count);
4180                            }
4181                            catch (Exception e) {
4182                                    finderCache.removeResult(finderPath, finderArgs);
4183    
4184                                    throw processException(e);
4185                            }
4186                            finally {
4187                                    closeSession(session);
4188                            }
4189                    }
4190    
4191                    return count.intValue();
4192            }
4193    
4194            private static final String _FINDER_COLUMN_O_P_P_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
4195            private static final String _FINDER_COLUMN_O_P_P_PLID_2 = "portletPreferences.plid = ? AND ";
4196            private static final String _FINDER_COLUMN_O_P_P_PORTLETID_1 = "portletPreferences.portletId IS NULL";
4197            private static final String _FINDER_COLUMN_O_P_P_PORTLETID_2 = "portletPreferences.portletId = ?";
4198            private static final String _FINDER_COLUMN_O_P_P_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = '')";
4199            public static final FinderPath FINDER_PATH_FETCH_BY_O_O_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
4200                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
4201                            PortletPreferencesImpl.class, FINDER_CLASS_NAME_ENTITY,
4202                            "fetchByO_O_P_P",
4203                            new String[] {
4204                                    Long.class.getName(), Integer.class.getName(),
4205                                    Long.class.getName(), String.class.getName()
4206                            },
4207                            PortletPreferencesModelImpl.OWNERID_COLUMN_BITMASK |
4208                            PortletPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK |
4209                            PortletPreferencesModelImpl.PLID_COLUMN_BITMASK |
4210                            PortletPreferencesModelImpl.PORTLETID_COLUMN_BITMASK);
4211            public static final FinderPath FINDER_PATH_COUNT_BY_O_O_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
4212                            PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
4213                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_O_P_P",
4214                            new String[] {
4215                                    Long.class.getName(), Integer.class.getName(),
4216                                    Long.class.getName(), String.class.getName()
4217                            });
4218    
4219            /**
4220             * Returns the portlet preferences where ownerId = &#63; and ownerType = &#63; and plid = &#63; and portletId = &#63; or throws a {@link NoSuchPortletPreferencesException} if it could not be found.
4221             *
4222             * @param ownerId the owner ID
4223             * @param ownerType the owner type
4224             * @param plid the plid
4225             * @param portletId the portlet ID
4226             * @return the matching portlet preferences
4227             * @throws NoSuchPortletPreferencesException if a matching portlet preferences could not be found
4228             */
4229            @Override
4230            public PortletPreferences findByO_O_P_P(long ownerId, int ownerType,
4231                    long plid, String portletId) throws NoSuchPortletPreferencesException {
4232                    PortletPreferences portletPreferences = fetchByO_O_P_P(ownerId,
4233                                    ownerType, plid, portletId);
4234    
4235                    if (portletPreferences == null) {
4236                            StringBundler msg = new StringBundler(10);
4237    
4238                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4239    
4240                            msg.append("ownerId=");
4241                            msg.append(ownerId);
4242    
4243                            msg.append(", ownerType=");
4244                            msg.append(ownerType);
4245    
4246                            msg.append(", plid=");
4247                            msg.append(plid);
4248    
4249                            msg.append(", portletId=");
4250                            msg.append(portletId);
4251    
4252                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4253    
4254                            if (_log.isWarnEnabled()) {
4255                                    _log.warn(msg.toString());
4256                            }
4257    
4258                            throw new NoSuchPortletPreferencesException(msg.toString());
4259                    }
4260    
4261                    return portletPreferences;
4262            }
4263    
4264            /**
4265             * 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.
4266             *
4267             * @param ownerId the owner ID
4268             * @param ownerType the owner type
4269             * @param plid the plid
4270             * @param portletId the portlet ID
4271             * @return the matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
4272             */
4273            @Override
4274            public PortletPreferences fetchByO_O_P_P(long ownerId, int ownerType,
4275                    long plid, String portletId) {
4276                    return fetchByO_O_P_P(ownerId, ownerType, plid, portletId, true);
4277            }
4278    
4279            /**
4280             * 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.
4281             *
4282             * @param ownerId the owner ID
4283             * @param ownerType the owner type
4284             * @param plid the plid
4285             * @param portletId the portlet ID
4286             * @param retrieveFromCache whether to retrieve from the finder cache
4287             * @return the matching portlet preferences, or <code>null</code> if a matching portlet preferences could not be found
4288             */
4289            @Override
4290            public PortletPreferences fetchByO_O_P_P(long ownerId, int ownerType,
4291                    long plid, String portletId, boolean retrieveFromCache) {
4292                    Object[] finderArgs = new Object[] { ownerId, ownerType, plid, portletId };
4293    
4294                    Object result = null;
4295    
4296                    if (retrieveFromCache) {
4297                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_O_O_P_P,
4298                                            finderArgs, this);
4299                    }
4300    
4301                    if (result instanceof PortletPreferences) {
4302                            PortletPreferences portletPreferences = (PortletPreferences)result;
4303    
4304                            if ((ownerId != portletPreferences.getOwnerId()) ||
4305                                            (ownerType != portletPreferences.getOwnerType()) ||
4306                                            (plid != portletPreferences.getPlid()) ||
4307                                            !Validator.equals(portletId,
4308                                                    portletPreferences.getPortletId())) {
4309                                    result = null;
4310                            }
4311                    }
4312    
4313                    if (result == null) {
4314                            StringBundler query = new StringBundler(6);
4315    
4316                            query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
4317    
4318                            query.append(_FINDER_COLUMN_O_O_P_P_OWNERID_2);
4319    
4320                            query.append(_FINDER_COLUMN_O_O_P_P_OWNERTYPE_2);
4321    
4322                            query.append(_FINDER_COLUMN_O_O_P_P_PLID_2);
4323    
4324                            boolean bindPortletId = false;
4325    
4326                            if (portletId == null) {
4327                                    query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_1);
4328                            }
4329                            else if (portletId.equals(StringPool.BLANK)) {
4330                                    query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_3);
4331                            }
4332                            else {
4333                                    bindPortletId = true;
4334    
4335                                    query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_2);
4336                            }
4337    
4338                            String sql = query.toString();
4339    
4340                            Session session = null;
4341    
4342                            try {
4343                                    session = openSession();
4344    
4345                                    Query q = session.createQuery(sql);
4346    
4347                                    QueryPos qPos = QueryPos.getInstance(q);
4348    
4349                                    qPos.add(ownerId);
4350    
4351                                    qPos.add(ownerType);
4352    
4353                                    qPos.add(plid);
4354    
4355                                    if (bindPortletId) {
4356                                            qPos.add(portletId);
4357                                    }
4358    
4359                                    List<PortletPreferences> list = q.list();
4360    
4361                                    if (list.isEmpty()) {
4362                                            finderCache.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
4363                                                    finderArgs, list);
4364                                    }
4365                                    else {
4366                                            PortletPreferences portletPreferences = list.get(0);
4367    
4368                                            result = portletPreferences;
4369    
4370                                            cacheResult(portletPreferences);
4371    
4372                                            if ((portletPreferences.getOwnerId() != ownerId) ||
4373                                                            (portletPreferences.getOwnerType() != ownerType) ||
4374                                                            (portletPreferences.getPlid() != plid) ||
4375                                                            (portletPreferences.getPortletId() == null) ||
4376                                                            !portletPreferences.getPortletId().equals(portletId)) {
4377                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
4378                                                            finderArgs, portletPreferences);
4379                                            }
4380                                    }
4381                            }
4382                            catch (Exception e) {
4383                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_O_O_P_P,
4384                                            finderArgs);
4385    
4386                                    throw processException(e);
4387                            }
4388                            finally {
4389                                    closeSession(session);
4390                            }
4391                    }
4392    
4393                    if (result instanceof List<?>) {
4394                            return null;
4395                    }
4396                    else {
4397                            return (PortletPreferences)result;
4398                    }
4399            }
4400    
4401            /**
4402             * Removes the portlet preferences where ownerId = &#63; and ownerType = &#63; and plid = &#63; and portletId = &#63; from the database.
4403             *
4404             * @param ownerId the owner ID
4405             * @param ownerType the owner type
4406             * @param plid the plid
4407             * @param portletId the portlet ID
4408             * @return the portlet preferences that was removed
4409             */
4410            @Override
4411            public PortletPreferences removeByO_O_P_P(long ownerId, int ownerType,
4412                    long plid, String portletId) throws NoSuchPortletPreferencesException {
4413                    PortletPreferences portletPreferences = findByO_O_P_P(ownerId,
4414                                    ownerType, plid, portletId);
4415    
4416                    return remove(portletPreferences);
4417            }
4418    
4419            /**
4420             * Returns the number of portlet preferenceses where ownerId = &#63; and ownerType = &#63; and plid = &#63; and portletId = &#63;.
4421             *
4422             * @param ownerId the owner ID
4423             * @param ownerType the owner type
4424             * @param plid the plid
4425             * @param portletId the portlet ID
4426             * @return the number of matching portlet preferenceses
4427             */
4428            @Override
4429            public int countByO_O_P_P(long ownerId, int ownerType, long plid,
4430                    String portletId) {
4431                    FinderPath finderPath = FINDER_PATH_COUNT_BY_O_O_P_P;
4432    
4433                    Object[] finderArgs = new Object[] { ownerId, ownerType, plid, portletId };
4434    
4435                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4436    
4437                    if (count == null) {
4438                            StringBundler query = new StringBundler(5);
4439    
4440                            query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
4441    
4442                            query.append(_FINDER_COLUMN_O_O_P_P_OWNERID_2);
4443    
4444                            query.append(_FINDER_COLUMN_O_O_P_P_OWNERTYPE_2);
4445    
4446                            query.append(_FINDER_COLUMN_O_O_P_P_PLID_2);
4447    
4448                            boolean bindPortletId = false;
4449    
4450                            if (portletId == null) {
4451                                    query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_1);
4452                            }
4453                            else if (portletId.equals(StringPool.BLANK)) {
4454                                    query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_3);
4455                            }
4456                            else {
4457                                    bindPortletId = true;
4458    
4459                                    query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_2);
4460                            }
4461    
4462                            String sql = query.toString();
4463    
4464                            Session session = null;
4465    
4466                            try {
4467                                    session = openSession();
4468    
4469                                    Query q = session.createQuery(sql);
4470    
4471                                    QueryPos qPos = QueryPos.getInstance(q);
4472    
4473                                    qPos.add(ownerId);
4474    
4475                                    qPos.add(ownerType);
4476    
4477                                    qPos.add(plid);
4478    
4479                                    if (bindPortletId) {
4480                                            qPos.add(portletId);
4481                                    }
4482    
4483                                    count = (Long)q.uniqueResult();
4484    
4485                                    finderCache.putResult(finderPath, finderArgs, count);
4486                            }
4487                            catch (Exception e) {
4488                                    finderCache.removeResult(finderPath, finderArgs);
4489    
4490                                    throw processException(e);
4491                            }
4492                            finally {
4493                                    closeSession(session);
4494                            }
4495                    }
4496    
4497                    return count.intValue();
4498            }
4499    
4500            private static final String _FINDER_COLUMN_O_O_P_P_OWNERID_2 = "portletPreferences.ownerId = ? AND ";
4501            private static final String _FINDER_COLUMN_O_O_P_P_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
4502            private static final String _FINDER_COLUMN_O_O_P_P_PLID_2 = "portletPreferences.plid = ? AND ";
4503            private static final String _FINDER_COLUMN_O_O_P_P_PORTLETID_1 = "portletPreferences.portletId IS NULL";
4504            private static final String _FINDER_COLUMN_O_O_P_P_PORTLETID_2 = "portletPreferences.portletId = ?";
4505            private static final String _FINDER_COLUMN_O_O_P_P_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = '')";
4506    
4507            public PortletPreferencesPersistenceImpl() {
4508                    setModelClass(PortletPreferences.class);
4509            }
4510    
4511            /**
4512             * Caches the portlet preferences in the entity cache if it is enabled.
4513             *
4514             * @param portletPreferences the portlet preferences
4515             */
4516            @Override
4517            public void cacheResult(PortletPreferences portletPreferences) {
4518                    entityCache.putResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
4519                            PortletPreferencesImpl.class, portletPreferences.getPrimaryKey(),
4520                            portletPreferences);
4521    
4522                    finderCache.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
4523                            new Object[] {
4524                                    portletPreferences.getOwnerId(),
4525                                    portletPreferences.getOwnerType(), portletPreferences.getPlid(),
4526                                    portletPreferences.getPortletId()
4527                            }, portletPreferences);
4528    
4529                    portletPreferences.resetOriginalValues();
4530            }
4531    
4532            /**
4533             * Caches the portlet preferenceses in the entity cache if it is enabled.
4534             *
4535             * @param portletPreferenceses the portlet preferenceses
4536             */
4537            @Override
4538            public void cacheResult(List<PortletPreferences> portletPreferenceses) {
4539                    for (PortletPreferences portletPreferences : portletPreferenceses) {
4540                            if (entityCache.getResult(
4541                                                    PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
4542                                                    PortletPreferencesImpl.class,
4543                                                    portletPreferences.getPrimaryKey()) == null) {
4544                                    cacheResult(portletPreferences);
4545                            }
4546                            else {
4547                                    portletPreferences.resetOriginalValues();
4548                            }
4549                    }
4550            }
4551    
4552            /**
4553             * Clears the cache for all portlet preferenceses.
4554             *
4555             * <p>
4556             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
4557             * </p>
4558             */
4559            @Override
4560            public void clearCache() {
4561                    entityCache.clearCache(PortletPreferencesImpl.class);
4562    
4563                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
4564                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4565                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4566            }
4567    
4568            /**
4569             * Clears the cache for the portlet preferences.
4570             *
4571             * <p>
4572             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
4573             * </p>
4574             */
4575            @Override
4576            public void clearCache(PortletPreferences portletPreferences) {
4577                    entityCache.removeResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
4578                            PortletPreferencesImpl.class, portletPreferences.getPrimaryKey());
4579    
4580                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4581                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4582    
4583                    clearUniqueFindersCache((PortletPreferencesModelImpl)portletPreferences);
4584            }
4585    
4586            @Override
4587            public void clearCache(List<PortletPreferences> portletPreferenceses) {
4588                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4589                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4590    
4591                    for (PortletPreferences portletPreferences : portletPreferenceses) {
4592                            entityCache.removeResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
4593                                    PortletPreferencesImpl.class, portletPreferences.getPrimaryKey());
4594    
4595                            clearUniqueFindersCache((PortletPreferencesModelImpl)portletPreferences);
4596                    }
4597            }
4598    
4599            protected void cacheUniqueFindersCache(
4600                    PortletPreferencesModelImpl portletPreferencesModelImpl, boolean isNew) {
4601                    if (isNew) {
4602                            Object[] args = new Object[] {
4603                                            portletPreferencesModelImpl.getOwnerId(),
4604                                            portletPreferencesModelImpl.getOwnerType(),
4605                                            portletPreferencesModelImpl.getPlid(),
4606                                            portletPreferencesModelImpl.getPortletId()
4607                                    };
4608    
4609                            finderCache.putResult(FINDER_PATH_COUNT_BY_O_O_P_P, args,
4610                                    Long.valueOf(1));
4611                            finderCache.putResult(FINDER_PATH_FETCH_BY_O_O_P_P, args,
4612                                    portletPreferencesModelImpl);
4613                    }
4614                    else {
4615                            if ((portletPreferencesModelImpl.getColumnBitmask() &
4616                                            FINDER_PATH_FETCH_BY_O_O_P_P.getColumnBitmask()) != 0) {
4617                                    Object[] args = new Object[] {
4618                                                    portletPreferencesModelImpl.getOwnerId(),
4619                                                    portletPreferencesModelImpl.getOwnerType(),
4620                                                    portletPreferencesModelImpl.getPlid(),
4621                                                    portletPreferencesModelImpl.getPortletId()
4622                                            };
4623    
4624                                    finderCache.putResult(FINDER_PATH_COUNT_BY_O_O_P_P, args,
4625                                            Long.valueOf(1));
4626                                    finderCache.putResult(FINDER_PATH_FETCH_BY_O_O_P_P, args,
4627                                            portletPreferencesModelImpl);
4628                            }
4629                    }
4630            }
4631    
4632            protected void clearUniqueFindersCache(
4633                    PortletPreferencesModelImpl portletPreferencesModelImpl) {
4634                    Object[] args = new Object[] {
4635                                    portletPreferencesModelImpl.getOwnerId(),
4636                                    portletPreferencesModelImpl.getOwnerType(),
4637                                    portletPreferencesModelImpl.getPlid(),
4638                                    portletPreferencesModelImpl.getPortletId()
4639                            };
4640    
4641                    finderCache.removeResult(FINDER_PATH_COUNT_BY_O_O_P_P, args);
4642                    finderCache.removeResult(FINDER_PATH_FETCH_BY_O_O_P_P, args);
4643    
4644                    if ((portletPreferencesModelImpl.getColumnBitmask() &
4645                                    FINDER_PATH_FETCH_BY_O_O_P_P.getColumnBitmask()) != 0) {
4646                            args = new Object[] {
4647                                            portletPreferencesModelImpl.getOriginalOwnerId(),
4648                                            portletPreferencesModelImpl.getOriginalOwnerType(),
4649                                            portletPreferencesModelImpl.getOriginalPlid(),
4650                                            portletPreferencesModelImpl.getOriginalPortletId()
4651                                    };
4652    
4653                            finderCache.removeResult(FINDER_PATH_COUNT_BY_O_O_P_P, args);
4654                            finderCache.removeResult(FINDER_PATH_FETCH_BY_O_O_P_P, args);
4655                    }
4656            }
4657    
4658            /**
4659             * Creates a new portlet preferences with the primary key. Does not add the portlet preferences to the database.
4660             *
4661             * @param portletPreferencesId the primary key for the new portlet preferences
4662             * @return the new portlet preferences
4663             */
4664            @Override
4665            public PortletPreferences create(long portletPreferencesId) {
4666                    PortletPreferences portletPreferences = new PortletPreferencesImpl();
4667    
4668                    portletPreferences.setNew(true);
4669                    portletPreferences.setPrimaryKey(portletPreferencesId);
4670    
4671                    portletPreferences.setCompanyId(companyProvider.getCompanyId());
4672    
4673                    return portletPreferences;
4674            }
4675    
4676            /**
4677             * Removes the portlet preferences with the primary key from the database. Also notifies the appropriate model listeners.
4678             *
4679             * @param portletPreferencesId the primary key of the portlet preferences
4680             * @return the portlet preferences that was removed
4681             * @throws NoSuchPortletPreferencesException if a portlet preferences with the primary key could not be found
4682             */
4683            @Override
4684            public PortletPreferences remove(long portletPreferencesId)
4685                    throws NoSuchPortletPreferencesException {
4686                    return remove((Serializable)portletPreferencesId);
4687            }
4688    
4689            /**
4690             * Removes the portlet preferences with the primary key from the database. Also notifies the appropriate model listeners.
4691             *
4692             * @param primaryKey the primary key of the portlet preferences
4693             * @return the portlet preferences that was removed
4694             * @throws NoSuchPortletPreferencesException if a portlet preferences with the primary key could not be found
4695             */
4696            @Override
4697            public PortletPreferences remove(Serializable primaryKey)
4698                    throws NoSuchPortletPreferencesException {
4699                    Session session = null;
4700    
4701                    try {
4702                            session = openSession();
4703    
4704                            PortletPreferences portletPreferences = (PortletPreferences)session.get(PortletPreferencesImpl.class,
4705                                            primaryKey);
4706    
4707                            if (portletPreferences == null) {
4708                                    if (_log.isWarnEnabled()) {
4709                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4710                                    }
4711    
4712                                    throw new NoSuchPortletPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4713                                            primaryKey);
4714                            }
4715    
4716                            return remove(portletPreferences);
4717                    }
4718                    catch (NoSuchPortletPreferencesException nsee) {
4719                            throw nsee;
4720                    }
4721                    catch (Exception e) {
4722                            throw processException(e);
4723                    }
4724                    finally {
4725                            closeSession(session);
4726                    }
4727            }
4728    
4729            @Override
4730            protected PortletPreferences removeImpl(
4731                    PortletPreferences portletPreferences) {
4732                    portletPreferences = toUnwrappedModel(portletPreferences);
4733    
4734                    Session session = null;
4735    
4736                    try {
4737                            session = openSession();
4738    
4739                            if (!session.contains(portletPreferences)) {
4740                                    portletPreferences = (PortletPreferences)session.get(PortletPreferencesImpl.class,
4741                                                    portletPreferences.getPrimaryKeyObj());
4742                            }
4743    
4744                            if (portletPreferences != null) {
4745                                    session.delete(portletPreferences);
4746                            }
4747                    }
4748                    catch (Exception e) {
4749                            throw processException(e);
4750                    }
4751                    finally {
4752                            closeSession(session);
4753                    }
4754    
4755                    if (portletPreferences != null) {
4756                            clearCache(portletPreferences);
4757                    }
4758    
4759                    return portletPreferences;
4760            }
4761    
4762            @Override
4763            public PortletPreferences updateImpl(PortletPreferences portletPreferences) {
4764                    portletPreferences = toUnwrappedModel(portletPreferences);
4765    
4766                    boolean isNew = portletPreferences.isNew();
4767    
4768                    PortletPreferencesModelImpl portletPreferencesModelImpl = (PortletPreferencesModelImpl)portletPreferences;
4769    
4770                    Session session = null;
4771    
4772                    try {
4773                            session = openSession();
4774    
4775                            if (portletPreferences.isNew()) {
4776                                    session.save(portletPreferences);
4777    
4778                                    portletPreferences.setNew(false);
4779                            }
4780                            else {
4781                                    portletPreferences = (PortletPreferences)session.merge(portletPreferences);
4782                            }
4783                    }
4784                    catch (Exception e) {
4785                            throw processException(e);
4786                    }
4787                    finally {
4788                            closeSession(session);
4789                    }
4790    
4791                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4792    
4793                    if (isNew || !PortletPreferencesModelImpl.COLUMN_BITMASK_ENABLED) {
4794                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4795                    }
4796    
4797                    else {
4798                            if ((portletPreferencesModelImpl.getColumnBitmask() &
4799                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PLID.getColumnBitmask()) != 0) {
4800                                    Object[] args = new Object[] {
4801                                                    portletPreferencesModelImpl.getOriginalPlid()
4802                                            };
4803    
4804                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_PLID, args);
4805                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PLID,
4806                                            args);
4807    
4808                                    args = new Object[] { portletPreferencesModelImpl.getPlid() };
4809    
4810                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_PLID, args);
4811                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PLID,
4812                                            args);
4813                            }
4814    
4815                            if ((portletPreferencesModelImpl.getColumnBitmask() &
4816                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORTLETID.getColumnBitmask()) != 0) {
4817                                    Object[] args = new Object[] {
4818                                                    portletPreferencesModelImpl.getOriginalPortletId()
4819                                            };
4820    
4821                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_PORTLETID, args);
4822                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORTLETID,
4823                                            args);
4824    
4825                                    args = new Object[] { portletPreferencesModelImpl.getPortletId() };
4826    
4827                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_PORTLETID, args);
4828                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORTLETID,
4829                                            args);
4830                            }
4831    
4832                            if ((portletPreferencesModelImpl.getColumnBitmask() &
4833                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P.getColumnBitmask()) != 0) {
4834                                    Object[] args = new Object[] {
4835                                                    portletPreferencesModelImpl.getOriginalOwnerType(),
4836                                                    portletPreferencesModelImpl.getOriginalPortletId()
4837                                            };
4838    
4839                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_O_P, args);
4840                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P,
4841                                            args);
4842    
4843                                    args = new Object[] {
4844                                                    portletPreferencesModelImpl.getOwnerType(),
4845                                                    portletPreferencesModelImpl.getPortletId()
4846                                            };
4847    
4848                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_O_P, args);
4849                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P,
4850                                            args);
4851                            }
4852    
4853                            if ((portletPreferencesModelImpl.getColumnBitmask() &
4854                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_P.getColumnBitmask()) != 0) {
4855                                    Object[] args = new Object[] {
4856                                                    portletPreferencesModelImpl.getOriginalPlid(),
4857                                                    portletPreferencesModelImpl.getOriginalPortletId()
4858                                            };
4859    
4860                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_P_P, args);
4861                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_P,
4862                                            args);
4863    
4864                                    args = new Object[] {
4865                                                    portletPreferencesModelImpl.getPlid(),
4866                                                    portletPreferencesModelImpl.getPortletId()
4867                                            };
4868    
4869                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_P_P, args);
4870                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_P,
4871                                            args);
4872                            }
4873    
4874                            if ((portletPreferencesModelImpl.getColumnBitmask() &
4875                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_P.getColumnBitmask()) != 0) {
4876                                    Object[] args = new Object[] {
4877                                                    portletPreferencesModelImpl.getOriginalOwnerId(),
4878                                                    portletPreferencesModelImpl.getOriginalOwnerType(),
4879                                                    portletPreferencesModelImpl.getOriginalPlid()
4880                                            };
4881    
4882                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_O_O_P, args);
4883                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_P,
4884                                            args);
4885    
4886                                    args = new Object[] {
4887                                                    portletPreferencesModelImpl.getOwnerId(),
4888                                                    portletPreferencesModelImpl.getOwnerType(),
4889                                                    portletPreferencesModelImpl.getPlid()
4890                                            };
4891    
4892                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_O_O_P, args);
4893                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_P,
4894                                            args);
4895                            }
4896    
4897                            if ((portletPreferencesModelImpl.getColumnBitmask() &
4898                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_PI.getColumnBitmask()) != 0) {
4899                                    Object[] args = new Object[] {
4900                                                    portletPreferencesModelImpl.getOriginalOwnerId(),
4901                                                    portletPreferencesModelImpl.getOriginalOwnerType(),
4902                                                    portletPreferencesModelImpl.getOriginalPortletId()
4903                                            };
4904    
4905                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_O_O_PI, args);
4906                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_PI,
4907                                            args);
4908    
4909                                    args = new Object[] {
4910                                                    portletPreferencesModelImpl.getOwnerId(),
4911                                                    portletPreferencesModelImpl.getOwnerType(),
4912                                                    portletPreferencesModelImpl.getPortletId()
4913                                            };
4914    
4915                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_O_O_PI, args);
4916                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_PI,
4917                                            args);
4918                            }
4919    
4920                            if ((portletPreferencesModelImpl.getColumnBitmask() &
4921                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P_P.getColumnBitmask()) != 0) {
4922                                    Object[] args = new Object[] {
4923                                                    portletPreferencesModelImpl.getOriginalOwnerType(),
4924                                                    portletPreferencesModelImpl.getOriginalPlid(),
4925                                                    portletPreferencesModelImpl.getOriginalPortletId()
4926                                            };
4927    
4928                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_O_P_P, args);
4929                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P_P,
4930                                            args);
4931    
4932                                    args = new Object[] {
4933                                                    portletPreferencesModelImpl.getOwnerType(),
4934                                                    portletPreferencesModelImpl.getPlid(),
4935                                                    portletPreferencesModelImpl.getPortletId()
4936                                            };
4937    
4938                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_O_P_P, args);
4939                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P_P,
4940                                            args);
4941                            }
4942                    }
4943    
4944                    entityCache.putResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
4945                            PortletPreferencesImpl.class, portletPreferences.getPrimaryKey(),
4946                            portletPreferences, false);
4947    
4948                    clearUniqueFindersCache(portletPreferencesModelImpl);
4949                    cacheUniqueFindersCache(portletPreferencesModelImpl, isNew);
4950    
4951                    portletPreferences.resetOriginalValues();
4952    
4953                    return portletPreferences;
4954            }
4955    
4956            protected PortletPreferences toUnwrappedModel(
4957                    PortletPreferences portletPreferences) {
4958                    if (portletPreferences instanceof PortletPreferencesImpl) {
4959                            return portletPreferences;
4960                    }
4961    
4962                    PortletPreferencesImpl portletPreferencesImpl = new PortletPreferencesImpl();
4963    
4964                    portletPreferencesImpl.setNew(portletPreferences.isNew());
4965                    portletPreferencesImpl.setPrimaryKey(portletPreferences.getPrimaryKey());
4966    
4967                    portletPreferencesImpl.setMvccVersion(portletPreferences.getMvccVersion());
4968                    portletPreferencesImpl.setPortletPreferencesId(portletPreferences.getPortletPreferencesId());
4969                    portletPreferencesImpl.setCompanyId(portletPreferences.getCompanyId());
4970                    portletPreferencesImpl.setOwnerId(portletPreferences.getOwnerId());
4971                    portletPreferencesImpl.setOwnerType(portletPreferences.getOwnerType());
4972                    portletPreferencesImpl.setPlid(portletPreferences.getPlid());
4973                    portletPreferencesImpl.setPortletId(portletPreferences.getPortletId());
4974                    portletPreferencesImpl.setPreferences(portletPreferences.getPreferences());
4975    
4976                    return portletPreferencesImpl;
4977            }
4978    
4979            /**
4980             * Returns the portlet preferences with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
4981             *
4982             * @param primaryKey the primary key of the portlet preferences
4983             * @return the portlet preferences
4984             * @throws NoSuchPortletPreferencesException if a portlet preferences with the primary key could not be found
4985             */
4986            @Override
4987            public PortletPreferences findByPrimaryKey(Serializable primaryKey)
4988                    throws NoSuchPortletPreferencesException {
4989                    PortletPreferences portletPreferences = fetchByPrimaryKey(primaryKey);
4990    
4991                    if (portletPreferences == null) {
4992                            if (_log.isWarnEnabled()) {
4993                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4994                            }
4995    
4996                            throw new NoSuchPortletPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4997                                    primaryKey);
4998                    }
4999    
5000                    return portletPreferences;
5001            }
5002    
5003            /**
5004             * Returns the portlet preferences with the primary key or throws a {@link NoSuchPortletPreferencesException} if it could not be found.
5005             *
5006             * @param portletPreferencesId the primary key of the portlet preferences
5007             * @return the portlet preferences
5008             * @throws NoSuchPortletPreferencesException if a portlet preferences with the primary key could not be found
5009             */
5010            @Override
5011            public PortletPreferences findByPrimaryKey(long portletPreferencesId)
5012                    throws NoSuchPortletPreferencesException {
5013                    return findByPrimaryKey((Serializable)portletPreferencesId);
5014            }
5015    
5016            /**
5017             * Returns the portlet preferences with the primary key or returns <code>null</code> if it could not be found.
5018             *
5019             * @param primaryKey the primary key of the portlet preferences
5020             * @return the portlet preferences, or <code>null</code> if a portlet preferences with the primary key could not be found
5021             */
5022            @Override
5023            public PortletPreferences fetchByPrimaryKey(Serializable primaryKey) {
5024                    PortletPreferences portletPreferences = (PortletPreferences)entityCache.getResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
5025                                    PortletPreferencesImpl.class, primaryKey);
5026    
5027                    if (portletPreferences == _nullPortletPreferences) {
5028                            return null;
5029                    }
5030    
5031                    if (portletPreferences == null) {
5032                            Session session = null;
5033    
5034                            try {
5035                                    session = openSession();
5036    
5037                                    portletPreferences = (PortletPreferences)session.get(PortletPreferencesImpl.class,
5038                                                    primaryKey);
5039    
5040                                    if (portletPreferences != null) {
5041                                            cacheResult(portletPreferences);
5042                                    }
5043                                    else {
5044                                            entityCache.putResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
5045                                                    PortletPreferencesImpl.class, primaryKey,
5046                                                    _nullPortletPreferences);
5047                                    }
5048                            }
5049                            catch (Exception e) {
5050                                    entityCache.removeResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
5051                                            PortletPreferencesImpl.class, primaryKey);
5052    
5053                                    throw processException(e);
5054                            }
5055                            finally {
5056                                    closeSession(session);
5057                            }
5058                    }
5059    
5060                    return portletPreferences;
5061            }
5062    
5063            /**
5064             * Returns the portlet preferences with the primary key or returns <code>null</code> if it could not be found.
5065             *
5066             * @param portletPreferencesId the primary key of the portlet preferences
5067             * @return the portlet preferences, or <code>null</code> if a portlet preferences with the primary key could not be found
5068             */
5069            @Override
5070            public PortletPreferences fetchByPrimaryKey(long portletPreferencesId) {
5071                    return fetchByPrimaryKey((Serializable)portletPreferencesId);
5072            }
5073    
5074            @Override
5075            public Map<Serializable, PortletPreferences> fetchByPrimaryKeys(
5076                    Set<Serializable> primaryKeys) {
5077                    if (primaryKeys.isEmpty()) {
5078                            return Collections.emptyMap();
5079                    }
5080    
5081                    Map<Serializable, PortletPreferences> map = new HashMap<Serializable, PortletPreferences>();
5082    
5083                    if (primaryKeys.size() == 1) {
5084                            Iterator<Serializable> iterator = primaryKeys.iterator();
5085    
5086                            Serializable primaryKey = iterator.next();
5087    
5088                            PortletPreferences portletPreferences = fetchByPrimaryKey(primaryKey);
5089    
5090                            if (portletPreferences != null) {
5091                                    map.put(primaryKey, portletPreferences);
5092                            }
5093    
5094                            return map;
5095                    }
5096    
5097                    Set<Serializable> uncachedPrimaryKeys = null;
5098    
5099                    for (Serializable primaryKey : primaryKeys) {
5100                            PortletPreferences portletPreferences = (PortletPreferences)entityCache.getResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
5101                                            PortletPreferencesImpl.class, primaryKey);
5102    
5103                            if (portletPreferences == null) {
5104                                    if (uncachedPrimaryKeys == null) {
5105                                            uncachedPrimaryKeys = new HashSet<Serializable>();
5106                                    }
5107    
5108                                    uncachedPrimaryKeys.add(primaryKey);
5109                            }
5110                            else {
5111                                    map.put(primaryKey, portletPreferences);
5112                            }
5113                    }
5114    
5115                    if (uncachedPrimaryKeys == null) {
5116                            return map;
5117                    }
5118    
5119                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
5120                                    1);
5121    
5122                    query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE_PKS_IN);
5123    
5124                    for (Serializable primaryKey : uncachedPrimaryKeys) {
5125                            query.append(String.valueOf(primaryKey));
5126    
5127                            query.append(StringPool.COMMA);
5128                    }
5129    
5130                    query.setIndex(query.index() - 1);
5131    
5132                    query.append(StringPool.CLOSE_PARENTHESIS);
5133    
5134                    String sql = query.toString();
5135    
5136                    Session session = null;
5137    
5138                    try {
5139                            session = openSession();
5140    
5141                            Query q = session.createQuery(sql);
5142    
5143                            for (PortletPreferences portletPreferences : (List<PortletPreferences>)q.list()) {
5144                                    map.put(portletPreferences.getPrimaryKeyObj(),
5145                                            portletPreferences);
5146    
5147                                    cacheResult(portletPreferences);
5148    
5149                                    uncachedPrimaryKeys.remove(portletPreferences.getPrimaryKeyObj());
5150                            }
5151    
5152                            for (Serializable primaryKey : uncachedPrimaryKeys) {
5153                                    entityCache.putResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
5154                                            PortletPreferencesImpl.class, primaryKey,
5155                                            _nullPortletPreferences);
5156                            }
5157                    }
5158                    catch (Exception e) {
5159                            throw processException(e);
5160                    }
5161                    finally {
5162                            closeSession(session);
5163                    }
5164    
5165                    return map;
5166            }
5167    
5168            /**
5169             * Returns all the portlet preferenceses.
5170             *
5171             * @return the portlet preferenceses
5172             */
5173            @Override
5174            public List<PortletPreferences> findAll() {
5175                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5176            }
5177    
5178            /**
5179             * Returns a range of all the portlet preferenceses.
5180             *
5181             * <p>
5182             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
5183             * </p>
5184             *
5185             * @param start the lower bound of the range of portlet preferenceses
5186             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
5187             * @return the range of portlet preferenceses
5188             */
5189            @Override
5190            public List<PortletPreferences> findAll(int start, int end) {
5191                    return findAll(start, end, null);
5192            }
5193    
5194            /**
5195             * Returns an ordered range of all the portlet preferenceses.
5196             *
5197             * <p>
5198             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
5199             * </p>
5200             *
5201             * @param start the lower bound of the range of portlet preferenceses
5202             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
5203             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5204             * @return the ordered range of portlet preferenceses
5205             */
5206            @Override
5207            public List<PortletPreferences> findAll(int start, int end,
5208                    OrderByComparator<PortletPreferences> orderByComparator) {
5209                    return findAll(start, end, orderByComparator, true);
5210            }
5211    
5212            /**
5213             * Returns an ordered range of all the portlet preferenceses.
5214             *
5215             * <p>
5216             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
5217             * </p>
5218             *
5219             * @param start the lower bound of the range of portlet preferenceses
5220             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
5221             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5222             * @param retrieveFromCache whether to retrieve from the finder cache
5223             * @return the ordered range of portlet preferenceses
5224             */
5225            @Override
5226            public List<PortletPreferences> findAll(int start, int end,
5227                    OrderByComparator<PortletPreferences> orderByComparator,
5228                    boolean retrieveFromCache) {
5229                    boolean pagination = true;
5230                    FinderPath finderPath = null;
5231                    Object[] finderArgs = null;
5232    
5233                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5234                                    (orderByComparator == null)) {
5235                            pagination = false;
5236                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5237                            finderArgs = FINDER_ARGS_EMPTY;
5238                    }
5239                    else {
5240                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5241                            finderArgs = new Object[] { start, end, orderByComparator };
5242                    }
5243    
5244                    List<PortletPreferences> list = null;
5245    
5246                    if (retrieveFromCache) {
5247                            list = (List<PortletPreferences>)finderCache.getResult(finderPath,
5248                                            finderArgs, this);
5249                    }
5250    
5251                    if (list == null) {
5252                            StringBundler query = null;
5253                            String sql = null;
5254    
5255                            if (orderByComparator != null) {
5256                                    query = new StringBundler(2 +
5257                                                    (orderByComparator.getOrderByFields().length * 2));
5258    
5259                                    query.append(_SQL_SELECT_PORTLETPREFERENCES);
5260    
5261                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5262                                            orderByComparator);
5263    
5264                                    sql = query.toString();
5265                            }
5266                            else {
5267                                    sql = _SQL_SELECT_PORTLETPREFERENCES;
5268    
5269                                    if (pagination) {
5270                                            sql = sql.concat(PortletPreferencesModelImpl.ORDER_BY_JPQL);
5271                                    }
5272                            }
5273    
5274                            Session session = null;
5275    
5276                            try {
5277                                    session = openSession();
5278    
5279                                    Query q = session.createQuery(sql);
5280    
5281                                    if (!pagination) {
5282                                            list = (List<PortletPreferences>)QueryUtil.list(q,
5283                                                            getDialect(), start, end, false);
5284    
5285                                            Collections.sort(list);
5286    
5287                                            list = Collections.unmodifiableList(list);
5288                                    }
5289                                    else {
5290                                            list = (List<PortletPreferences>)QueryUtil.list(q,
5291                                                            getDialect(), start, end);
5292                                    }
5293    
5294                                    cacheResult(list);
5295    
5296                                    finderCache.putResult(finderPath, finderArgs, list);
5297                            }
5298                            catch (Exception e) {
5299                                    finderCache.removeResult(finderPath, finderArgs);
5300    
5301                                    throw processException(e);
5302                            }
5303                            finally {
5304                                    closeSession(session);
5305                            }
5306                    }
5307    
5308                    return list;
5309            }
5310    
5311            /**
5312             * Removes all the portlet preferenceses from the database.
5313             *
5314             */
5315            @Override
5316            public void removeAll() {
5317                    for (PortletPreferences portletPreferences : findAll()) {
5318                            remove(portletPreferences);
5319                    }
5320            }
5321    
5322            /**
5323             * Returns the number of portlet preferenceses.
5324             *
5325             * @return the number of portlet preferenceses
5326             */
5327            @Override
5328            public int countAll() {
5329                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
5330                                    FINDER_ARGS_EMPTY, this);
5331    
5332                    if (count == null) {
5333                            Session session = null;
5334    
5335                            try {
5336                                    session = openSession();
5337    
5338                                    Query q = session.createQuery(_SQL_COUNT_PORTLETPREFERENCES);
5339    
5340                                    count = (Long)q.uniqueResult();
5341    
5342                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
5343                                            count);
5344                            }
5345                            catch (Exception e) {
5346                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
5347                                            FINDER_ARGS_EMPTY);
5348    
5349                                    throw processException(e);
5350                            }
5351                            finally {
5352                                    closeSession(session);
5353                            }
5354                    }
5355    
5356                    return count.intValue();
5357            }
5358    
5359            @Override
5360            protected Map<String, Integer> getTableColumnsMap() {
5361                    return PortletPreferencesModelImpl.TABLE_COLUMNS_MAP;
5362            }
5363    
5364            /**
5365             * Initializes the portlet preferences persistence.
5366             */
5367            public void afterPropertiesSet() {
5368            }
5369    
5370            public void destroy() {
5371                    entityCache.removeCache(PortletPreferencesImpl.class.getName());
5372                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
5373                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5374                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5375            }
5376    
5377            @BeanReference(type = CompanyProviderWrapper.class)
5378            protected CompanyProvider companyProvider;
5379            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
5380            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
5381            private static final String _SQL_SELECT_PORTLETPREFERENCES = "SELECT portletPreferences FROM PortletPreferences portletPreferences";
5382            private static final String _SQL_SELECT_PORTLETPREFERENCES_WHERE_PKS_IN = "SELECT portletPreferences FROM PortletPreferences portletPreferences WHERE portletPreferencesId IN (";
5383            private static final String _SQL_SELECT_PORTLETPREFERENCES_WHERE = "SELECT portletPreferences FROM PortletPreferences portletPreferences WHERE ";
5384            private static final String _SQL_COUNT_PORTLETPREFERENCES = "SELECT COUNT(portletPreferences) FROM PortletPreferences portletPreferences";
5385            private static final String _SQL_COUNT_PORTLETPREFERENCES_WHERE = "SELECT COUNT(portletPreferences) FROM PortletPreferences portletPreferences WHERE ";
5386            private static final String _ORDER_BY_ENTITY_ALIAS = "portletPreferences.";
5387            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortletPreferences exists with the primary key ";
5388            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortletPreferences exists with the key {";
5389            private static final Log _log = LogFactoryUtil.getLog(PortletPreferencesPersistenceImpl.class);
5390            private static final PortletPreferences _nullPortletPreferences = new PortletPreferencesImpl() {
5391                            @Override
5392                            public Object clone() {
5393                                    return this;
5394                            }
5395    
5396                            @Override
5397                            public CacheModel<PortletPreferences> toCacheModel() {
5398                                    return _nullPortletPreferencesCacheModel;
5399                            }
5400                    };
5401    
5402            private static final CacheModel<PortletPreferences> _nullPortletPreferencesCacheModel =
5403                    new NullCacheModel();
5404    
5405            private static class NullCacheModel implements CacheModel<PortletPreferences>,
5406                    MVCCModel {
5407                    @Override
5408                    public long getMvccVersion() {
5409                            return -1;
5410                    }
5411    
5412                    @Override
5413                    public void setMvccVersion(long mvccVersion) {
5414                    }
5415    
5416                    @Override
5417                    public PortletPreferences toEntityModel() {
5418                            return _nullPortletPreferences;
5419                    }
5420            }
5421    }