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