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