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