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