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