001    /**
002     * Copyright (c) 2000-2012 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.NoSuchModelException;
018    import com.liferay.portal.NoSuchPreferencesException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.PortalPreferences;
040    import com.liferay.portal.model.impl.PortalPreferencesImpl;
041    import com.liferay.portal.model.impl.PortalPreferencesModelImpl;
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 portal 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 PortalPreferencesPersistence
059     * @see PortalPreferencesUtil
060     * @generated
061     */
062    public class PortalPreferencesPersistenceImpl extends BasePersistenceImpl<PortalPreferences>
063            implements PortalPreferencesPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link PortalPreferencesUtil} to access the portal preferences persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = PortalPreferencesImpl.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_FETCH_BY_O_O = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
075                            PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
076                            PortalPreferencesImpl.class, FINDER_CLASS_NAME_ENTITY,
077                            "fetchByO_O",
078                            new String[] { Long.class.getName(), Integer.class.getName() },
079                            PortalPreferencesModelImpl.OWNERID_COLUMN_BITMASK |
080                            PortalPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK);
081            public static final FinderPath FINDER_PATH_COUNT_BY_O_O = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
082                            PortalPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_O",
084                            new String[] { Long.class.getName(), Integer.class.getName() });
085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
086                            PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
087                            PortalPreferencesImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
090                            PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
091                            PortalPreferencesImpl.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
093            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
094                            PortalPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
096    
097            /**
098             * Caches the portal preferences in the entity cache if it is enabled.
099             *
100             * @param portalPreferences the portal preferences
101             */
102            public void cacheResult(PortalPreferences portalPreferences) {
103                    EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
104                            PortalPreferencesImpl.class, portalPreferences.getPrimaryKey(),
105                            portalPreferences);
106    
107                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
108                            new Object[] {
109                                    Long.valueOf(portalPreferences.getOwnerId()),
110                                    Integer.valueOf(portalPreferences.getOwnerType())
111                            }, portalPreferences);
112    
113                    portalPreferences.resetOriginalValues();
114            }
115    
116            /**
117             * Caches the portal preferenceses in the entity cache if it is enabled.
118             *
119             * @param portalPreferenceses the portal preferenceses
120             */
121            public void cacheResult(List<PortalPreferences> portalPreferenceses) {
122                    for (PortalPreferences portalPreferences : portalPreferenceses) {
123                            if (EntityCacheUtil.getResult(
124                                                    PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
125                                                    PortalPreferencesImpl.class,
126                                                    portalPreferences.getPrimaryKey()) == null) {
127                                    cacheResult(portalPreferences);
128                            }
129                            else {
130                                    portalPreferences.resetOriginalValues();
131                            }
132                    }
133            }
134    
135            /**
136             * Clears the cache for all portal preferenceses.
137             *
138             * <p>
139             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
140             * </p>
141             */
142            @Override
143            public void clearCache() {
144                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
145                            CacheRegistryUtil.clear(PortalPreferencesImpl.class.getName());
146                    }
147    
148                    EntityCacheUtil.clearCache(PortalPreferencesImpl.class.getName());
149    
150                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
151                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
152                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
153            }
154    
155            /**
156             * Clears the cache for the portal preferences.
157             *
158             * <p>
159             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
160             * </p>
161             */
162            @Override
163            public void clearCache(PortalPreferences portalPreferences) {
164                    EntityCacheUtil.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
165                            PortalPreferencesImpl.class, portalPreferences.getPrimaryKey());
166    
167                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
168                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
169    
170                    clearUniqueFindersCache(portalPreferences);
171            }
172    
173            @Override
174            public void clearCache(List<PortalPreferences> portalPreferenceses) {
175                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
176                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
177    
178                    for (PortalPreferences portalPreferences : portalPreferenceses) {
179                            EntityCacheUtil.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
180                                    PortalPreferencesImpl.class, portalPreferences.getPrimaryKey());
181    
182                            clearUniqueFindersCache(portalPreferences);
183                    }
184            }
185    
186            protected void clearUniqueFindersCache(PortalPreferences portalPreferences) {
187                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O,
188                            new Object[] {
189                                    Long.valueOf(portalPreferences.getOwnerId()),
190                                    Integer.valueOf(portalPreferences.getOwnerType())
191                            });
192            }
193    
194            /**
195             * Creates a new portal preferences with the primary key. Does not add the portal preferences to the database.
196             *
197             * @param portalPreferencesId the primary key for the new portal preferences
198             * @return the new portal preferences
199             */
200            public PortalPreferences create(long portalPreferencesId) {
201                    PortalPreferences portalPreferences = new PortalPreferencesImpl();
202    
203                    portalPreferences.setNew(true);
204                    portalPreferences.setPrimaryKey(portalPreferencesId);
205    
206                    return portalPreferences;
207            }
208    
209            /**
210             * Removes the portal preferences with the primary key from the database. Also notifies the appropriate model listeners.
211             *
212             * @param portalPreferencesId the primary key of the portal preferences
213             * @return the portal preferences that was removed
214             * @throws com.liferay.portal.NoSuchPreferencesException if a portal preferences with the primary key could not be found
215             * @throws SystemException if a system exception occurred
216             */
217            public PortalPreferences remove(long portalPreferencesId)
218                    throws NoSuchPreferencesException, SystemException {
219                    return remove(Long.valueOf(portalPreferencesId));
220            }
221    
222            /**
223             * Removes the portal preferences with the primary key from the database. Also notifies the appropriate model listeners.
224             *
225             * @param primaryKey the primary key of the portal preferences
226             * @return the portal preferences that was removed
227             * @throws com.liferay.portal.NoSuchPreferencesException if a portal preferences with the primary key could not be found
228             * @throws SystemException if a system exception occurred
229             */
230            @Override
231            public PortalPreferences remove(Serializable primaryKey)
232                    throws NoSuchPreferencesException, SystemException {
233                    Session session = null;
234    
235                    try {
236                            session = openSession();
237    
238                            PortalPreferences portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
239                                            primaryKey);
240    
241                            if (portalPreferences == null) {
242                                    if (_log.isWarnEnabled()) {
243                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
244                                    }
245    
246                                    throw new NoSuchPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
247                                            primaryKey);
248                            }
249    
250                            return remove(portalPreferences);
251                    }
252                    catch (NoSuchPreferencesException nsee) {
253                            throw nsee;
254                    }
255                    catch (Exception e) {
256                            throw processException(e);
257                    }
258                    finally {
259                            closeSession(session);
260                    }
261            }
262    
263            @Override
264            protected PortalPreferences removeImpl(PortalPreferences portalPreferences)
265                    throws SystemException {
266                    portalPreferences = toUnwrappedModel(portalPreferences);
267    
268                    Session session = null;
269    
270                    try {
271                            session = openSession();
272    
273                            if (portalPreferences.isCachedModel()) {
274                                    portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
275                                                    portalPreferences.getPrimaryKeyObj());
276                            }
277    
278                            session.delete(portalPreferences);
279                    }
280                    catch (Exception e) {
281                            throw processException(e);
282                    }
283                    finally {
284                            closeSession(session);
285                    }
286    
287                    clearCache(portalPreferences);
288    
289                    return portalPreferences;
290            }
291    
292            @Override
293            public PortalPreferences updateImpl(
294                    com.liferay.portal.model.PortalPreferences portalPreferences)
295                    throws SystemException {
296                    portalPreferences = toUnwrappedModel(portalPreferences);
297    
298                    boolean isNew = portalPreferences.isNew();
299    
300                    PortalPreferencesModelImpl portalPreferencesModelImpl = (PortalPreferencesModelImpl)portalPreferences;
301    
302                    Session session = null;
303    
304                    try {
305                            session = openSession();
306    
307                            if (portalPreferences.isNew()) {
308                                    session.save(portalPreferences);
309    
310                                    portalPreferences.setNew(false);
311                            }
312                            else {
313                                    session.merge(portalPreferences);
314                            }
315                    }
316                    catch (Exception e) {
317                            throw processException(e);
318                    }
319                    finally {
320                            closeSession(session);
321                    }
322    
323                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
324    
325                    if (isNew || !PortalPreferencesModelImpl.COLUMN_BITMASK_ENABLED) {
326                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
327                    }
328    
329                    EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
330                            PortalPreferencesImpl.class, portalPreferences.getPrimaryKey(),
331                            portalPreferences);
332    
333                    if (isNew) {
334                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
335                                    new Object[] {
336                                            Long.valueOf(portalPreferences.getOwnerId()),
337                                            Integer.valueOf(portalPreferences.getOwnerType())
338                                    }, portalPreferences);
339                    }
340                    else {
341                            if ((portalPreferencesModelImpl.getColumnBitmask() &
342                                            FINDER_PATH_FETCH_BY_O_O.getColumnBitmask()) != 0) {
343                                    Object[] args = new Object[] {
344                                                    Long.valueOf(portalPreferencesModelImpl.getOriginalOwnerId()),
345                                                    Integer.valueOf(portalPreferencesModelImpl.getOriginalOwnerType())
346                                            };
347    
348                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_O_O, args);
349    
350                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O, args);
351    
352                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
353                                            new Object[] {
354                                                    Long.valueOf(portalPreferences.getOwnerId()),
355                                                    Integer.valueOf(portalPreferences.getOwnerType())
356                                            }, portalPreferences);
357                            }
358                    }
359    
360                    return portalPreferences;
361            }
362    
363            protected PortalPreferences toUnwrappedModel(
364                    PortalPreferences portalPreferences) {
365                    if (portalPreferences instanceof PortalPreferencesImpl) {
366                            return portalPreferences;
367                    }
368    
369                    PortalPreferencesImpl portalPreferencesImpl = new PortalPreferencesImpl();
370    
371                    portalPreferencesImpl.setNew(portalPreferences.isNew());
372                    portalPreferencesImpl.setPrimaryKey(portalPreferences.getPrimaryKey());
373    
374                    portalPreferencesImpl.setPortalPreferencesId(portalPreferences.getPortalPreferencesId());
375                    portalPreferencesImpl.setOwnerId(portalPreferences.getOwnerId());
376                    portalPreferencesImpl.setOwnerType(portalPreferences.getOwnerType());
377                    portalPreferencesImpl.setPreferences(portalPreferences.getPreferences());
378    
379                    return portalPreferencesImpl;
380            }
381    
382            /**
383             * Returns the portal preferences with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
384             *
385             * @param primaryKey the primary key of the portal preferences
386             * @return the portal preferences
387             * @throws com.liferay.portal.NoSuchModelException if a portal preferences with the primary key could not be found
388             * @throws SystemException if a system exception occurred
389             */
390            @Override
391            public PortalPreferences findByPrimaryKey(Serializable primaryKey)
392                    throws NoSuchModelException, SystemException {
393                    return findByPrimaryKey(((Long)primaryKey).longValue());
394            }
395    
396            /**
397             * Returns the portal preferences with the primary key or throws a {@link com.liferay.portal.NoSuchPreferencesException} if it could not be found.
398             *
399             * @param portalPreferencesId the primary key of the portal preferences
400             * @return the portal preferences
401             * @throws com.liferay.portal.NoSuchPreferencesException if a portal preferences with the primary key could not be found
402             * @throws SystemException if a system exception occurred
403             */
404            public PortalPreferences findByPrimaryKey(long portalPreferencesId)
405                    throws NoSuchPreferencesException, SystemException {
406                    PortalPreferences portalPreferences = fetchByPrimaryKey(portalPreferencesId);
407    
408                    if (portalPreferences == null) {
409                            if (_log.isWarnEnabled()) {
410                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
411                                            portalPreferencesId);
412                            }
413    
414                            throw new NoSuchPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
415                                    portalPreferencesId);
416                    }
417    
418                    return portalPreferences;
419            }
420    
421            /**
422             * Returns the portal preferences with the primary key or returns <code>null</code> if it could not be found.
423             *
424             * @param primaryKey the primary key of the portal preferences
425             * @return the portal preferences, or <code>null</code> if a portal preferences with the primary key could not be found
426             * @throws SystemException if a system exception occurred
427             */
428            @Override
429            public PortalPreferences fetchByPrimaryKey(Serializable primaryKey)
430                    throws SystemException {
431                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
432            }
433    
434            /**
435             * Returns the portal preferences with the primary key or returns <code>null</code> if it could not be found.
436             *
437             * @param portalPreferencesId the primary key of the portal preferences
438             * @return the portal preferences, or <code>null</code> if a portal preferences with the primary key could not be found
439             * @throws SystemException if a system exception occurred
440             */
441            public PortalPreferences fetchByPrimaryKey(long portalPreferencesId)
442                    throws SystemException {
443                    PortalPreferences portalPreferences = (PortalPreferences)EntityCacheUtil.getResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
444                                    PortalPreferencesImpl.class, portalPreferencesId);
445    
446                    if (portalPreferences == _nullPortalPreferences) {
447                            return null;
448                    }
449    
450                    if (portalPreferences == null) {
451                            Session session = null;
452    
453                            boolean hasException = false;
454    
455                            try {
456                                    session = openSession();
457    
458                                    portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
459                                                    Long.valueOf(portalPreferencesId));
460                            }
461                            catch (Exception e) {
462                                    hasException = true;
463    
464                                    throw processException(e);
465                            }
466                            finally {
467                                    if (portalPreferences != null) {
468                                            cacheResult(portalPreferences);
469                                    }
470                                    else if (!hasException) {
471                                            EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
472                                                    PortalPreferencesImpl.class, portalPreferencesId,
473                                                    _nullPortalPreferences);
474                                    }
475    
476                                    closeSession(session);
477                            }
478                    }
479    
480                    return portalPreferences;
481            }
482    
483            /**
484             * Returns the portal preferences where ownerId = &#63; and ownerType = &#63; or throws a {@link com.liferay.portal.NoSuchPreferencesException} if it could not be found.
485             *
486             * @param ownerId the owner ID
487             * @param ownerType the owner type
488             * @return the matching portal preferences
489             * @throws com.liferay.portal.NoSuchPreferencesException if a matching portal preferences could not be found
490             * @throws SystemException if a system exception occurred
491             */
492            public PortalPreferences findByO_O(long ownerId, int ownerType)
493                    throws NoSuchPreferencesException, SystemException {
494                    PortalPreferences portalPreferences = fetchByO_O(ownerId, ownerType);
495    
496                    if (portalPreferences == null) {
497                            StringBundler msg = new StringBundler(6);
498    
499                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
500    
501                            msg.append("ownerId=");
502                            msg.append(ownerId);
503    
504                            msg.append(", ownerType=");
505                            msg.append(ownerType);
506    
507                            msg.append(StringPool.CLOSE_CURLY_BRACE);
508    
509                            if (_log.isWarnEnabled()) {
510                                    _log.warn(msg.toString());
511                            }
512    
513                            throw new NoSuchPreferencesException(msg.toString());
514                    }
515    
516                    return portalPreferences;
517            }
518    
519            /**
520             * Returns the portal preferences where ownerId = &#63; and ownerType = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
521             *
522             * @param ownerId the owner ID
523             * @param ownerType the owner type
524             * @return the matching portal preferences, or <code>null</code> if a matching portal preferences could not be found
525             * @throws SystemException if a system exception occurred
526             */
527            public PortalPreferences fetchByO_O(long ownerId, int ownerType)
528                    throws SystemException {
529                    return fetchByO_O(ownerId, ownerType, true);
530            }
531    
532            /**
533             * Returns the portal preferences where ownerId = &#63; and ownerType = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
534             *
535             * @param ownerId the owner ID
536             * @param ownerType the owner type
537             * @param retrieveFromCache whether to use the finder cache
538             * @return the matching portal preferences, or <code>null</code> if a matching portal preferences could not be found
539             * @throws SystemException if a system exception occurred
540             */
541            public PortalPreferences fetchByO_O(long ownerId, int ownerType,
542                    boolean retrieveFromCache) throws SystemException {
543                    Object[] finderArgs = new Object[] { ownerId, ownerType };
544    
545                    Object result = null;
546    
547                    if (retrieveFromCache) {
548                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_O_O,
549                                            finderArgs, this);
550                    }
551    
552                    if (result instanceof PortalPreferences) {
553                            PortalPreferences portalPreferences = (PortalPreferences)result;
554    
555                            if ((ownerId != portalPreferences.getOwnerId()) ||
556                                            (ownerType != portalPreferences.getOwnerType())) {
557                                    result = null;
558                            }
559                    }
560    
561                    if (result == null) {
562                            StringBundler query = new StringBundler(3);
563    
564                            query.append(_SQL_SELECT_PORTALPREFERENCES_WHERE);
565    
566                            query.append(_FINDER_COLUMN_O_O_OWNERID_2);
567    
568                            query.append(_FINDER_COLUMN_O_O_OWNERTYPE_2);
569    
570                            String sql = query.toString();
571    
572                            Session session = null;
573    
574                            try {
575                                    session = openSession();
576    
577                                    Query q = session.createQuery(sql);
578    
579                                    QueryPos qPos = QueryPos.getInstance(q);
580    
581                                    qPos.add(ownerId);
582    
583                                    qPos.add(ownerType);
584    
585                                    List<PortalPreferences> list = q.list();
586    
587                                    result = list;
588    
589                                    PortalPreferences portalPreferences = null;
590    
591                                    if (list.isEmpty()) {
592                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
593                                                    finderArgs, list);
594                                    }
595                                    else {
596                                            portalPreferences = list.get(0);
597    
598                                            cacheResult(portalPreferences);
599    
600                                            if ((portalPreferences.getOwnerId() != ownerId) ||
601                                                            (portalPreferences.getOwnerType() != ownerType)) {
602                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
603                                                            finderArgs, portalPreferences);
604                                            }
605                                    }
606    
607                                    return portalPreferences;
608                            }
609                            catch (Exception e) {
610                                    throw processException(e);
611                            }
612                            finally {
613                                    if (result == null) {
614                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O,
615                                                    finderArgs);
616                                    }
617    
618                                    closeSession(session);
619                            }
620                    }
621                    else {
622                            if (result instanceof List<?>) {
623                                    return null;
624                            }
625                            else {
626                                    return (PortalPreferences)result;
627                            }
628                    }
629            }
630    
631            /**
632             * Returns all the portal preferenceses.
633             *
634             * @return the portal preferenceses
635             * @throws SystemException if a system exception occurred
636             */
637            public List<PortalPreferences> findAll() throws SystemException {
638                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
639            }
640    
641            /**
642             * Returns a range of all the portal preferenceses.
643             *
644             * <p>
645             * 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.
646             * </p>
647             *
648             * @param start the lower bound of the range of portal preferenceses
649             * @param end the upper bound of the range of portal preferenceses (not inclusive)
650             * @return the range of portal preferenceses
651             * @throws SystemException if a system exception occurred
652             */
653            public List<PortalPreferences> findAll(int start, int end)
654                    throws SystemException {
655                    return findAll(start, end, null);
656            }
657    
658            /**
659             * Returns an ordered range of all the portal preferenceses.
660             *
661             * <p>
662             * 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.
663             * </p>
664             *
665             * @param start the lower bound of the range of portal preferenceses
666             * @param end the upper bound of the range of portal preferenceses (not inclusive)
667             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
668             * @return the ordered range of portal preferenceses
669             * @throws SystemException if a system exception occurred
670             */
671            public List<PortalPreferences> findAll(int start, int end,
672                    OrderByComparator orderByComparator) throws SystemException {
673                    FinderPath finderPath = null;
674                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
675    
676                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
677                                    (orderByComparator == null)) {
678                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
679                            finderArgs = FINDER_ARGS_EMPTY;
680                    }
681                    else {
682                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
683                            finderArgs = new Object[] { start, end, orderByComparator };
684                    }
685    
686                    List<PortalPreferences> list = (List<PortalPreferences>)FinderCacheUtil.getResult(finderPath,
687                                    finderArgs, this);
688    
689                    if (list == null) {
690                            StringBundler query = null;
691                            String sql = null;
692    
693                            if (orderByComparator != null) {
694                                    query = new StringBundler(2 +
695                                                    (orderByComparator.getOrderByFields().length * 3));
696    
697                                    query.append(_SQL_SELECT_PORTALPREFERENCES);
698    
699                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
700                                            orderByComparator);
701    
702                                    sql = query.toString();
703                            }
704                            else {
705                                    sql = _SQL_SELECT_PORTALPREFERENCES;
706                            }
707    
708                            Session session = null;
709    
710                            try {
711                                    session = openSession();
712    
713                                    Query q = session.createQuery(sql);
714    
715                                    if (orderByComparator == null) {
716                                            list = (List<PortalPreferences>)QueryUtil.list(q,
717                                                            getDialect(), start, end, false);
718    
719                                            Collections.sort(list);
720                                    }
721                                    else {
722                                            list = (List<PortalPreferences>)QueryUtil.list(q,
723                                                            getDialect(), start, end);
724                                    }
725                            }
726                            catch (Exception e) {
727                                    throw processException(e);
728                            }
729                            finally {
730                                    if (list == null) {
731                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
732                                    }
733                                    else {
734                                            cacheResult(list);
735    
736                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
737                                    }
738    
739                                    closeSession(session);
740                            }
741                    }
742    
743                    return list;
744            }
745    
746            /**
747             * Removes the portal preferences where ownerId = &#63; and ownerType = &#63; from the database.
748             *
749             * @param ownerId the owner ID
750             * @param ownerType the owner type
751             * @return the portal preferences that was removed
752             * @throws SystemException if a system exception occurred
753             */
754            public PortalPreferences removeByO_O(long ownerId, int ownerType)
755                    throws NoSuchPreferencesException, SystemException {
756                    PortalPreferences portalPreferences = findByO_O(ownerId, ownerType);
757    
758                    return remove(portalPreferences);
759            }
760    
761            /**
762             * Removes all the portal preferenceses from the database.
763             *
764             * @throws SystemException if a system exception occurred
765             */
766            public void removeAll() throws SystemException {
767                    for (PortalPreferences portalPreferences : findAll()) {
768                            remove(portalPreferences);
769                    }
770            }
771    
772            /**
773             * Returns the number of portal preferenceses where ownerId = &#63; and ownerType = &#63;.
774             *
775             * @param ownerId the owner ID
776             * @param ownerType the owner type
777             * @return the number of matching portal preferenceses
778             * @throws SystemException if a system exception occurred
779             */
780            public int countByO_O(long ownerId, int ownerType)
781                    throws SystemException {
782                    Object[] finderArgs = new Object[] { ownerId, ownerType };
783    
784                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_O_O,
785                                    finderArgs, this);
786    
787                    if (count == null) {
788                            StringBundler query = new StringBundler(3);
789    
790                            query.append(_SQL_COUNT_PORTALPREFERENCES_WHERE);
791    
792                            query.append(_FINDER_COLUMN_O_O_OWNERID_2);
793    
794                            query.append(_FINDER_COLUMN_O_O_OWNERTYPE_2);
795    
796                            String sql = query.toString();
797    
798                            Session session = null;
799    
800                            try {
801                                    session = openSession();
802    
803                                    Query q = session.createQuery(sql);
804    
805                                    QueryPos qPos = QueryPos.getInstance(q);
806    
807                                    qPos.add(ownerId);
808    
809                                    qPos.add(ownerType);
810    
811                                    count = (Long)q.uniqueResult();
812                            }
813                            catch (Exception e) {
814                                    throw processException(e);
815                            }
816                            finally {
817                                    if (count == null) {
818                                            count = Long.valueOf(0);
819                                    }
820    
821                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_O_O, finderArgs,
822                                            count);
823    
824                                    closeSession(session);
825                            }
826                    }
827    
828                    return count.intValue();
829            }
830    
831            /**
832             * Returns the number of portal preferenceses.
833             *
834             * @return the number of portal preferenceses
835             * @throws SystemException if a system exception occurred
836             */
837            public int countAll() throws SystemException {
838                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
839                                    FINDER_ARGS_EMPTY, this);
840    
841                    if (count == null) {
842                            Session session = null;
843    
844                            try {
845                                    session = openSession();
846    
847                                    Query q = session.createQuery(_SQL_COUNT_PORTALPREFERENCES);
848    
849                                    count = (Long)q.uniqueResult();
850                            }
851                            catch (Exception e) {
852                                    throw processException(e);
853                            }
854                            finally {
855                                    if (count == null) {
856                                            count = Long.valueOf(0);
857                                    }
858    
859                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
860                                            FINDER_ARGS_EMPTY, count);
861    
862                                    closeSession(session);
863                            }
864                    }
865    
866                    return count.intValue();
867            }
868    
869            /**
870             * Initializes the portal preferences persistence.
871             */
872            public void afterPropertiesSet() {
873                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
874                                            com.liferay.portal.util.PropsUtil.get(
875                                                    "value.object.listener.com.liferay.portal.model.PortalPreferences")));
876    
877                    if (listenerClassNames.length > 0) {
878                            try {
879                                    List<ModelListener<PortalPreferences>> listenersList = new ArrayList<ModelListener<PortalPreferences>>();
880    
881                                    for (String listenerClassName : listenerClassNames) {
882                                            listenersList.add((ModelListener<PortalPreferences>)InstanceFactory.newInstance(
883                                                            listenerClassName));
884                                    }
885    
886                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
887                            }
888                            catch (Exception e) {
889                                    _log.error(e);
890                            }
891                    }
892            }
893    
894            public void destroy() {
895                    EntityCacheUtil.removeCache(PortalPreferencesImpl.class.getName());
896                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
897                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
898            }
899    
900            @BeanReference(type = AccountPersistence.class)
901            protected AccountPersistence accountPersistence;
902            @BeanReference(type = AddressPersistence.class)
903            protected AddressPersistence addressPersistence;
904            @BeanReference(type = BrowserTrackerPersistence.class)
905            protected BrowserTrackerPersistence browserTrackerPersistence;
906            @BeanReference(type = ClassNamePersistence.class)
907            protected ClassNamePersistence classNamePersistence;
908            @BeanReference(type = ClusterGroupPersistence.class)
909            protected ClusterGroupPersistence clusterGroupPersistence;
910            @BeanReference(type = CompanyPersistence.class)
911            protected CompanyPersistence companyPersistence;
912            @BeanReference(type = ContactPersistence.class)
913            protected ContactPersistence contactPersistence;
914            @BeanReference(type = CountryPersistence.class)
915            protected CountryPersistence countryPersistence;
916            @BeanReference(type = EmailAddressPersistence.class)
917            protected EmailAddressPersistence emailAddressPersistence;
918            @BeanReference(type = GroupPersistence.class)
919            protected GroupPersistence groupPersistence;
920            @BeanReference(type = ImagePersistence.class)
921            protected ImagePersistence imagePersistence;
922            @BeanReference(type = LayoutPersistence.class)
923            protected LayoutPersistence layoutPersistence;
924            @BeanReference(type = LayoutBranchPersistence.class)
925            protected LayoutBranchPersistence layoutBranchPersistence;
926            @BeanReference(type = LayoutPrototypePersistence.class)
927            protected LayoutPrototypePersistence layoutPrototypePersistence;
928            @BeanReference(type = LayoutRevisionPersistence.class)
929            protected LayoutRevisionPersistence layoutRevisionPersistence;
930            @BeanReference(type = LayoutSetPersistence.class)
931            protected LayoutSetPersistence layoutSetPersistence;
932            @BeanReference(type = LayoutSetBranchPersistence.class)
933            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
934            @BeanReference(type = LayoutSetPrototypePersistence.class)
935            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
936            @BeanReference(type = ListTypePersistence.class)
937            protected ListTypePersistence listTypePersistence;
938            @BeanReference(type = LockPersistence.class)
939            protected LockPersistence lockPersistence;
940            @BeanReference(type = MembershipRequestPersistence.class)
941            protected MembershipRequestPersistence membershipRequestPersistence;
942            @BeanReference(type = OrganizationPersistence.class)
943            protected OrganizationPersistence organizationPersistence;
944            @BeanReference(type = OrgGroupRolePersistence.class)
945            protected OrgGroupRolePersistence orgGroupRolePersistence;
946            @BeanReference(type = OrgLaborPersistence.class)
947            protected OrgLaborPersistence orgLaborPersistence;
948            @BeanReference(type = PasswordPolicyPersistence.class)
949            protected PasswordPolicyPersistence passwordPolicyPersistence;
950            @BeanReference(type = PasswordPolicyRelPersistence.class)
951            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
952            @BeanReference(type = PasswordTrackerPersistence.class)
953            protected PasswordTrackerPersistence passwordTrackerPersistence;
954            @BeanReference(type = PhonePersistence.class)
955            protected PhonePersistence phonePersistence;
956            @BeanReference(type = PluginSettingPersistence.class)
957            protected PluginSettingPersistence pluginSettingPersistence;
958            @BeanReference(type = PortalPreferencesPersistence.class)
959            protected PortalPreferencesPersistence portalPreferencesPersistence;
960            @BeanReference(type = PortletPersistence.class)
961            protected PortletPersistence portletPersistence;
962            @BeanReference(type = PortletItemPersistence.class)
963            protected PortletItemPersistence portletItemPersistence;
964            @BeanReference(type = PortletPreferencesPersistence.class)
965            protected PortletPreferencesPersistence portletPreferencesPersistence;
966            @BeanReference(type = RegionPersistence.class)
967            protected RegionPersistence regionPersistence;
968            @BeanReference(type = ReleasePersistence.class)
969            protected ReleasePersistence releasePersistence;
970            @BeanReference(type = RepositoryPersistence.class)
971            protected RepositoryPersistence repositoryPersistence;
972            @BeanReference(type = RepositoryEntryPersistence.class)
973            protected RepositoryEntryPersistence repositoryEntryPersistence;
974            @BeanReference(type = ResourceActionPersistence.class)
975            protected ResourceActionPersistence resourceActionPersistence;
976            @BeanReference(type = ResourceBlockPersistence.class)
977            protected ResourceBlockPersistence resourceBlockPersistence;
978            @BeanReference(type = ResourceBlockPermissionPersistence.class)
979            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
980            @BeanReference(type = ResourcePermissionPersistence.class)
981            protected ResourcePermissionPersistence resourcePermissionPersistence;
982            @BeanReference(type = ResourceTypePermissionPersistence.class)
983            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
984            @BeanReference(type = RolePersistence.class)
985            protected RolePersistence rolePersistence;
986            @BeanReference(type = ServiceComponentPersistence.class)
987            protected ServiceComponentPersistence serviceComponentPersistence;
988            @BeanReference(type = ShardPersistence.class)
989            protected ShardPersistence shardPersistence;
990            @BeanReference(type = SubscriptionPersistence.class)
991            protected SubscriptionPersistence subscriptionPersistence;
992            @BeanReference(type = TeamPersistence.class)
993            protected TeamPersistence teamPersistence;
994            @BeanReference(type = TicketPersistence.class)
995            protected TicketPersistence ticketPersistence;
996            @BeanReference(type = UserPersistence.class)
997            protected UserPersistence userPersistence;
998            @BeanReference(type = UserGroupPersistence.class)
999            protected UserGroupPersistence userGroupPersistence;
1000            @BeanReference(type = UserGroupGroupRolePersistence.class)
1001            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1002            @BeanReference(type = UserGroupRolePersistence.class)
1003            protected UserGroupRolePersistence userGroupRolePersistence;
1004            @BeanReference(type = UserIdMapperPersistence.class)
1005            protected UserIdMapperPersistence userIdMapperPersistence;
1006            @BeanReference(type = UserNotificationEventPersistence.class)
1007            protected UserNotificationEventPersistence userNotificationEventPersistence;
1008            @BeanReference(type = UserTrackerPersistence.class)
1009            protected UserTrackerPersistence userTrackerPersistence;
1010            @BeanReference(type = UserTrackerPathPersistence.class)
1011            protected UserTrackerPathPersistence userTrackerPathPersistence;
1012            @BeanReference(type = VirtualHostPersistence.class)
1013            protected VirtualHostPersistence virtualHostPersistence;
1014            @BeanReference(type = WebDAVPropsPersistence.class)
1015            protected WebDAVPropsPersistence webDAVPropsPersistence;
1016            @BeanReference(type = WebsitePersistence.class)
1017            protected WebsitePersistence websitePersistence;
1018            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1019            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1020            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1021            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1022            private static final String _SQL_SELECT_PORTALPREFERENCES = "SELECT portalPreferences FROM PortalPreferences portalPreferences";
1023            private static final String _SQL_SELECT_PORTALPREFERENCES_WHERE = "SELECT portalPreferences FROM PortalPreferences portalPreferences WHERE ";
1024            private static final String _SQL_COUNT_PORTALPREFERENCES = "SELECT COUNT(portalPreferences) FROM PortalPreferences portalPreferences";
1025            private static final String _SQL_COUNT_PORTALPREFERENCES_WHERE = "SELECT COUNT(portalPreferences) FROM PortalPreferences portalPreferences WHERE ";
1026            private static final String _FINDER_COLUMN_O_O_OWNERID_2 = "portalPreferences.ownerId = ? AND ";
1027            private static final String _FINDER_COLUMN_O_O_OWNERTYPE_2 = "portalPreferences.ownerType = ?";
1028            private static final String _ORDER_BY_ENTITY_ALIAS = "portalPreferences.";
1029            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortalPreferences exists with the primary key ";
1030            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortalPreferences exists with the key {";
1031            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1032            private static Log _log = LogFactoryUtil.getLog(PortalPreferencesPersistenceImpl.class);
1033            private static PortalPreferences _nullPortalPreferences = new PortalPreferencesImpl() {
1034                            @Override
1035                            public Object clone() {
1036                                    return this;
1037                            }
1038    
1039                            @Override
1040                            public CacheModel<PortalPreferences> toCacheModel() {
1041                                    return _nullPortalPreferencesCacheModel;
1042                            }
1043                    };
1044    
1045            private static CacheModel<PortalPreferences> _nullPortalPreferencesCacheModel =
1046                    new CacheModel<PortalPreferences>() {
1047                            public PortalPreferences toEntityModel() {
1048                                    return _nullPortalPreferences;
1049                            }
1050                    };
1051    }